Lines Matching refs:ihp

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