summaryrefslogtreecommitdiffstats
path: root/src/trie.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/trie.h')
-rw-r--r--src/trie.h31
1 files changed, 10 insertions, 21 deletions
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 <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