diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-03-28 15:34:43 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-03-29 12:26:43 -0400 |
commit | ba2d4ac206ff1321ea953d3305d8bda048922983 (patch) | |
tree | 91c1ab573bb7efe5c273c1e1fd9cef4d8d966473 /src/trie.h | |
parent | 7888fbababd22190e9f919fc272957426a27969e (diff) | |
download | bfs-ba2d4ac206ff1321ea953d3305d8bda048922983.tar.xz |
trie: Use list.h for the list of leaves
Diffstat (limited to 'src/trie.h')
-rw-r--r-- | src/trie.h | 31 |
1 files changed, 10 insertions, 21 deletions
@@ -4,6 +4,8 @@ #ifndef BFS_TRIE_H #define BFS_TRIE_H +#include "config.h" +#include "list.h" #include <stdbool.h> #include <stddef.h> #include <stdint.h> @@ -12,24 +14,13 @@ * A leaf of a trie. */ struct trie_leaf { - /** - * Linked list of leaves, in insertion order. - */ - struct trie_leaf *prev, *next; - - /** - * An arbitrary value associated with this leaf. - */ + /** Linked list of leaves, in insertion order. */ + struct link link; + /** An arbitrary value associated with this leaf. */ void *value; - - /** - * The length of the key in bytes. - */ + /** The length of the key in bytes. */ size_t length; - - /** - * The key itself, stored inline. - */ + /** The key itself, stored inline. */ char key[]; }; @@ -40,7 +31,7 @@ struct trie { /** Pointer to the root node/leaf. */ uintptr_t root; /** Linked list of leaves. */ - struct trie_leaf *head, *tail; + struct list leaves; }; /** @@ -142,9 +133,7 @@ void trie_destroy(struct trie *trie); /** * Iterate over the leaves of a trie. */ -#define TRIE_FOR_EACH(trie, leaf) \ - for (struct trie_leaf *leaf = (trie)->head, *_next; \ - leaf && (_next = leaf->next, true); \ - leaf = _next) +#define TRIE_FOR_EACH(trie, leaf) \ + LIST_FOR_EACH(&(trie)->leaves, struct trie_leaf, leaf) #endif // BFS_TRIE_H |