Lines Matching refs:ht
44 HashTable ht = malloc(sizeof(struct HashTableRec)); in ht_create() local
46 if (!ht) { in ht_create()
50 ht->keySize = keySize; in ht_create()
51 ht->dataSize = dataSize; in ht_create()
52 ht->hash = hash; in ht_create()
53 ht->compare = compare; in ht_create()
54 ht->elements = 0; in ht_create()
55 ht->bucketBits = INITHASHSIZE; in ht_create()
56 numBuckets = 1 << ht->bucketBits; in ht_create()
57 ht->buckets = xallocarray(numBuckets, sizeof(*ht->buckets)); in ht_create()
58 ht->cdata = cdata; in ht_create()
60 if (ht->buckets) { in ht_create()
62 xorg_list_init(&ht->buckets[c]); in ht_create()
64 return ht; in ht_create()
66 free(ht); in ht_create()
72 ht_destroy(HashTable ht) in ht_destroy() argument
76 int numBuckets = 1 << ht->bucketBits; in ht_destroy()
78 xorg_list_for_each_entry_safe(it, tmp, &ht->buckets[c], l) { in ht_destroy()
85 free(ht->buckets); in ht_destroy()
86 free(ht); in ht_destroy()
90 double_size(HashTable ht) in double_size() argument
93 int numBuckets = 1 << ht->bucketBits; in double_size()
94 int newBucketBits = ht->bucketBits + 1; in double_size()
98 newBuckets = xallocarray(newNumBuckets, sizeof(*ht->buckets)); in double_size()
106 xorg_list_for_each_entry_safe(it, tmp, &ht->buckets[c], l) { in double_size()
108 &newBuckets[ht->hash(ht->cdata, it->key, newBucketBits)]; in double_size()
113 free(ht->buckets); in double_size()
115 ht->buckets = newBuckets; in double_size()
116 ht->bucketBits = newBucketBits; in double_size()
124 ht_add(HashTable ht, const void *key) in ht_add() argument
126 unsigned index = ht->hash(ht->cdata, key, ht->bucketBits); in ht_add()
127 struct xorg_list *bucket = &ht->buckets[index]; in ht_add()
132 elem->key = malloc(ht->keySize); in ht_add()
137 elem->data = calloc(1, ht->dataSize); in ht_add()
138 if (ht->dataSize && !elem->data) { in ht_add()
142 ++ht->elements; in ht_add()
144 memcpy(elem->key, key, ht->keySize); in ht_add()
146 if (ht->elements > 4 * (1 << ht->bucketBits) && in ht_add()
147 ht->bucketBits < MAXHASHSIZE) { in ht_add()
148 if (!double_size(ht)) { in ht_add()
149 --ht->elements; in ht_add()
157 return elem->data ? elem->data : ((char*) elem->key + ht->keySize); in ht_add()
170 ht_remove(HashTable ht, const void *key) in ht_remove() argument
172 unsigned index = ht->hash(ht->cdata, key, ht->bucketBits); in ht_remove()
173 struct xorg_list *bucket = &ht->buckets[index]; in ht_remove()
177 if (ht->compare(ht->cdata, key, it->key) == 0) { in ht_remove()
179 --ht->elements; in ht_remove()
189 ht_find(HashTable ht, const void *key) in ht_find() argument
191 unsigned index = ht->hash(ht->cdata, key, ht->bucketBits); in ht_find()
192 struct xorg_list *bucket = &ht->buckets[index]; in ht_find()
196 if (ht->compare(ht->cdata, key, it->key) == 0) { in ht_find()
197 return it->data ? it->data : ((char*) it->key + ht->keySize); in ht_find()
205 ht_dump_distribution(HashTable ht) in ht_dump_distribution() argument
208 int numBuckets = 1 << ht->bucketBits; in ht_dump_distribution()
213 xorg_list_for_each_entry(it, &ht->buckets[c], l) { in ht_dump_distribution()
275 ht_dump_contents(HashTable ht, in ht_dump_contents() argument
281 int numBuckets = 1 << ht->bucketBits; in ht_dump_contents()
287 xorg_list_for_each_entry(it, &ht->buckets[c], l) { in ht_dump_contents()