fix sll & hashtable bugs

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

5
util.d
View File

@ -139,6 +139,8 @@ DLLPop(T, U)(T* list, U* nil)
{ {
U* node = list.first; U* node = list.first;
if (!CheckNil(nil, list.first))
{
if(list.first == list.last) if(list.first == list.last)
{ {
list.first = list.last = nil; list.first = list.last = nil;
@ -148,6 +150,7 @@ DLLPop(T, U)(T* list, U* nil)
list.first = list.first.next; list.first = list.first.next;
list.first.prev = nil; 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)
{ {