From 47f232e8fd307794e20bf0d6c84152f48be18cb3 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 4 Mar 2019 23:30:33 -0800 Subject: trie: Implement prefix/postfix search --- trie.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'trie.h') diff --git a/trie.h b/trie.h index 8fcf04b..fcdd630 100644 --- a/trie.h +++ b/trie.h @@ -79,6 +79,30 @@ struct trie_leaf *trie_find_str(const struct trie *trie, const char *key); */ struct trie_leaf *trie_find_mem(const struct trie *trie, const void *key, size_t length); +/** + * Find the shortest leaf that starts with a given key. + * + * @param trie + * The trie to search. + * @param key + * The key to look up. + * @return + * A leaf that starts with the given key, or NULL. + */ +struct trie_leaf *trie_find_postfix(const struct trie *trie, const char *key); + +/** + * Find the leaf that is the longest prefix of the given key. + * + * @param trie + * The trie to search. + * @param key + * The key to look up. + * @return + * The longest prefix match for the given key, or NULL. + */ +struct trie_leaf *trie_find_prefix(const struct trie *trie, const char *key); + /** * Insert a string key into the trie. * -- cgit v1.2.3