diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2025-01-24 13:15:01 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2025-02-06 06:42:37 +0000 |
| commit | e248e73753d61bfd24f1af8e824231434db63c53 (patch) | |
| tree | ea691f1e970d04d7b8a1b45e68db589b1debeaba /composed.c | |
| parent | composed: re-factor: break out key calculation from vt.c (diff) | |
composed: refactor: break out lookup with collision detection
Diffstat (limited to 'composed.c')
| -rw-r--r-- | composed.c | 37 |
1 files changed, 36 insertions, 1 deletions
@@ -51,7 +51,7 @@ UNITTEST xassert(k3 == k4); } -struct composed * +const struct composed * composed_lookup(struct composed *root, uint32_t key) { struct composed *node = root; @@ -66,6 +66,41 @@ composed_lookup(struct composed *root, uint32_t key) return NULL; } +const struct composed * +composed_lookup_without_collision(struct composed *root, uint32_t *key, + const char32_t *prefix_text, size_t prefix_len, + char32_t wc, int forced_width) +{ + while (true) { + const struct composed *cc = composed_lookup(root, *key); + if (cc == NULL) + return NULL; + + bool match = cc->count == prefix_len + 1 && + cc->forced_width == forced_width && + cc->chars[prefix_len] == wc; + + if (match) { + for (size_t i = 0; i < prefix_len; i++) { + if (cc->chars[i] != prefix_text[i]) { + match = false; + break; + } + } + } + + if (match) + return cc; + + (*key)++; + *key &= CELL_COMB_CHARS_HI - CELL_COMB_CHARS_LO; + + /* TODO: this will loop infinitly if the composed table is full */ + } + + return NULL; +} + void composed_insert(struct composed **root, struct composed *node) { |
