kiba-engine
hash_table.h
1 #pragma once
2 
4 #include <kiba/defines.h>
5 
6 // TODO restructure this. try an array of keys and values instead
7 typedef struct hash_table_entry {
8  u64 hash;
9  usize key_size;
10  void *key;
11  uptr value;
13 
14 typedef struct hash_table {
15  usize size;
16  usize capacity;
17  f64 max_load;
18  allocator *alloc;
19  hash_table_entry *data;
20 } hash_table;
21 
22 KB_API b8 hash_table_create(hash_table *table, usize initial_capacity, f64 max_load, allocator *alloc);
23 
24 KB_API void hash_table_destroy(hash_table *table);
25 
26 KB_API b8 hash_table_set(hash_table *table, const void *key, usize key_size, uptr value);
27 
28 KB_API b8 hash_table_get(hash_table *table, const void *key, usize key_size, void *value_ptr);
29 
30 #define hash_table_for_each(table) \
31  for (hash_table_entry *entry = (table).data; entry < (table).data + (table).capacity; ++entry) \
32  if (entry->key_size != 0)
Central header providing allocator functionality.
Global typedefs and macros.
Central allocator structure.
Definition: allocator.h:87
Definition: hash_table.h:7