Lines Matching refs:hp
38 ctf_hash_create(ctf_hash_t *hp, ulong_t nelems)
48 memset(hp, 0, sizeof (ctf_hash_t));
49 hp->h_buckets = __UNCONST(_CTF_EMPTY);
50 hp->h_nbuckets = 1;
54 hp->h_nbuckets = 211; /* use a prime number of hash buckets */
55 hp->h_nelems = nelems + 1; /* we use index zero as a sentinel */
56 hp->h_free = 1; /* first free element is index 1 */
58 hp->h_buckets = ctf_alloc(sizeof (*hp->h_buckets) * hp->h_nbuckets);
59 hp->h_chains = ctf_alloc(sizeof (ctf_helem_t) * hp->h_nelems);
61 if (hp->h_buckets == NULL || hp->h_chains == NULL) {
62 ctf_hash_destroy(hp);
66 memset(hp->h_buckets, 0, sizeof (*hp->h_buckets) * hp->h_nbuckets);
67 memset(hp->h_chains, 0, sizeof (*hp->h_chains) * hp->h_nelems);
73 ctf_hash_size(const ctf_hash_t *hp)
75 return (hp->h_nelems ? hp->h_nelems - 1 : 0);
98 ctf_hash_insert(ctf_hash_t *hp, ctf_file_t *fp, uint_t type, uint_t name)
102 ctf_helem_t *hep = &hp->h_chains[hp->h_free];
108 if (hp->h_free >= hp->h_nelems)
122 h = ctf_hash_compute(str, strlen(str)) % hp->h_nbuckets;
123 hep->h_next = hp->h_buckets[h];
124 hp->h_buckets[h] = hp->h_free++;
135 ctf_hash_define(ctf_hash_t *hp, ctf_file_t *fp, uint_t type, uint_t name)
138 ctf_helem_t *hep = ctf_hash_lookup(hp, fp, str, strlen(str));
141 return (ctf_hash_insert(hp, fp, type, name));
148 ctf_hash_lookup(ctf_hash_t *hp, ctf_file_t *fp, const char *key, size_t len)
155 ulong_t h = ctf_hash_compute(key, len) % hp->h_nbuckets;
157 for (i = hp->h_buckets[h]; i != 0; i = hep->h_next) {
158 hep = &hp->h_chains[i];
170 ctf_hash_destroy(ctf_hash_t *hp)
172 if (hp->h_buckets != NULL && hp->h_nbuckets != 1) {
173 ctf_free(hp->h_buckets, sizeof (*hp->h_buckets) * hp->h_nbuckets);
174 hp->h_buckets = NULL;
177 if (hp->h_chains != NULL) {
178 ctf_free(hp->h_chains, sizeof (ctf_helem_t) * hp->h_nelems);
179 hp->h_chains = NULL;