diff options
| author | gingerBill <bill@gingerbill.org> | 2020-05-21 16:27:40 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-05-21 16:27:40 +0100 |
| commit | d09ac8943ac38b955e9a10d22e5c2f3fba8e7eaa (patch) | |
| tree | b1c8ec516f93d0c15eef14812442bda09c3d750c /src/map.cpp | |
| parent | 8e63c943939619cb74266ff43a0cff20293d5b70 (diff) | |
Minor fixes to improve hash map/set performance
Diffstat (limited to 'src/map.cpp')
| -rw-r--r-- | src/map.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/map.cpp b/src/map.cpp index ae6bf9f74..85836fccb 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -89,8 +89,11 @@ template <typename T> void multi_map_remove_all(Map<T> *h, HashKey const &key); template <typename T> gb_inline void map_init(Map<T> *h, gbAllocator a, isize capacity) { - array_init(&h->hashes, a, 0, capacity); + array_init(&h->hashes, a, capacity); array_init(&h->entries, a, 0, capacity); + for (isize i = 0; i < capacity; i++) { + h->hashes.data[i] = -1; + } } template <typename T> @@ -161,7 +164,7 @@ template <typename T> void map_rehash(Map<T> *h, isize new_count) { isize i, j; Map<T> nh = {}; - map_init(&nh, h->hashes.allocator); + map_init(&nh, h->hashes.allocator, new_count); array_resize(&nh.hashes, new_count); array_reserve(&nh.entries, h->entries.count); for (i = 0; i < new_count; i++) { |