Never nest
This commit is contained in:
34
hm.h
34
hm.h
@@ -264,23 +264,25 @@ bool hm_remove(HashMap *hm, const void *key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Hm__Bucket *cur = head; cur != NULL; cur = cur->next) {
|
for (Hm__Bucket *cur = head; cur != NULL; cur = cur->next) {
|
||||||
if (hm__keycmp(hm, key, cur->key)) {
|
if (!hm__keycmp(hm, key, cur->key)) {
|
||||||
if (cur == head) {
|
continue;
|
||||||
hm->map[idx] = cur->next;
|
|
||||||
} else {
|
|
||||||
cur->prev->next = cur->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cur->next != NULL) {
|
|
||||||
cur->next->prev = cur->prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
HM_FREE(cur->key);
|
|
||||||
HM_FREE(cur->value);
|
|
||||||
HM_FREE(cur);
|
|
||||||
--hm->count;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cur == head) {
|
||||||
|
hm->map[idx] = cur->next;
|
||||||
|
} else {
|
||||||
|
cur->prev->next = cur->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cur->next != NULL) {
|
||||||
|
cur->next->prev = cur->prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
HM_FREE(cur->key);
|
||||||
|
HM_FREE(cur->value);
|
||||||
|
HM_FREE(cur);
|
||||||
|
--hm->count;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user