diff options
| author | gingerBill <bill@gingerbill.org> | 2021-10-22 14:12:48 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-10-22 14:12:48 +0100 |
| commit | ef73a284e3e438a25a4e329d59057cfa8cddf44c (patch) | |
| tree | 5b4e37bf64f4e8bc43b38a66ba46e103864f548a /src/map.cpp | |
| parent | 28af376d103da1b7820032de0b6d8fc6ca9d6d3a (diff) | |
Fix check_remove_expr_info
Diffstat (limited to 'src/map.cpp')
| -rw-r--r-- | src/map.cpp | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/src/map.cpp b/src/map.cpp index 55eb4fbce..3a34764bf 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -114,16 +114,17 @@ gb_internal isize map__add_entry(Map<T> *h, HashKey const &key) { template <typename T> gb_internal MapFindResult map__find(Map<T> *h, HashKey const &key) { MapFindResult fr = {-1, -1, -1}; - if (h->hashes.count > 0) { - fr.hash_index = key.key & (h->hashes.count-1); - fr.entry_index = h->hashes.data[fr.hash_index]; - while (fr.entry_index >= 0) { - if (hash_key_equal(h->entries.data[fr.entry_index].key, key)) { - return fr; - } - fr.entry_prev = fr.entry_index; - fr.entry_index = h->entries.data[fr.entry_index].next; + if (h->hashes.count == 0) { + return fr; + } + fr.hash_index = key.key & (h->hashes.count-1); + fr.entry_index = h->hashes.data[fr.hash_index]; + while (fr.entry_index >= 0) { + if (hash_key_equal(h->entries.data[fr.entry_index].key, key)) { + return fr; } + fr.entry_prev = fr.entry_index; + fr.entry_index = h->entries.data[fr.entry_index].next; } return fr; } @@ -131,16 +132,17 @@ gb_internal MapFindResult map__find(Map<T> *h, HashKey const &key) { template <typename T> gb_internal MapFindResult map__find_from_entry(Map<T> *h, MapEntry<T> *e) { MapFindResult fr = {-1, -1, -1}; - if (h->hashes.count > 0) { - fr.hash_index = e->key.key & (h->hashes.count-1); - fr.entry_index = h->hashes.data[fr.hash_index]; - while (fr.entry_index >= 0) { - if (&h->entries.data[fr.entry_index] == e) { - return fr; - } - fr.entry_prev = fr.entry_index; - fr.entry_index = h->entries.data[fr.entry_index].next; + if (h->hashes.count == 0) { + return fr; + } + fr.hash_index = e->key.key & (h->hashes.count-1); + fr.entry_index = h->hashes.data[fr.hash_index]; + while (fr.entry_index >= 0) { + if (&h->entries.data[fr.entry_index] == e) { + return fr; } + fr.entry_prev = fr.entry_index; + fr.entry_index = h->entries.data[fr.entry_index].next; } return fr; } @@ -246,6 +248,8 @@ void map__erase(Map<T> *h, MapFindResult const &fr) { return; } h->entries.data[fr.entry_index] = h->entries.data[h->entries.count-1]; + array_pop(&h->entries); + last = map__find(h, h->entries.data[fr.entry_index].key); if (last.entry_prev >= 0) { h->entries.data[last.entry_prev].next = fr.entry_index; |