fix sll & hashtable bugs

This commit is contained in:
Matthew 2025-09-15 09:02:21 +10:00
parent 608f527ca5
commit c5c58fd986

19
util.d
View File

@ -139,14 +139,17 @@ DLLPop(T, U)(T* list, U* nil)
{ {
U* node = list.first; U* node = list.first;
if(list.first == list.last) if (!CheckNil(nil, list.first))
{ {
list.first = list.last = nil; if(list.first == list.last)
} {
else list.first = list.last = nil;
{ }
list.first = list.first.next; else
list.first.prev = nil; {
list.first = list.first.next;
list.first.prev = nil;
}
} }
return node; return node;
@ -518,7 +521,7 @@ Delete(K, V)(HashTable!(K, V)* ht, K key)
auto list = GetList(ht, key); auto list = GetList(ht, key);
auto prev = ht.nil; auto prev = ht.nil;
for(auto node = list.first; !CheckNil(ht.nil, node); node = node.next) for(auto node = list.first; !CheckNil(ht.nil, node); prev = node, node = node.next)
{ {
if(node.value.key == key) if(node.value.key == key)
{ {