25#define INITIAL_SIZE 1024
26#define LOAD_FACTOR 0.75
27#define LARGE_MAP_THRESHOLD (2ULL * 1024 * 1024 * 1024 / sizeof(kv_pair_t))
28#define LARGE_GROWTH_FACTOR 1.25
136 size_t old_size = map->
size;
139 map->
size = new_size;
142 for(
size_t i = 0; i < old_size; i++)
143 if(old_table[i].key != 0)
146 size_t idx = old_table[i].
key % new_size;
148 while(map->
table[idx].
key != 0) idx = (idx + 1) % new_size;
150 map->
table[idx] = old_table[i];
189 size_t idx = key % map->
size;
193 if(map->
table[idx].
key == key)
return false;
230 size_t idx = key % map->
size;
240 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.
static size_t calculate_new_size(size_t current_size)
Calculates the new size for hash map resizing.
#define LARGE_GROWTH_FACTOR
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.
#define LARGE_MAP_THRESHOLD
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.