diff options
| author | gingerBill <bill@gingerbill.org> | 2023-01-05 11:54:21 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-01-05 11:54:21 +0000 |
| commit | 1517f1d7793c8985664600a820e3434dfdf83810 (patch) | |
| tree | 30b50588d6328517658ea15438551890113febb4 /src/ptr_map.cpp | |
| parent | bbb2164e38e3930cb79c5e7bc61b421e38131361 (diff) | |
Add uncomment `add_type_info_type` calls for type assertions
Diffstat (limited to 'src/ptr_map.cpp')
| -rw-r--r-- | src/ptr_map.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/ptr_map.cpp b/src/ptr_map.cpp index c33bf9ffb..89d2cbf9d 100644 --- a/src/ptr_map.cpp +++ b/src/ptr_map.cpp @@ -52,6 +52,7 @@ template <typename K, typename V> gb_internal void map_init (PtrMap< template <typename K, typename V> gb_internal void map_destroy (PtrMap<K, V> *h); template <typename K, typename V> gb_internal V * map_get (PtrMap<K, V> *h, K key); template <typename K, typename V> gb_internal void map_set (PtrMap<K, V> *h, K key, V const &value); +template <typename K, typename V> gb_internal bool map_set_if_not_previously_exists(PtrMap<K, V> *h, K key, V const &value); // returns true if it previously existed template <typename K, typename V> gb_internal void map_remove (PtrMap<K, V> *h, K key); template <typename K, typename V> gb_internal void map_clear (PtrMap<K, V> *h); template <typename K, typename V> gb_internal void map_grow (PtrMap<K, V> *h); @@ -240,6 +241,34 @@ gb_internal void map_set(PtrMap<K, V> *h, K key, V const &value) { } } +// returns true if it previously existed +template <typename K, typename V> +gb_internal bool map_set_if_not_previously_exists(PtrMap<K, V> *h, K key, V const &value) { + MapIndex index; + MapFindResult fr; + if (h->hashes.count == 0) { + map_grow(h); + } + fr = map__find(h, key); + if (fr.entry_index != MAP_SENTINEL) { + return true; + } else { + index = map__add_entry(h, key); + if (fr.entry_prev != MAP_SENTINEL) { + h->entries.data[fr.entry_prev].next = index; + } else { + h->hashes.data[fr.hash_index] = index; + } + } + h->entries.data[index].value = value; + + if (map__full(h)) { + map_grow(h); + } + return false; +} + + template <typename K, typename V> gb_internal void map__erase(PtrMap<K, V> *h, MapFindResult const &fr) { MapFindResult last; |