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.c | |
parent | 7888fbababd22190e9f919fc272957426a27969e (diff) | |
download | bfs-ba2d4ac206ff1321ea953d3305d8bda048922983.tar.xz |
trie: Use list.h for the list of leaves
Diffstat (limited to 'src/trie.c')
-rw-r--r-- | src/trie.c | 28 |
1 files changed, 4 insertions, 24 deletions
@@ -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); } |