| 151 | } |
| 152 | |
| 153 | void hashmap_init(struct hashmap *map, hashmap_cmp_fn equals_function, |
| 154 | const void *cmpfn_data, size_t initial_size) |
| 155 | { |
| 156 | unsigned int size = HASHMAP_INITIAL_SIZE; |
| 157 | |
| 158 | memset(map, 0, sizeof(*map)); |
| 159 | |
| 160 | map->cmpfn = equals_function ? equals_function : always_equal; |
| 161 | map->cmpfn_data = cmpfn_data; |
| 162 | |
| 163 | /* calculate initial table size and allocate the table */ |
| 164 | initial_size = (unsigned int) ((uint64_t) initial_size * 100 |
| 165 | / HASHMAP_LOAD_FACTOR); |
| 166 | while (initial_size > size) |
| 167 | size <<= HASHMAP_RESIZE_BITS; |
| 168 | alloc_table(map, size); |
| 169 | |
| 170 | /* |
| 171 | * Keep track of the number of items in the map and |
| 172 | * allow the map to automatically grow as necessary. |
| 173 | */ |
| 174 | map->do_count_items = 1; |
| 175 | } |
| 176 | |
| 177 | static void free_individual_entries(struct hashmap *map, ssize_t entry_offset) |
| 178 | { |