diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2025-02-05 13:29:05 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2025-02-06 10:38:45 -0500 |
commit | a85565334708840dd44b849a91c1fa09b9038093 (patch) | |
tree | 29599824ab1f5ef02713e558bc68c7f3388c32c8 /src/trie.h | |
parent | f8aca1c316b116c2de11d42010fdda0ddb418750 (diff) | |
download | bfs-a85565334708840dd44b849a91c1fa09b9038093.tar.xz |
trie: New trie_{get,set}_{str,mem}() functions
Diffstat (limited to 'src/trie.h')
-rw-r--r-- | src/trie.h | 56 |
1 files changed, 56 insertions, 0 deletions
@@ -70,6 +70,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. * * @trie @@ -120,6 +146,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. * * @trie |