Lines Matching refs:map

48     Hashmap* map = static_cast<Hashmap*>(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 = static_cast<Entry**>(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 pthread_mutex_init(&map->lock, nullptr); in hashmapCreate()
74 return map; in hashmapCreate()
83 static inline int hashKey(Hashmap* map, void* key) { in hashKey() argument
84 int h = map->hash(key); in hashKey()
100 static void expandIfNecessary(Hashmap* map) { in expandIfNecessary() argument
102 if (map->size > (map->bucketCount * 3 / 4)) { in expandIfNecessary()
104 size_t newBucketCount = map->bucketCount << 1; in expandIfNecessary()
113 for (i = 0; i < map->bucketCount; i++) { in expandIfNecessary()
114 Entry* entry = map->buckets[i]; in expandIfNecessary()
125 free(map->buckets); in expandIfNecessary()
126 map->buckets = newBuckets; in expandIfNecessary()
127 map->bucketCount = newBucketCount; in expandIfNecessary()
131 void hashmapLock(Hashmap* map) { in hashmapLock() argument
132 pthread_mutex_lock(&map->lock); in hashmapLock()
135 void hashmapUnlock(Hashmap* map) { in hashmapUnlock() argument
136 pthread_mutex_unlock(&map->lock); in hashmapUnlock()
139 void hashmapFree(Hashmap* map) { in hashmapFree() argument
141 for (i = 0; i < map->bucketCount; i++) { in hashmapFree()
142 Entry* entry = map->buckets[i]; in hashmapFree()
149 free(map->buckets); in hashmapFree()
150 pthread_mutex_destroy(&map->lock); in hashmapFree()
151 free(map); in hashmapFree()
192 void* hashmapPut(Hashmap* map, void* key, void* value) { in hashmapPut() argument
193 int hash = hashKey(map, key); in hashmapPut()
194 size_t index = calculateIndex(map->bucketCount, hash); in hashmapPut()
196 Entry** p = &(map->buckets[index]); in hashmapPut()
207 map->size++; in hashmapPut()
208 expandIfNecessary(map); in hashmapPut()
213 if (equalKeys(current->key, current->hash, key, hash, map->equals)) { in hashmapPut()
224 void* hashmapGet(Hashmap* map, void* key) { in hashmapGet() argument
225 int hash = hashKey(map, key); in hashmapGet()
226 size_t index = calculateIndex(map->bucketCount, hash); in hashmapGet()
228 Entry* entry = map->buckets[index]; in hashmapGet()
230 if (equalKeys(entry->key, entry->hash, key, hash, map->equals)) { in hashmapGet()
239 void* hashmapRemove(Hashmap* map, void* key) { in hashmapRemove() argument
240 int hash = hashKey(map, key); in hashmapRemove()
241 size_t index = calculateIndex(map->bucketCount, hash); in hashmapRemove()
244 Entry** p = &(map->buckets[index]); in hashmapRemove()
247 if (equalKeys(current->key, current->hash, key, hash, map->equals)) { in hashmapRemove()
251 map->size--; in hashmapRemove()
261 void hashmapForEach(Hashmap* map, bool (*callback)(void* key, void* value, void* context), in hashmapForEach() argument
264 for (i = 0; i < map->bucketCount; i++) { in hashmapForEach()
265 Entry* entry = map->buckets[i]; in hashmapForEach()