Lines Matching defs:hp
34 ctf_hash_create(ctf_hash_t *hp, ulong_t nelems)
44 bzero(hp, sizeof (ctf_hash_t));
45 hp->h_buckets = (ushort_t *)_CTF_EMPTY;
46 hp->h_nbuckets = 1;
50 hp->h_nbuckets = 211; /* use a prime number of hash buckets */
51 hp->h_nelems = nelems + 1; /* we use index zero as a sentinel */
52 hp->h_free = 1; /* first free element is index 1 */
54 hp->h_buckets = ctf_alloc(sizeof (ushort_t) * hp->h_nbuckets);
55 hp->h_chains = ctf_alloc(sizeof (ctf_helem_t) * hp->h_nelems);
57 if (hp->h_buckets == NULL || hp->h_chains == NULL) {
58 ctf_hash_destroy(hp);
62 bzero(hp->h_buckets, sizeof (ushort_t) * hp->h_nbuckets);
63 bzero(hp->h_chains, sizeof (ctf_helem_t) * hp->h_nelems);
69 ctf_hash_size(const ctf_hash_t *hp)
71 return (hp->h_nelems ? hp->h_nelems - 1 : 0);
94 ctf_hash_insert(ctf_hash_t *hp, ctf_file_t *fp, ushort_t type, uint_t name)
98 ctf_helem_t *hep = &hp->h_chains[hp->h_free];
104 if (hp->h_free >= hp->h_nelems)
118 h = ctf_hash_compute(str, strlen(str)) % hp->h_nbuckets;
119 hep->h_next = hp->h_buckets[h];
120 hp->h_buckets[h] = hp->h_free++;
131 ctf_hash_define(ctf_hash_t *hp, ctf_file_t *fp, ushort_t type, uint_t name)
134 ctf_helem_t *hep = ctf_hash_lookup(hp, fp, str, strlen(str));
137 return (ctf_hash_insert(hp, fp, type, name));
144 ctf_hash_lookup(ctf_hash_t *hp, ctf_file_t *fp, const char *key, size_t len)
151 ulong_t h = ctf_hash_compute(key, len) % hp->h_nbuckets;
153 for (i = hp->h_buckets[h]; i != 0; i = hep->h_next) {
154 hep = &hp->h_chains[i];
166 ctf_hash_destroy(ctf_hash_t *hp)
168 if (hp->h_buckets != NULL && hp->h_nbuckets != 1) {
169 ctf_free(hp->h_buckets, sizeof (ushort_t) * hp->h_nbuckets);
170 hp->h_buckets = NULL;
173 if (hp->h_chains != NULL) {
174 ctf_free(hp->h_chains, sizeof (ctf_helem_t) * hp->h_nelems);
175 hp->h_chains = NULL;