Lines Matching defs:ihp

94 	ipmi_hash_t *ihp;
96 if ((ihp = ipmi_zalloc(hp, sizeof (ipmi_hash_t))) == NULL)
99 ihp->ih_handle = hp;
100 ihp->ih_nbuckets = IPMI_HASHMINSIZE;
101 ihp->ih_linkoffs = linkoffs;
102 ihp->ih_convert = convert;
103 ihp->ih_compute = compute;
104 ihp->ih_compare = compare;
106 if ((ihp->ih_buckets = ipmi_zalloc(hp,
107 ihp->ih_nbuckets * sizeof (void *))) == NULL) {
108 ipmi_free(hp, ihp);
112 return (ihp);
116 ipmi_hash_destroy(ipmi_hash_t *ihp)
118 if (ihp != NULL) {
119 ipmi_free(ihp->ih_handle, ihp->ih_buckets);
120 ipmi_free(ihp->ih_handle, ihp);
164 ipmi_hash_compute(ipmi_hash_t *ihp, const void *elem)
166 return (ihp->ih_compute(ihp->ih_convert(elem)) % ihp->ih_nbuckets);
170 ipmi_hash_resize(ipmi_hash_t *ihp, ulong_t nsize)
172 size_t osize = ihp->ih_nbuckets;
173 ipmi_handle_t *hp = ihp->ih_handle;
192 ihp->ih_nbuckets = nsize;
195 while ((link = ihp->ih_buckets[idx]) != NULL) {
203 ihp->ih_buckets[idx] = link->ihl_next;
204 elem = (void *)((uintptr_t)link - ihp->ih_linkoffs);
205 nidx = ipmi_hash_compute(ihp, elem);
212 ipmi_free(hp, ihp->ih_buckets);
213 ihp->ih_buckets = nbuckets;
217 ipmi_hash_lookup(ipmi_hash_t *ihp, const void *search)
219 ulong_t idx = ihp->ih_compute(search) % ihp->ih_nbuckets;
222 for (hl = ihp->ih_buckets[idx]; hl != NULL; hl = hl->ihl_next) {
223 void *elem = (void *)((uintptr_t)hl - ihp->ih_linkoffs);
225 if (ihp->ih_compare(ihp->ih_convert(elem), search) == 0)
233 ipmi_hash_first(ipmi_hash_t *ihp)
235 void *link = ipmi_list_next(&(ihp)->ih_list);
240 return ((void *)((uintptr_t)link - ihp->ih_linkoffs));
244 ipmi_hash_next(ipmi_hash_t *ihp, void *elem)
246 void *link = ipmi_list_next((uintptr_t)elem + ihp->ih_linkoffs);
251 return ((void *)((uintptr_t)link - ihp->ih_linkoffs));
255 ipmi_hash_insert(ipmi_hash_t *ihp, void *elem)
257 ipmi_hash_link_t *link = (void *)((uintptr_t)elem + ihp->ih_linkoffs);
258 ulong_t idx = ipmi_hash_compute(ihp, elem);
260 assert(ipmi_hash_lookup(ihp, ihp->ih_convert(elem)) == NULL);
262 link->ihl_next = ihp->ih_buckets[idx];
263 ihp->ih_buckets[idx] = link;
265 ipmi_list_append(&ihp->ih_list, link);
267 if (++ihp->ih_nelements > ihp->ih_nbuckets / 2)
268 ipmi_hash_resize(ihp, ipmi_hash_double(ihp->ih_nbuckets));
272 ipmi_hash_remove(ipmi_hash_t *ihp, void *elem)
274 ulong_t idx = ipmi_hash_compute(ihp, elem);
275 ipmi_hash_link_t *link = (void *)((uintptr_t)elem + ihp->ih_linkoffs);
276 ipmi_hash_link_t **hlp = &ihp->ih_buckets[idx];
286 ipmi_list_delete(&ihp->ih_list, link);
288 assert(ihp->ih_nelements > 0);
290 if (--ihp->ih_nelements < ihp->ih_nbuckets / 4)
291 ipmi_hash_resize(ihp, ipmi_hash_half(ihp->ih_nbuckets));
295 ipmi_hash_count(ipmi_hash_t *ihp)
297 return (ihp->ih_nelements);