From b59333294204fd3e298483aea09bc4fab589de94 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Tue, 27 Sep 2016 15:28:44 +0100 Subject: Minimal Dependency Map: Only build what is needed --- src/common.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/common.cpp') diff --git a/src/common.cpp b/src/common.cpp index c807e8565..b714f1588 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -55,7 +55,7 @@ struct BlockTimer { } ~BlockTimer() { finish = gb_utc_time_now(); - gb_printf_err("%s - %llu us\n", finish-start); + gb_printf_err("%llu us\n", finish-start); } }; @@ -63,7 +63,10 @@ struct BlockTimer { // Hasing struct HashKey { - u64 key; + union { + u64 key; + void *ptr; + }; b32 is_string; String string; // if String, s.len > 0 }; @@ -182,13 +185,13 @@ template void map_clear (Map *h); template void map_grow (Map *h); template void map_rehash (Map *h, isize new_count); -template typename MapEntry *multi_map_find_first(Map *h, HashKey key); -template typename MapEntry *multi_map_find_next (Map *h, typename MapEntry *e); +template MapEntry *multi_map_find_first(Map *h, HashKey key); +template MapEntry *multi_map_find_next (Map *h, MapEntry *e); template isize multi_map_count (Map *h, HashKey key); template void multi_map_get_all (Map *h, HashKey key, T *items); template void multi_map_insert (Map *h, HashKey key, T value); -template void multi_map_remove (Map *h, HashKey key, typename MapEntry *e); +template void multi_map_remove (Map *h, HashKey key, MapEntry *e); template void multi_map_remove_all(Map *h, HashKey key); @@ -232,7 +235,7 @@ gb_internal MapFindResult map__find(Map *h, HashKey key) { } template -gb_internal MapFindResult map__find(Map *h, typename MapEntry *e) { +gb_internal MapFindResult map__find(Map *h, MapEntry *e) { MapFindResult fr = {-1, -1, -1}; if (gb_array_count(h->hashes) > 0) { fr.hash_index = e->key.key % gb_array_count(h->hashes); @@ -359,7 +362,7 @@ gb_inline void map_clear(Map *h) { template -typename MapEntry *multi_map_find_first(Map *h, HashKey key) { +MapEntry *multi_map_find_first(Map *h, HashKey key) { isize i = map__find(h, key).entry_index; if (i < 0) { return NULL; @@ -368,7 +371,7 @@ typename MapEntry *multi_map_find_first(Map *h, HashKey key) { } template -typename MapEntry *multi_map_find_next(Map *h, typename MapEntry *e) { +MapEntry *multi_map_find_next(Map *h, MapEntry *e) { isize i = e->next; while (i >= 0) { if (hash_key_equal(h->entries[i].key, e->key)) { @@ -420,7 +423,7 @@ void multi_map_insert(Map *h, HashKey key, T value) { } template -void multi_map_remove(Map *h, HashKey key, typename MapEntry *e) { +void multi_map_remove(Map *h, HashKey key, MapEntry *e) { MapFindResult fr = map__find(h, e); if (fr.entry_index >= 0) { map__erase(h, fr); -- cgit v1.2.3