diff options
| author | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-10 12:54:18 +0100 |
|---|---|---|
| committer | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-10 12:54:18 +0100 |
| commit | 949cceeaa87a76d647660d3585ef9338bfaa3781 (patch) | |
| tree | 266d15b3a270bf0357e19f5058d75df67df7ea41 /src/hash.h | |
| parent | b9d3576c1402c530aef200e8832f13eecda5070d (diff) | |
formatting
Diffstat (limited to 'src/hash.h')
| -rw-r--r-- | src/hash.h | 49 |
1 files changed, 26 insertions, 23 deletions
@@ -1,49 +1,53 @@ #pragma once +#include <mimalloc.h> + +#include <cstring> + #include "hashmap.h" #include "utils.h" -#include <cstring> -#include <mimalloc.h> #define WAYC_HASHMAP_SEED 0 #define WAYC_HASHMAP_CAP 16 -template <typename K, typename V> struct hashentry_s { +template <typename K, typename V> +struct hashentry_s { K key; V value; }; template <typename K, typename V> -inline u64 wayc_hashentry_hash(const void *item, uint64_t seed0, +inline u64 wayc_hashentry_hash(const void* item, uint64_t seed0, uint64_t seed1) { wayc_notnull(item); - const hashentry_s<K, V> *entry = (const hashentry_s<K, V> *)item; + const hashentry_s<K, V>* entry = (const hashentry_s<K, V>*)item; return hashmap_murmur(&entry->key, sizeof(K), seed0, seed1); } template <typename K, typename V> -inline i32 wayc_hashentry_compare(const void *a, const void *b, void *udata) { +inline i32 wayc_hashentry_compare(const void* a, const void* b, void* udata) { (void)udata; wayc_notnull(a); wayc_notnull(b); - const hashentry_s<K, V> *entry_a = (const hashentry_s<K, V> *)a; - const hashentry_s<K, V> *entry_b = (const hashentry_s<K, V> *)b; + const hashentry_s<K, V>* entry_a = (const hashentry_s<K, V>*)a; + const hashentry_s<K, V>* entry_b = (const hashentry_s<K, V>*)b; return memcmp(&entry_a->key, &entry_b->key, sizeof(K)); } -template <typename K, typename V> struct hashmap_s { - struct hashmap *inner; +template <typename K, typename V> +struct hashmap_s { + struct hashmap* inner; }; template <typename K, typename V> -inline void wayc_hashmap_init(hashmap_s<K, V> *map) { +inline void wayc_hashmap_init(hashmap_s<K, V>* map) { wayc_notnull(map); memset(map, 0, sizeof(*map)); - struct hashmap *inner; + struct hashmap* inner; inner = hashmap_new_with_allocator( mi_malloc, mi_realloc, mi_free, sizeof(hashentry_s<K, V>), WAYC_HASHMAP_CAP, WAYC_HASHMAP_SEED, WAYC_HASHMAP_SEED, @@ -56,14 +60,14 @@ inline void wayc_hashmap_init(hashmap_s<K, V> *map) { } template <typename K, typename V> -inline void wayc_hashmap_deinit(hashmap_s<K, V> *map) { +inline void wayc_hashmap_deinit(hashmap_s<K, V>* map) { wayc_notnull(map); hashmap_free(map->inner); } template <typename K, typename V> -inline V *wayc_hashmap_insert(hashmap_s<K, V> *map, const K *key, - const V *value) { +inline V* wayc_hashmap_insert(hashmap_s<K, V>* map, const K* key, + const V* value) { wayc_notnull(map); wayc_notnull(key); wayc_notnull(value); @@ -71,27 +75,26 @@ inline V *wayc_hashmap_insert(hashmap_s<K, V> *map, const K *key, hashentry_s<K, V> entry{}; entry.key = *key; entry.value = *value; - hashentry_s<K, V> *stored = - (hashentry_s<K, V> *)hashmap_set(map->inner, &entry); + hashentry_s<K, V>* stored = + (hashentry_s<K, V>*)hashmap_set(map->inner, &entry); return &stored->value; } template <typename K, typename V> -inline V *wayc_hashmap_get(hashmap_s<K, V> *map, const K *key) { +inline V* wayc_hashmap_get(hashmap_s<K, V>* map, const K* key) { wayc_notnull(map); wayc_notnull(key); hashentry_s<K, V> entry{}; entry.key = *key; - auto *stored = (hashentry_s<K, V> *)hashmap_get(map->inner, &entry); - if (!stored) - return nullptr; + auto* stored = (hashentry_s<K, V>*)hashmap_get(map->inner, &entry); + if (!stored) return nullptr; return &stored->value; } template <typename K, typename V> -inline void wayc_hashmap_remove(hashmap_s<K, V> *map, const K *key) { +inline void wayc_hashmap_remove(hashmap_s<K, V>* map, const K* key) { wayc_notnull(map); wayc_notnull(key); @@ -101,7 +104,7 @@ inline void wayc_hashmap_remove(hashmap_s<K, V> *map, const K *key) { } template <typename K, typename V> -inline usize wayc_hashmap_count(hashmap_s<K, V> *map) { +inline usize wayc_hashmap_count(hashmap_s<K, V>* map) { wayc_notnull(map); return hashmap_count(map->inner); }
\ No newline at end of file |
