summaryrefslogtreecommitdiffstats
path: root/src/trie.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-03-28 15:34:43 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-03-29 12:26:43 -0400
commitba2d4ac206ff1321ea953d3305d8bda048922983 (patch)
tree91c1ab573bb7efe5c273c1e1fd9cef4d8d966473 /src/trie.c
parent7888fbababd22190e9f919fc272957426a27969e (diff)
downloadbfs-ba2d4ac206ff1321ea953d3305d8bda048922983.tar.xz
trie: Use list.h for the list of leaves
Diffstat (limited to 'src/trie.c')
-rw-r--r--src/trie.c28
1 files changed, 4 insertions, 24 deletions
diff --git a/src/trie.c b/src/trie.c
index 77c43cc..7b00f4b 100644
--- a/src/trie.c
+++ b/src/trie.c
@@ -163,8 +163,7 @@ static uintptr_t trie_encode_node(const struct trie_node *node) {
void trie_init(struct trie *trie) {
trie->root = 0;
- trie->head = NULL;
- trie->tail = NULL;
+ list_init(&trie->leaves);
}
/** Check if a number is a power of two. */
@@ -341,16 +340,8 @@ static struct trie_leaf *trie_leaf_alloc(struct trie *trie, const void *key, siz
return NULL;
}
- leaf->prev = trie->tail;
- leaf->next = NULL;
-
- if (leaf->prev) {
- leaf->prev->next = leaf;
- } else {
- trie->head = leaf;
- }
-
- trie->tail = leaf;
+ link_init(&leaf->link);
+ list_append(&trie->leaves, &leaf->link);
leaf->value = NULL;
leaf->length = length;
@@ -361,18 +352,7 @@ static struct trie_leaf *trie_leaf_alloc(struct trie *trie, const void *key, siz
/** Free a leaf. */
static void trie_leaf_free(struct trie *trie, struct trie_leaf *leaf) {
- if (leaf->prev) {
- leaf->prev->next = leaf->next;
- } else {
- trie->head = leaf->next;
- }
-
- if (leaf->next) {
- leaf->next->prev = leaf->prev;
- } else {
- trie->tail = leaf->prev;
- }
-
+ list_remove(&trie->leaves, &leaf->link);
free(leaf);
}