- } else if (trie_entry_c_match(trie, current, key, &pos)) {
- key += pos;
+ } else if (trie_entry_c_match(trie, current, key)) {
+ key += current->c_len;
+ current = trie_entry_child(trie, current, key);
+ if (current == NULL) {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+ }
+}
+
+bool trie_prefix(const trie_t *trie, const char *key)
+{
+ assert(trie->keys.len == 0L && "Can't lookup: trie not compiled");
+ if (trie->entries.len == 0) {
+ return false;
+ } else {
+ const trie_entry_t *current = array_ptr(trie->entries, 0);
+ while (true) {
+ if (trie_entry_is_leaf(current)) {
+ return trie_entry_prefix(trie, current, key);
+ } else if (trie_entry_c_match(trie, current, key)) {
+ key += current->c_len;