Lines Matching refs:sp
39 dt_strtab_grow(dt_strtab_t *sp)
43 if ((ptr = malloc(sp->str_bufsz)) == NULL)
46 bufs = realloc(sp->str_bufs, (sp->str_nbufs + 1) * sizeof (char *));
53 sp->str_nbufs++;
54 sp->str_bufs = bufs;
55 sp->str_ptr = ptr;
56 sp->str_bufs[sp->str_nbufs - 1] = sp->str_ptr;
64 dt_strtab_t *sp = malloc(sizeof (dt_strtab_t));
69 if (sp == NULL)
72 bzero(sp, sizeof (dt_strtab_t));
73 sp->str_hash = malloc(nbuckets * sizeof (dt_strhash_t *));
75 if (sp->str_hash == NULL)
78 bzero(sp->str_hash, nbuckets * sizeof (dt_strhash_t *));
79 sp->str_hashsz = nbuckets;
80 sp->str_bufs = NULL;
81 sp->str_ptr = NULL;
82 sp->str_nbufs = 0;
83 sp->str_bufsz = bufsz;
84 sp->str_nstrs = 1;
85 sp->str_size = 1;
87 if (dt_strtab_grow(sp) == -1)
90 *sp->str_ptr++ = '\0';
91 return (sp);
94 dt_strtab_destroy(sp);
99 dt_strtab_destroy(dt_strtab_t *sp)
104 for (i = 0; i < sp->str_hashsz; i++) {
105 for (hp = sp->str_hash[i]; hp != NULL; hp = hq) {
111 for (i = 0; i < sp->str_nbufs; i++)
112 free(sp->str_bufs[i]);
114 if (sp->str_hash != NULL)
115 free(sp->str_hash);
116 if (sp->str_bufs != NULL)
117 free(sp->str_bufs);
119 free(sp);
145 dt_strtab_compare(dt_strtab_t *sp, dt_strhash_t *hp,
154 if (buf == sp->str_bufs[b] + sp->str_bufsz)
155 buf = sp->str_bufs[++b];
157 resid = sp->str_bufs[b] + sp->str_bufsz - buf;
172 dt_strtab_copyin(dt_strtab_t *sp, const char *str, size_t len)
174 char *old_p = sp->str_ptr;
175 ulong_t old_n = sp->str_nbufs;
177 ulong_t b = sp->str_nbufs - 1;
181 if (sp->str_ptr == sp->str_bufs[b] + sp->str_bufsz) {
182 if (dt_strtab_grow(sp) == -1)
187 resid = sp->str_bufs[b] + sp->str_bufsz - sp->str_ptr;
189 bcopy(str, sp->str_ptr, n);
191 sp->str_ptr += n;
199 while (sp->str_nbufs != old_n)
200 free(sp->str_bufs[--sp->str_nbufs]);
202 sp->str_ptr = old_p;
207 dt_strtab_index(dt_strtab_t *sp, const char *str)
216 h = dt_strtab_hash(str, &len) % sp->str_hashsz;
218 for (hp = sp->str_hash[h]; hp != NULL; hp = hp->str_next) {
219 if (dt_strtab_compare(sp, hp, str, len + 1) == 0)
227 dt_strtab_insert(dt_strtab_t *sp, const char *str)
234 if ((off = dt_strtab_index(sp, str)) != -1)
237 h = dt_strtab_hash(str, &len) % sp->str_hashsz;
246 hp->str_data = sp->str_ptr;
247 hp->str_buf = sp->str_nbufs - 1;
248 hp->str_off = sp->str_size;
250 hp->str_next = sp->str_hash[h];
256 if (dt_strtab_copyin(sp, str, len + 1) == -1)
259 sp->str_nstrs++;
260 sp->str_size += len + 1;
261 sp->str_hash[h] = hp;
267 dt_strtab_size(const dt_strtab_t *sp)
269 return (sp->str_size);
273 dt_strtab_write(const dt_strtab_t *sp, dt_strtab_write_f *func, void *private)
279 for (i = 0; i < sp->str_nbufs; i++, total += res) {
280 if (i == sp->str_nbufs - 1)
281 n = sp->str_ptr - sp->str_bufs[i];
283 n = sp->str_bufsz;
285 if ((res = func(sp->str_bufs[i], n, total, private)) <= 0)
289 if (total == 0 && sp->str_size != 0)