Lines Matching defs:shp

90 	shadow_hash_t *shp;
92 if ((shp = shadow_zalloc(sizeof (shadow_hash_t))) == NULL)
95 shp->sh_nbuckets = SHADOW_HASHMINSIZE;
96 shp->sh_linkoffs = linkoffs;
97 shp->sh_convert = convert;
98 shp->sh_compute = compute;
99 shp->sh_compare = compare;
101 if ((shp->sh_buckets = shadow_zalloc(
102 shp->sh_nbuckets * sizeof (void *))) == NULL) {
103 free(shp);
107 return (shp);
111 shadow_hash_destroy(shadow_hash_t *shp)
113 if (shp != NULL) {
114 free(shp->sh_buckets);
115 free(shp);
145 shadow_hash_compute(shadow_hash_t *shp, const void *elem)
147 return (shp->sh_compute(shp->sh_convert(elem)) % shp->sh_nbuckets);
151 shadow_hash_resize(shadow_hash_t *shp, ulong_t nsize)
153 size_t osize = shp->sh_nbuckets;
172 shp->sh_nbuckets = nsize;
175 while ((link = shp->sh_buckets[idx]) != NULL) {
183 shp->sh_buckets[idx] = link->shl_next;
184 elem = (void *)((uintptr_t)link - shp->sh_linkoffs);
185 nidx = shadow_hash_compute(shp, elem);
192 free(shp->sh_buckets);
193 shp->sh_buckets = nbuckets;
197 shadow_hash_lookup(shadow_hash_t *shp, const void *search)
199 ulong_t idx = shp->sh_compute(search) % shp->sh_nbuckets;
202 for (hl = shp->sh_buckets[idx]; hl != NULL; hl = hl->shl_next) {
203 void *elem = (void *)((uintptr_t)hl - shp->sh_linkoffs);
205 if (shp->sh_compare(shp->sh_convert(elem), search) == 0)
213 shadow_hash_first(shadow_hash_t *shp)
215 void *link = shadow_list_next(&(shp)->sh_list);
220 return ((void *)((uintptr_t)link - shp->sh_linkoffs));
224 shadow_hash_next(shadow_hash_t *shp, void *elem)
226 void *link = shadow_list_next((uintptr_t)elem + shp->sh_linkoffs);
231 return ((void *)((uintptr_t)link - shp->sh_linkoffs));
235 shadow_hash_insert(shadow_hash_t *shp, void *elem)
237 shadow_hash_link_t *link = (void *)((uintptr_t)elem + shp->sh_linkoffs);
238 ulong_t idx = shadow_hash_compute(shp, elem);
240 assert(shadow_hash_lookup(shp, shp->sh_convert(elem)) == NULL);
242 link->shl_next = shp->sh_buckets[idx];
243 shp->sh_buckets[idx] = link;
245 shadow_list_append(&shp->sh_list, link);
247 if (++shp->sh_nelements > shp->sh_nbuckets / 2)
248 shadow_hash_resize(shp, shadow_hash_double(shp->sh_nbuckets));
252 shadow_hash_remove(shadow_hash_t *shp, void *elem)
254 ulong_t idx = shadow_hash_compute(shp, elem);
255 shadow_hash_link_t *link = (void *)((uintptr_t)elem + shp->sh_linkoffs);
256 shadow_hash_link_t **hlp = &shp->sh_buckets[idx];
266 shadow_list_delete(&shp->sh_list, link);
268 assert(shp->sh_nelements > 0);
270 if (--shp->sh_nelements < shp->sh_nbuckets / 4)
271 shadow_hash_resize(shp, shadow_hash_half(shp->sh_nbuckets));
275 shadow_hash_count(shadow_hash_t *shp)
277 return (shp->sh_nelements);