25#define INITIAL_SIZE 1024
26#define LOAD_FACTOR 0.75
104 size_t old_size = map->
size;
107 map->
size = new_size;
110 for(
size_t i = 0; i < old_size; i++)
111 if(old_table[i].key != 0)
114 size_t idx = old_table[i].
key % new_size;
116 while(map->
table[idx].
key != 0) idx = (idx + 1) % new_size;
118 map->
table[idx] = old_table[i];
157 size_t idx = key % map->
size;
161 if(map->
table[idx].
key == key)
return false;
198 size_t idx = key % map->
size;
208 idx = (idx + 1) % map->
size;
bool lookup_map(const hash_map_t *map, uint64_t key, uint64_t *out_value)
Looks up a value by key in the hash map.
hash_map_t * create_map(size_t size)
Creates a new hash map with the specified initial size.
bool insert_map(hash_map_t *map, uint64_t key, uint64_t value)
Inserts a key-value pair into the hash map.
void free_map(hash_map_t *map)
Frees all memory associated with a hash map.
static void resize_map(hash_map_t *map, size_t new_size)
Resizes the hash map to a new size and rehashes all entries.
Minimal open-addressing hash map for 64-bit key/value pairs used in deduplication lookup.
size_t count
Number of active (filled) entries.
size_t size
Allocated slot capacity of table.
kv_pair_t * table
Array of key/value slots of length == size.
Single key/value slot used internally by the open-addressing hash map.
uint64_t value
Associated value payload (64-bit) stored alongside the key.
uint64_t key
Stored key (64-bit). May use a reserved sentinel to denote an empty slot.