Home | History | Annotate | Download | only in libcutils

Lines Matching refs:map

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