From a85565334708840dd44b849a91c1fa09b9038093 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 5 Feb 2025 13:29:05 -0500 Subject: trie: New trie_{get,set}_{str,mem}() functions --- src/trie.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'src/trie.h') diff --git a/src/trie.h b/src/trie.h index 318a23b..d8cecab 100644 --- a/src/trie.h +++ b/src/trie.h @@ -69,6 +69,32 @@ 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); +/** + * Get the value associated with a string key. + * + * @trie + * The trie to search. + * @key + * The key to look up. + * @return + * The found value, or NULL if the key is not present. + */ +void *trie_get_str(const struct trie *trie, const char *key); + +/** + * Get the value associated with a fixed-size key. + * + * @trie + * The trie to search. + * @key + * The key to look up. + * @length + * The length of the key in bytes. + * @return + * The found value, or NULL if the key is not present. + */ +void *trie_get_mem(const struct trie *trie, const void *key, size_t length); + /** * Find the shortest leaf that starts with a given key. * @@ -119,6 +145,36 @@ struct trie_leaf *trie_insert_str(struct trie *trie, const char *key); */ struct trie_leaf *trie_insert_mem(struct trie *trie, const void *key, size_t length); +/** + * Set the value for a string key. + * + * @trie + * The trie to modify. + * @key + * The key to insert. + * @value + * The value to set. + * @return + * 0 on success, -1 on error. + */ +int trie_set_str(struct trie *trie, const char *key, const void *value); + +/** + * Set the value for a fixed-size key. + * + * @trie + * The trie to modify. + * @key + * The key to insert. + * @length + * The length of the key in bytes. + * @value + * The value to set. + * @return + * 0 on success, -1 on error. + */ +int trie_set_mem(struct trie *trie, const void *key, size_t length, const void *value); + /** * Remove a leaf from a trie. * -- cgit v1.2.3