add fn to get all nodes from hashtable
This commit is contained in:
parent
2581fcb18c
commit
ff378df96e
28
util.d
28
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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user