Lines Matching refs:h

39     struct hashtable *h;  in create_hashtable()  local
50 h = (struct hashtable *)calloc(1, sizeof(struct hashtable)); in create_hashtable()
51 if (NULL == h) in create_hashtable()
53 h->table = (struct entry **)calloc(size, sizeof(struct entry *)); in create_hashtable()
54 if (NULL == h->table) in create_hashtable()
57 h->tablelength = size; in create_hashtable()
58 h->primeindex = pindex; in create_hashtable()
59 h->entrycount = 0; in create_hashtable()
60 h->hashfn = hashf; in create_hashtable()
61 h->eqfn = eqf; in create_hashtable()
62 h->loadlimit = (unsigned int)(((uint64_t)size * max_load_factor) / 100); in create_hashtable()
63 return h; in create_hashtable()
66 free(h); in create_hashtable()
73 hash(struct hashtable *h, void *k) in hash() argument
77 unsigned int i = h->hashfn(k); in hash()
87 hashtable_expand(struct hashtable *h) in hashtable_expand() argument
95 if (h->primeindex == (prime_table_length - 1)) return 0; in hashtable_expand()
96 newsize = primes[++(h->primeindex)]; in hashtable_expand()
103 for (i = 0; i < h->tablelength; i++) { in hashtable_expand()
104 while (NULL != (e = h->table[i])) { in hashtable_expand()
105 h->table[i] = e->next; in hashtable_expand()
106 index = indexFor(newsize,e->h); in hashtable_expand()
111 free(h->table); in hashtable_expand()
112 h->table = newtable; in hashtable_expand()
118 realloc(h->table, newsize * sizeof(struct entry *)); in hashtable_expand()
119 if (NULL == newtable) { (h->primeindex)--; return 0; } in hashtable_expand()
120 h->table = newtable; in hashtable_expand()
121 memset(newtable[h->tablelength], 0, newsize - h->tablelength); in hashtable_expand()
122 for (i = 0; i < h->tablelength; i++) { in hashtable_expand()
124 index = indexFor(newsize,e->h); in hashtable_expand()
138 h->tablelength = newsize; in hashtable_expand()
139 h->loadlimit = (unsigned int) in hashtable_expand()
146 hashtable_count(struct hashtable *h) in hashtable_count() argument
148 return h->entrycount; in hashtable_count()
153 hashtable_insert(struct hashtable *h, void *k, void *v) in hashtable_insert() argument
158 if (++(h->entrycount) > h->loadlimit) in hashtable_insert()
164 hashtable_expand(h); in hashtable_insert()
167 if (NULL == e) { --(h->entrycount); return 0; } /*oom*/ in hashtable_insert()
168 e->h = hash(h,k); in hashtable_insert()
169 index = indexFor(h->tablelength,e->h); in hashtable_insert()
172 e->next = h->table[index]; in hashtable_insert()
173 h->table[index] = e; in hashtable_insert()
179 hashtable_search(struct hashtable *h, void *k) in hashtable_search() argument
183 hashvalue = hash(h,k); in hashtable_search()
184 index = indexFor(h->tablelength,hashvalue); in hashtable_search()
185 e = h->table[index]; in hashtable_search()
189 if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v; in hashtable_search()
197 hashtable_remove(struct hashtable *h, void *k) in hashtable_remove() argument
207 hashvalue = hash(h,k); in hashtable_remove()
208 index = indexFor(h->tablelength,hash(h,k)); in hashtable_remove()
209 pE = &(h->table[index]); in hashtable_remove()
214 if ((hashvalue == e->h) && (h->eqfn(k, e->k))) in hashtable_remove()
217 h->entrycount--; in hashtable_remove()
232 hashtable_destroy(struct hashtable *h, int free_values) in hashtable_destroy() argument
236 struct entry **table = h->table; in hashtable_destroy()
239 for (i = 0; i < h->tablelength; i++) in hashtable_destroy()
248 for (i = 0; i < h->tablelength; i++) in hashtable_destroy()
255 free(h->table); in hashtable_destroy()
256 free(h); in hashtable_destroy()