Lines Matching refs:map
48 Hashmap* map = malloc(sizeof(Hashmap)); in hashmapCreate() local
49 if (map == NULL) { in hashmapCreate()
55 map->bucketCount = 1; in hashmapCreate()
56 while (map->bucketCount <= minimumBucketCount) { in hashmapCreate()
58 map->bucketCount <<= 1; in hashmapCreate()
61 map->buckets = calloc(map->bucketCount, sizeof(Entry*)); in hashmapCreate()
62 if (map->buckets == NULL) { in hashmapCreate()
63 free(map); in hashmapCreate()
67 map->size = 0; in hashmapCreate()
69 map->hash = hash; in hashmapCreate()
70 map->equals = equals; in hashmapCreate()
72 mutex_init(&map->lock); in hashmapCreate()
74 return map; in hashmapCreate()
80 static inline int hashKey(Hashmap* map, void* key) { in hashKey() argument
81 int h = map->hash(key); in hashKey()
93 size_t hashmapSize(Hashmap* map) { in hashmapSize() argument
94 return map->size; in hashmapSize()
101 static void expandIfNecessary(Hashmap* map) { in expandIfNecessary() argument
103 if (map->size > (map->bucketCount * 3 / 4)) { in expandIfNecessary()
105 size_t newBucketCount = map->bucketCount << 1; in expandIfNecessary()
114 for (i = 0; i < map->bucketCount; i++) { in expandIfNecessary()
115 Entry* entry = map->buckets[i]; in expandIfNecessary()
126 free(map->buckets); in expandIfNecessary()
127 map->buckets = newBuckets; in expandIfNecessary()
128 map->bucketCount = newBucketCount; in expandIfNecessary()
132 void hashmapLock(Hashmap* map) { in hashmapLock() argument
133 mutex_lock(&map->lock); in hashmapLock()
136 void hashmapUnlock(Hashmap* map) { in hashmapUnlock() argument
137 mutex_unlock(&map->lock); in hashmapUnlock()
140 void hashmapFree(Hashmap* map) { in hashmapFree() argument
142 for (i = 0; i < map->bucketCount; i++) { in hashmapFree()
143 Entry* entry = map->buckets[i]; in hashmapFree()
150 free(map->buckets); in hashmapFree()
151 mutex_destroy(&map->lock); in hashmapFree()
152 free(map); in hashmapFree()
189 void* hashmapPut(Hashmap* map, void* key, void* value) { in hashmapPut() argument
190 int hash = hashKey(map, key); in hashmapPut()
191 size_t index = calculateIndex(map->bucketCount, hash); in hashmapPut()
193 Entry** p = &(map->buckets[index]); in hashmapPut()
204 map->size++; in hashmapPut()
205 expandIfNecessary(map); in hashmapPut()
210 if (equalKeys(current->key, current->hash, key, hash, map->equals)) { in hashmapPut()
221 void* hashmapGet(Hashmap* map, void* key) { in hashmapGet() argument
222 int hash = hashKey(map, key); in hashmapGet()
223 size_t index = calculateIndex(map->bucketCount, hash); in hashmapGet()
225 Entry* entry = map->buckets[index]; in hashmapGet()
227 if (equalKeys(entry->key, entry->hash, key, hash, map->equals)) { in hashmapGet()
236 bool hashmapContainsKey(Hashmap* map, void* key) { in hashmapContainsKey() argument
237 int hash = hashKey(map, key); in hashmapContainsKey()
238 size_t index = calculateIndex(map->bucketCount, hash); in hashmapContainsKey()
240 Entry* entry = map->buckets[index]; in hashmapContainsKey()
242 if (equalKeys(entry->key, entry->hash, key, hash, map->equals)) { in hashmapContainsKey()
251 void* hashmapMemoize(Hashmap* map, void* key, in hashmapMemoize() argument
253 int hash = hashKey(map, key); in hashmapMemoize()
254 size_t index = calculateIndex(map->bucketCount, hash); in hashmapMemoize()
256 Entry** p = &(map->buckets[index]); in hashmapMemoize()
269 map->size++; in hashmapMemoize()
270 expandIfNecessary(map); in hashmapMemoize()
275 if (equalKeys(current->key, current->hash, key, hash, map->equals)) { in hashmapMemoize()
284 void* hashmapRemove(Hashmap* map, void* key) { in hashmapRemove() argument
285 int hash = hashKey(map, key); in hashmapRemove()
286 size_t index = calculateIndex(map->bucketCount, hash); in hashmapRemove()
289 Entry** p = &(map->buckets[index]); in hashmapRemove()
292 if (equalKeys(current->key, current->hash, key, hash, map->equals)) { in hashmapRemove()
296 map->size--; in hashmapRemove()
306 void hashmapForEach(Hashmap* map, in hashmapForEach() argument
310 for (i = 0; i < map->bucketCount; i++) { in hashmapForEach()
311 Entry* entry = map->buckets[i]; in hashmapForEach()
322 size_t hashmapCurrentCapacity(Hashmap* map) { in hashmapCurrentCapacity() argument
323 size_t bucketCount = map->bucketCount; in hashmapCurrentCapacity()
327 size_t hashmapCountCollisions(Hashmap* map) { in hashmapCountCollisions() argument
330 for (i = 0; i < map->bucketCount; i++) { in hashmapCountCollisions()
331 Entry* entry = map->buckets[i]; in hashmapCountCollisions()