From ff378df96ec625854266948b23fe76c2d2183621 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 15 Sep 2025 05:38:15 +1000 Subject: [PATCH] add fn to get all nodes from hashtable --- util.d | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/util.d b/util.d index 3c149c8..83164ef 100644 --- a/util.d +++ b/util.d @@ -489,6 +489,28 @@ GetList(K, V)(HashTable!(K, V)* ht, K key) return ht.lists.ptr + index; } +KVPair!(K, V)*[] +GetAllNodes(Arena* arena, HashTable!(K, V)* ht) +{ + KVPair!(K, V)*[] pairs = AllocArray!(KVPair!(K, V)*)(arena, ht.node_count); + + if(ht.node_count > 0) + { + u64 count = 0; + + for(u64 i = 0; i < ht.lists.length; i += 1) + { + for(auto n = ht.lists[i].first; !CheckNil(ht.nil, n); n = n.next) + { + pairs[count] = &n.value; + count += 1; + } + } + } + + return pairs; +} + pragma(inline) Result!(V) Delete(K, V)(HashTable!(K, V)* ht, K key) { @@ -500,14 +522,16 @@ Delete(K, V)(HashTable!(K, V)* ht, K key) { if(node.value.key == key) { - Remove(list, node, prev, ht.nil); + SLLRemove(list, node, prev, ht.nil); result.ok = true; result.value = node.value.value; memset(&node.value, 0, node.value.sizeof); - Push(&ht.free_lists, node, ht.nil); + SLLPush(&ht.free_lists, node, ht.nil); + + ht.node_count -= 1; break; }