Lines Matching refs:hash

43 struct hash {  struct
94 hash_t *hash; in hash_new() local
96 hash = xmalloc(sizeof (hash_t)); in hash_new()
97 hash->h_buckets = xcalloc(sizeof (list_t *) * nbuckets); in hash_new()
98 hash->h_nbuckets = nbuckets; in hash_new()
99 hash->h_hashfn = hashfn ? hashfn : (int (*)())hash_def_hash; in hash_new()
100 hash->h_cmp = cmp ? cmp : (int (*)())hash_def_cmp; in hash_new()
102 return (hash); in hash_new()
106 hash_add(hash_t *hash, void *key) in hash_add() argument
108 int bucket = hash->h_hashfn(hash->h_nbuckets, key); in hash_add()
110 list_add(&hash->h_buckets[bucket], key); in hash_add()
127 hash_remove_cb(void *key1, void *key2, hash_t *hash) in hash_remove_cb() argument
129 return (hash->h_cmp(key1, key2)); in hash_remove_cb()
133 hash_remove(hash_t *hash, void *key) in hash_remove() argument
135 int bucket = hash->h_hashfn(hash->h_nbuckets, key); in hash_remove()
137 (void) list_remove(&hash->h_buckets[bucket], key, in hash_remove()
138 (int (*)())hash_remove_cb, hash); in hash_remove()
142 hash_match(hash_t *hash, void *key, int (*fun)(void *, void *), in hash_match() argument
145 int bucket = hash->h_hashfn(hash->h_nbuckets, key); in hash_match()
147 return (list_iter(hash->h_buckets[bucket], fun, private) < 0); in hash_match()
166 hash_find_iter(hash_t *hash, void *key, int (*fun)(void *, void *), in hash_find_iter() argument
169 int bucket = hash->h_hashfn(hash->h_nbuckets, key); in hash_find_iter()
172 hd.hd_hash = hash; in hash_find_iter()
177 return (list_iter(hash->h_buckets[bucket], (int (*)())hash_find_list_cb, in hash_find_iter()
194 hash_find(hash_t *hash, void *key, void **value) in hash_find() argument
199 hd.hd_hash = hash; in hash_find()
203 ret = hash_match(hash, key, (int (*)())hash_find_first_cb, &hd); in hash_find()
211 hash_iter(hash_t *hash, int (*fun)(void *, void *), void *private) in hash_iter() argument
217 for (i = 0; i < hash->h_nbuckets; i++) { in hash_iter()
218 if (hash->h_buckets[i] != NULL) { in hash_iter()
219 if ((cbrc = list_iter(hash->h_buckets[i], fun, in hash_iter()
230 hash_count(hash_t *hash) in hash_count() argument
234 for (num = 0, i = 0; i < hash->h_nbuckets; i++) in hash_count()
235 num += list_count(hash->h_buckets[i]); in hash_count()
241 hash_free(hash_t *hash, void (*datafree)(void *, void *), void *private) in hash_free() argument
245 if (hash == NULL) in hash_free()
248 for (i = 0; i < hash->h_nbuckets; i++) in hash_free()
249 list_free(hash->h_buckets[i], datafree, private); in hash_free()
250 free(hash->h_buckets); in hash_free()
251 free(hash); in hash_free()
255 hash_stats(hash_t *hash, int verbose) in hash_stats() argument
257 int min = list_count(hash->h_buckets[0]); in hash_stats()
267 for (i = 1; i < hash->h_nbuckets; i++) { in hash_stats()
268 count = list_count(hash->h_buckets[i]); in hash_stats()
283 printf(" Buckets: %d\n", hash->h_nbuckets); in hash_stats()
286 printf(" Average: %5.2f\n", (float)tot / (float)hash->h_nbuckets); in hash_stats()