Home | History | Annotate | Download | only in libcutils

Lines Matching refs:map

49     Hashmap* map = static_cast<Hashmap*>(malloc(sizeof(Hashmap)));
50 if (map == NULL) {
56 map->bucketCount = 1;
57 while (map->bucketCount <= minimumBucketCount) {
59 map->bucketCount <<= 1;
62 map->buckets = static_cast<Entry**>(calloc(map->bucketCount, sizeof(Entry*)));
63 if (map->buckets == NULL) {
64 free(map);
68 map->size = 0;
70 map->hash = hash;
71 map->equals = equals;
73 mutex_init(&map->lock);
75 return map;
84 static inline int hashKey(Hashmap* map, void* key) {
85 int h = map->hash(key);
97 size_t hashmapSize(Hashmap* map) {
98 return map->size;
105 static void expandIfNecessary(Hashmap* map) {
107 if (map->size > (map->bucketCount * 3 / 4)) {
109 size_t newBucketCount = map->bucketCount << 1;
118 for (i = 0; i < map->bucketCount; i++) {
119 Entry* entry = map->buckets[i];
130 free(map->buckets);
131 map->buckets = newBuckets;
132 map->bucketCount = newBucketCount;
136 void hashmapLock(Hashmap* map) {
137 mutex_lock(&map->lock);
140 void hashmapUnlock(Hashmap* map) {
141 mutex_unlock(&map->lock);
144 void hashmapFree(Hashmap* map) {
146 for (i = 0; i < map->bucketCount; i++) {
147 Entry* entry = map->buckets[i];
154 free(map->buckets);
155 mutex_destroy(&map->lock);
156 free(map);
197 void* hashmapPut(Hashmap* map, void* key, void* value) {
198 int hash = hashKey(map, key);
199 size_t index = calculateIndex(map->bucketCount, hash);
201 Entry** p = &(map->buckets[index]);
212 map->size++;
213 expandIfNecessary(map);
218 if (equalKeys(current->key, current->hash, key, hash, map->equals)) {
229 void* hashmapGet(Hashmap* map, void* key) {
230 int hash = hashKey(map, key);
231 size_t index = calculateIndex(map->bucketCount, hash);
233 Entry* entry = map->buckets[index];
235 if (equalKeys(entry->key, entry->hash, key, hash, map->equals)) {
244 bool hashmapContainsKey(Hashmap* map, void* key) {
245 int hash = hashKey(map, key);
246 size_t index = calculateIndex(map->bucketCount, hash);
248 Entry* entry = map->buckets[index];
250 if (equalKeys(entry->key, entry->hash, key, hash, map->equals)) {
259 void* hashmapMemoize(Hashmap* map, void* key,
261 int hash = hashKey(map, key);
262 size_t index = calculateIndex(map->bucketCount, hash);
264 Entry** p = &(map->buckets[index]);
277 map->size++;
278 expandIfNecessary(map);
283 if (equalKeys(current->key, current->hash, key, hash, map->equals)) {
292 void* hashmapRemove(Hashmap* map, void* key) {
293 int hash = hashKey(map, key);
294 size_t index = calculateIndex(map->bucketCount, hash);
297 Entry** p = &(map->buckets[index]);
300 if (equalKeys(current->key, current->hash, key, hash, map->equals)) {
304 map->size--;
314 void hashmapForEach(Hashmap* map,
318 for (i = 0; i < map->bucketCount; i++) {
319 Entry* entry = map->buckets[i];
330 size_t hashmapCurrentCapacity(Hashmap* map) {
331 size_t bucketCount = map->bucketCount;
335 size_t hashmapCountCollisions(Hashmap* map) {
338 for (i = 0; i < map->bucketCount; i++) {
339 Entry* entry = map->buckets[i];