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/string_map.cpp | 82 +++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'src/string_map.cpp') diff --git a/src/string_map.cpp b/src/string_map.cpp index e2a4d5f65..e289d4c9b 100644 --- a/src/string_map.cpp +++ b/src/string_map.cpp @@ -3,7 +3,7 @@ struct StringHashKey { String string; }; -gb_inline StringHashKey string_hash_string(String const &s) { +gb_internal gb_inline StringHashKey string_hash_string(String const &s) { StringHashKey hash_key = {}; hash_key.hash = fnv32a(s.text, s.len); hash_key.string = s; @@ -11,15 +11,15 @@ gb_inline StringHashKey string_hash_string(String const &s) { } -bool string_hash_key_equal(StringHashKey const &a, StringHashKey const &b) { +gb_internal gb_inline bool string_hash_key_equal(StringHashKey const &a, StringHashKey const &b) { if (a.hash == b.hash) { // NOTE(bill): If two string's hashes collide, compare the strings themselves return a.string == b.string; } return false; } -bool operator==(StringHashKey const &a, StringHashKey const &b) { return string_hash_key_equal(a, b); } -bool operator!=(StringHashKey const &a, StringHashKey const &b) { return !string_hash_key_equal(a, b); } +gb_internal bool operator==(StringHashKey const &a, StringHashKey const &b) { return string_hash_key_equal(a, b); } +gb_internal bool operator!=(StringHashKey const &a, StringHashKey const &b) { return !string_hash_key_equal(a, b); } template struct StringMapEntry { @@ -37,29 +37,29 @@ struct StringMap { }; -template void string_map_init (StringMap *h, gbAllocator a, isize capacity = 16); -template void string_map_destroy (StringMap *h); +template gb_internal void string_map_init (StringMap *h, gbAllocator a, isize capacity = 16); +template gb_internal void string_map_destroy (StringMap *h); -template T * string_map_get (StringMap *h, char const *key); -template T * string_map_get (StringMap *h, String const &key); -template T * string_map_get (StringMap *h, StringHashKey const &key); +template gb_internal T * string_map_get (StringMap *h, char const *key); +template gb_internal T * string_map_get (StringMap *h, String const &key); +template gb_internal T * string_map_get (StringMap *h, StringHashKey const &key); -template T & string_map_must_get (StringMap *h, char const *key); -template T & string_map_must_get (StringMap *h, String const &key); -template T & string_map_must_get (StringMap *h, StringHashKey const &key); +template gb_internal T & string_map_must_get (StringMap *h, char const *key); +template gb_internal T & string_map_must_get (StringMap *h, String const &key); +template gb_internal T & string_map_must_get (StringMap *h, StringHashKey const &key); -template void string_map_set (StringMap *h, StringHashKey const &key, T const &value); -template void string_map_set (StringMap *h, String const &key, T const &value); -template void string_map_set (StringMap *h, char const *key, T const &value); +template gb_internal void string_map_set (StringMap *h, StringHashKey const &key, T const &value); +template gb_internal void string_map_set (StringMap *h, String const &key, T const &value); +template gb_internal void string_map_set (StringMap *h, char const *key, T const &value); -template void string_map_remove (StringMap *h, StringHashKey const &key); -template void string_map_clear (StringMap *h); -template void string_map_grow (StringMap *h); -template void string_map_rehash (StringMap *h, isize new_count); -template void string_map_reserve (StringMap *h, isize cap); +template gb_internal void string_map_remove (StringMap *h, StringHashKey const &key); +template gb_internal void string_map_clear (StringMap *h); +template gb_internal void string_map_grow (StringMap *h); +template gb_internal void string_map_rehash (StringMap *h, isize new_count); +template gb_internal void string_map_reserve (StringMap *h, isize cap); template -gb_inline void string_map_init(StringMap *h, gbAllocator a, isize capacity) { +gb_internal gb_inline void string_map_init(StringMap *h, gbAllocator a, isize capacity) { capacity = next_pow2_isize(capacity); slice_init(&h->hashes, a, capacity); array_init(&h->entries, a, 0, capacity); @@ -69,7 +69,7 @@ gb_inline void string_map_init(StringMap *h, gbAllocator a, isize capacity) { } template -gb_inline void string_map_destroy(StringMap *h) { +gb_internal gb_inline void string_map_destroy(StringMap *h) { slice_free(&h->hashes, h->entries.allocator); array_free(&h->entries); } @@ -130,7 +130,7 @@ gb_inline void string_map_grow(StringMap *h) { template -void string_map_reset_entries(StringMap *h) { +gb_internal void string_map_reset_entries(StringMap *h) { for (isize i = 0; i < h->hashes.count; i++) { h->hashes.data[i] = MAP_SENTINEL; } @@ -148,7 +148,7 @@ void string_map_reset_entries(StringMap *h) { } template -void string_map_reserve(StringMap *h, isize cap) { +gb_internal void string_map_reserve(StringMap *h, isize cap) { array_reserve(&h->entries, cap); if (h->entries.count*2 < h->hashes.count) { return; @@ -159,12 +159,12 @@ void string_map_reserve(StringMap *h, isize cap) { template -void string_map_rehash(StringMap *h, isize new_count) { +gb_internal void string_map_rehash(StringMap *h, isize new_count) { string_map_reserve(h, new_count); } template -T *string_map_get(StringMap *h, StringHashKey const &key) { +gb_internal T *string_map_get(StringMap *h, StringHashKey const &key) { isize index = string_map__find(h, key).entry_index; if (index != MAP_SENTINEL) { return &h->entries.data[index].value; @@ -173,34 +173,34 @@ T *string_map_get(StringMap *h, StringHashKey const &key) { } template -gb_inline T *string_map_get(StringMap *h, String const &key) { +gb_internal gb_inline T *string_map_get(StringMap *h, String const &key) { return string_map_get(h, string_hash_string(key)); } template -gb_inline T *string_map_get(StringMap *h, char const *key) { +gb_internal gb_inline T *string_map_get(StringMap *h, char const *key) { return string_map_get(h, string_hash_string(make_string_c(key))); } template -T &string_map_must_get(StringMap *h, StringHashKey const &key) { +gb_internal T &string_map_must_get(StringMap *h, StringHashKey const &key) { isize index = string_map__find(h, key).entry_index; GB_ASSERT(index != MAP_SENTINEL); return h->entries.data[index].value; } template -gb_inline T &string_map_must_get(StringMap *h, String const &key) { +gb_internal gb_inline T &string_map_must_get(StringMap *h, String const &key) { return string_map_must_get(h, string_hash_string(key)); } template -gb_inline T &string_map_must_get(StringMap *h, char const *key) { +gb_internal gb_inline T &string_map_must_get(StringMap *h, char const *key) { return string_map_must_get(h, string_hash_string(make_string_c(key))); } template -void string_map_set(StringMap *h, StringHashKey const &key, T const &value) { +gb_internal void string_map_set(StringMap *h, StringHashKey const &key, T const &value) { MapIndex index; MapFindResult fr; if (h->hashes.count == 0) { @@ -225,18 +225,18 @@ void string_map_set(StringMap *h, StringHashKey const &key, T const &value) { } template -gb_inline void string_map_set(StringMap *h, String const &key, T const &value) { +gb_internal gb_inline void string_map_set(StringMap *h, String const &key, T const &value) { string_map_set(h, string_hash_string(key), value); } template -gb_inline void string_map_set(StringMap *h, char const *key, T const &value) { +gb_internal gb_inline void string_map_set(StringMap *h, char const *key, T const &value) { string_map_set(h, string_hash_string(make_string_c(key)), value); } template -void string_map__erase(StringMap *h, MapFindResult const &fr) { +gb_internal void string_map__erase(StringMap *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; @@ -257,7 +257,7 @@ void string_map__erase(StringMap *h, MapFindResult const &fr) { } template -void string_map_remove(StringMap *h, StringHashKey const &key) { +gb_internal void string_map_remove(StringMap *h, StringHashKey const &key) { MapFindResult fr = string_map__find(h, key); if (fr.entry_index != MAP_SENTINEL) { string_map__erase(h, fr); @@ -265,7 +265,7 @@ void string_map_remove(StringMap *h, StringHashKey const &key) { } template -gb_inline void string_map_clear(StringMap *h) { +gb_internal gb_inline void string_map_clear(StringMap *h) { array_clear(&h->entries); for (isize i = 0; i < h->hashes.count; i++) { h->hashes.data[i] = MAP_SENTINEL; @@ -275,21 +275,21 @@ gb_inline void string_map_clear(StringMap *h) { template -StringMapEntry *begin(StringMap &m) { +gb_internal StringMapEntry *begin(StringMap &m) { return m.entries.data; } template -StringMapEntry const *begin(StringMap const &m) { +gb_internal StringMapEntry const *begin(StringMap const &m) { return m.entries.data; } template -StringMapEntry *end(StringMap &m) { +gb_internal StringMapEntry *end(StringMap &m) { return m.entries.data + m.entries.count; } template -StringMapEntry const *end(StringMap const &m) { +gb_internal StringMapEntry const *end(StringMap const &m) { return m.entries.data + m.entries.count; } \ No newline at end of file -- cgit v1.2.3