From ba2d4ac206ff1321ea953d3305d8bda048922983 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 28 Mar 2023 15:34:43 -0400 Subject: trie: Use list.h for the list of leaves --- src/trie.h | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'src/trie.h') diff --git a/src/trie.h b/src/trie.h index 03ee64d..6e1e875 100644 --- a/src/trie.h +++ b/src/trie.h @@ -4,6 +4,8 @@ #ifndef BFS_TRIE_H #define BFS_TRIE_H +#include "config.h" +#include "list.h" #include #include #include @@ -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 -- cgit v1.2.3