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