From ac5f5a33e94054396de66a37043e226349b6c91c Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 21:17:07 +0000 Subject: `gb_internal` a lot --- src/ptr_map.cpp | 84 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) (limited to 'src/ptr_map.cpp') diff --git a/src/ptr_map.cpp b/src/ptr_map.cpp index ed4b20bf8..434680e91 100644 --- a/src/ptr_map.cpp +++ b/src/ptr_map.cpp @@ -26,7 +26,7 @@ struct PtrMap { }; -u32 ptr_map_hash_key(uintptr key) { +gb_internal gb_inline u32 ptr_map_hash_key(uintptr key) { #if defined(GB_ARCH_64_BIT) key = (~key) + (key << 21); key = key ^ (key >> 24); @@ -41,35 +41,35 @@ u32 ptr_map_hash_key(uintptr key) { return (word >> 22u) ^ word; #endif } -u32 ptr_map_hash_key(void const *key) { +gb_internal gb_inline u32 ptr_map_hash_key(void const *key) { return ptr_map_hash_key((uintptr)key); } -template void map_init (PtrMap *h, gbAllocator a, isize capacity = 16); -template void map_destroy (PtrMap *h); -template V * map_get (PtrMap *h, K key); -template void map_set (PtrMap *h, K key, V const &value); -template void map_remove (PtrMap *h, K key); -template void map_clear (PtrMap *h); -template void map_grow (PtrMap *h); -template void map_rehash (PtrMap *h, isize new_count); -template void map_reserve (PtrMap *h, isize cap); +template gb_internal void map_init (PtrMap *h, gbAllocator a, isize capacity = 16); +template gb_internal void map_destroy (PtrMap *h); +template gb_internal V * map_get (PtrMap *h, K key); +template gb_internal void map_set (PtrMap *h, K key, V const &value); +template gb_internal void map_remove (PtrMap *h, K key); +template gb_internal void map_clear (PtrMap *h); +template gb_internal void map_grow (PtrMap *h); +template gb_internal void map_rehash (PtrMap *h, isize new_count); +template gb_internal void map_reserve (PtrMap *h, isize cap); #if PTR_MAP_ENABLE_MULTI_MAP // Mutlivalued map procedure -template PtrMapEntry * multi_map_find_first(PtrMap *h, K key); -template PtrMapEntry * multi_map_find_next (PtrMap *h, PtrMapEntry *e); - -template isize multi_map_count (PtrMap *h, K key); -template void multi_map_get_all (PtrMap *h, K key, V *items); -template void multi_map_insert (PtrMap *h, K key, V const &value); -template void multi_map_remove (PtrMap *h, K key, PtrMapEntry *e); -template void multi_map_remove_all(PtrMap *h, K key); +template gb_internal PtrMapEntry * multi_map_find_first(PtrMap *h, K key); +template gb_internal PtrMapEntry * multi_map_find_next (PtrMap *h, PtrMapEntry *e); + +template gb_internal isize multi_map_count (PtrMap *h, K key); +template gb_internal void multi_map_get_all (PtrMap *h, K key, V *items); +template gb_internal void multi_map_insert (PtrMap *h, K key, V const &value); +template gb_internal void multi_map_remove (PtrMap *h, K key, PtrMapEntry *e); +template gb_internal void multi_map_remove_all(PtrMap *h, K key); #endif template -gb_inline void map_init(PtrMap *h, gbAllocator a, isize capacity) { +gb_internal gb_inline void map_init(PtrMap *h, gbAllocator a, isize capacity) { capacity = next_pow2_isize(capacity); slice_init(&h->hashes, a, capacity); array_init(&h->entries, a, 0, capacity); @@ -79,7 +79,7 @@ gb_inline void map_init(PtrMap *h, gbAllocator a, isize capacity) { } template -gb_inline void map_destroy(PtrMap *h) { +gb_internal gb_inline void map_destroy(PtrMap *h) { slice_free(&h->hashes, h->entries.allocator); array_free(&h->entries); } @@ -137,13 +137,13 @@ gb_internal b32 map__full(PtrMap *h) { } template -gb_inline void map_grow(PtrMap *h) { +gb_internal gb_inline void map_grow(PtrMap *h) { isize new_count = gb_max(h->hashes.count<<1, 16); map_rehash(h, new_count); } template -void map_reset_entries(PtrMap *h) { +gb_internal void map_reset_entries(PtrMap *h) { for (isize i = 0; i < h->hashes.count; i++) { h->hashes.data[i] = MAP_SENTINEL; } @@ -161,7 +161,7 @@ void map_reset_entries(PtrMap *h) { } template -void map_reserve(PtrMap *h, isize cap) { +gb_internal void map_reserve(PtrMap *h, isize cap) { array_reserve(&h->entries, cap); if (h->entries.count*2 < h->hashes.count) { return; @@ -172,12 +172,12 @@ void map_reserve(PtrMap *h, isize cap) { template -void map_rehash(PtrMap *h, isize new_count) { +gb_internal void map_rehash(PtrMap *h, isize new_count) { map_reserve(h, new_count); } template -V *map_get(PtrMap *h, K key) { +gb_internal V *map_get(PtrMap *h, K key) { MapIndex index = map__find(h, key).entry_index; if (index != MAP_SENTINEL) { return &h->entries.data[index].value; @@ -186,14 +186,14 @@ V *map_get(PtrMap *h, K key) { } template -V &map_must_get(PtrMap *h, K key) { +gb_internal V &map_must_get(PtrMap *h, K key) { MapIndex index = map__find(h, key).entry_index; GB_ASSERT(index != MAP_SENTINEL); return h->entries.data[index].value; } template -void map_set(PtrMap *h, K key, V const &value) { +gb_internal void map_set(PtrMap *h, K key, V const &value) { MapIndex index; MapFindResult fr; if (h->hashes.count == 0) { @@ -219,7 +219,7 @@ void map_set(PtrMap *h, K key, V const &value) { template -void map__erase(PtrMap *h, MapFindResult const &fr) { +gb_internal void map__erase(PtrMap *h, MapFindResult const &fr) { MapFindResult last; if (fr.entry_prev == MAP_SENTINEL) { h->hashes.data[fr.hash_index] = h->entries.data[fr.entry_index].next; @@ -242,7 +242,7 @@ void map__erase(PtrMap *h, MapFindResult const &fr) { } template -void map_remove(PtrMap *h, K key) { +gb_internal void map_remove(PtrMap *h, K key) { MapFindResult fr = map__find(h, key); if (fr.entry_index != MAP_SENTINEL) { map__erase(h, fr); @@ -250,7 +250,7 @@ void map_remove(PtrMap *h, K key) { } template -gb_inline void map_clear(PtrMap *h) { +gb_internal gb_inline void map_clear(PtrMap *h) { array_clear(&h->entries); for (isize i = 0; i < h->hashes.count; i++) { h->hashes.data[i] = MAP_SENTINEL; @@ -260,7 +260,7 @@ gb_inline void map_clear(PtrMap *h) { #if PTR_MAP_ENABLE_MULTI_MAP template -PtrMapEntry *multi_map_find_first(PtrMap *h, K key) { +gb_internal PtrMapEntry *multi_map_find_first(PtrMap *h, K key) { MapIndex i = map__find(h, key).entry_index; if (i == MAP_SENTINEL) { return nullptr; @@ -269,7 +269,7 @@ PtrMapEntry *multi_map_find_first(PtrMap *h, K key) { } template -PtrMapEntry *multi_map_find_next(PtrMap *h, PtrMapEntry *e) { +gb_internal PtrMapEntry *multi_map_find_next(PtrMap *h, PtrMapEntry *e) { MapIndex i = e->next; while (i != MAP_SENTINEL) { if (h->entries.data[i].key == e->key) { @@ -281,7 +281,7 @@ PtrMapEntry *multi_map_find_next(PtrMap *h, PtrMapEntry *e) { } template -isize multi_map_count(PtrMap *h, K key) { +gb_internal isize multi_map_count(PtrMap *h, K key) { isize count = 0; PtrMapEntry *e = multi_map_find_first(h, key); while (e != nullptr) { @@ -292,7 +292,7 @@ isize multi_map_count(PtrMap *h, K key) { } template -void multi_map_get_all(PtrMap *h, K key, V *items) { +gb_internal void multi_map_get_all(PtrMap *h, K key, V *items) { isize i = 0; PtrMapEntry *e = multi_map_find_first(h, key); while (e != nullptr) { @@ -302,7 +302,7 @@ void multi_map_get_all(PtrMap *h, K key, V *items) { } template -void multi_map_insert(PtrMap *h, K key, V const &value) { +gb_internal void multi_map_insert(PtrMap *h, K key, V const &value) { MapFindResult fr; MapIndex i; if (h->hashes.count == 0) { @@ -325,7 +325,7 @@ void multi_map_insert(PtrMap *h, K key, V const &value) { } template -void multi_map_remove(PtrMap *h, K key, PtrMapEntry *e) { +gb_internal void multi_map_remove(PtrMap *h, K key, PtrMapEntry *e) { MapFindResult fr = map__find_from_entry(h, e); if (fr.entry_index != MAP_SENTINEL) { map__erase(h, fr); @@ -333,7 +333,7 @@ void multi_map_remove(PtrMap *h, K key, PtrMapEntry *e) { } template -void multi_map_remove_all(PtrMap *h, K key) { +gb_internal void multi_map_remove_all(PtrMap *h, K key) { while (map_get(h, key) != nullptr) { map_remove(h, key); } @@ -342,21 +342,21 @@ void multi_map_remove_all(PtrMap *h, K key) { template -PtrMapEntry *begin(PtrMap &m) { +gb_internal PtrMapEntry *begin(PtrMap &m) { return m.entries.data; } template -PtrMapEntry const *begin(PtrMap const &m) { +gb_internal PtrMapEntry const *begin(PtrMap const &m) { return m.entries.data; } template -PtrMapEntry *end(PtrMap &m) { +gb_internal PtrMapEntry *end(PtrMap &m) { return m.entries.data + m.entries.count; } template -PtrMapEntry const *end(PtrMap const &m) { +gb_internal PtrMapEntry const *end(PtrMap const &m) { return m.entries.data + m.entries.count; } -- cgit v1.2.3