Lines Matching refs:htab
65 static void _hdelete(const char *key, struct hsearch_data *htab, ENTRY *ep,
99 int hcreate_r(size_t nel, struct hsearch_data *htab) in hcreate_r() argument
102 if (htab == NULL) { in hcreate_r()
108 if (htab->table != NULL) in hcreate_r()
116 htab->size = nel; in hcreate_r()
117 htab->filled = 0; in hcreate_r()
120 htab->table = (_ENTRY *) calloc(htab->size + 1, sizeof(_ENTRY)); in hcreate_r()
121 if (htab->table == NULL) in hcreate_r()
138 void hdestroy_r(struct hsearch_data *htab) in hdestroy_r() argument
143 if (htab == NULL) { in hdestroy_r()
149 for (i = 1; i <= htab->size; ++i) { in hdestroy_r()
150 if (htab->table[i].used > 0) { in hdestroy_r()
151 ENTRY *ep = &htab->table[i].entry; in hdestroy_r()
157 free(htab->table); in hdestroy_r()
160 htab->table = NULL; in hdestroy_r()
201 struct hsearch_data *htab) in hmatch_r() argument
206 for (idx = last_idx + 1; idx < htab->size; ++idx) { in hmatch_r()
207 if (htab->table[idx].used <= 0) in hmatch_r()
209 if (!strncmp(match, htab->table[idx].entry.key, key_len)) { in hmatch_r()
210 *retval = &htab->table[idx].entry; in hmatch_r()
225 ENTRY **retval, struct hsearch_data *htab, int flag, in _compare_and_overwrite_entry() argument
228 if (htab->table[idx].used == hval in _compare_and_overwrite_entry()
229 && strcmp(item.key, htab->table[idx].entry.key) == 0) { in _compare_and_overwrite_entry()
233 if (htab->change_ok != NULL && htab->change_ok( in _compare_and_overwrite_entry()
234 &htab->table[idx].entry, item.data, in _compare_and_overwrite_entry()
244 if (htab->table[idx].entry.callback && in _compare_and_overwrite_entry()
245 htab->table[idx].entry.callback(item.key, in _compare_and_overwrite_entry()
254 free(htab->table[idx].entry.data); in _compare_and_overwrite_entry()
255 htab->table[idx].entry.data = strdup(item.data); in _compare_and_overwrite_entry()
256 if (!htab->table[idx].entry.data) { in _compare_and_overwrite_entry()
263 *retval = &htab->table[idx].entry; in _compare_and_overwrite_entry()
271 struct hsearch_data *htab, int flag) in hsearch_r() argument
292 hval %= htab->size; in hsearch_r()
299 if (htab->table[idx].used) { in hsearch_r()
306 if (htab->table[idx].used == -1 in hsearch_r()
310 ret = _compare_and_overwrite_entry(item, action, retval, htab, in hsearch_r()
319 hval2 = 1 + hval % (htab->size - 2); in hsearch_r()
327 idx = htab->size + idx - hval2; in hsearch_r()
340 htab, flag, hval, idx); in hsearch_r()
344 while (htab->table[idx].used); in hsearch_r()
353 if (htab->filled == htab->size) { in hsearch_r()
366 htab->table[idx].used = hval; in hsearch_r()
367 htab->table[idx].entry.key = strdup(item.key); in hsearch_r()
368 htab->table[idx].entry.data = strdup(item.data); in hsearch_r()
369 if (!htab->table[idx].entry.key || in hsearch_r()
370 !htab->table[idx].entry.data) { in hsearch_r()
376 ++htab->filled; in hsearch_r()
379 env_callback_init(&htab->table[idx].entry); in hsearch_r()
381 env_flags_init(&htab->table[idx].entry); in hsearch_r()
384 if (htab->change_ok != NULL && htab->change_ok( in hsearch_r()
385 &htab->table[idx].entry, item.data, env_op_create, flag)) { in hsearch_r()
388 _hdelete(item.key, htab, &htab->table[idx].entry, idx); in hsearch_r()
395 if (htab->table[idx].entry.callback && in hsearch_r()
396 htab->table[idx].entry.callback(item.key, item.data, in hsearch_r()
400 _hdelete(item.key, htab, &htab->table[idx].entry, idx); in hsearch_r()
407 *retval = &htab->table[idx].entry; in hsearch_r()
427 static void _hdelete(const char *key, struct hsearch_data *htab, ENTRY *ep, in _hdelete() argument
436 htab->table[idx].used = -1; in _hdelete()
438 --htab->filled; in _hdelete()
441 int hdelete_r(const char *key, struct hsearch_data *htab, int flag) in hdelete_r() argument
450 idx = hsearch_r(e, FIND, &ep, htab, 0); in hdelete_r()
457 if (htab->change_ok != NULL && in hdelete_r()
458 htab->change_ok(ep, NULL, env_op_delete, flag)) { in hdelete_r()
466 if (htab->table[idx].entry.callback && in hdelete_r()
467 htab->table[idx].entry.callback(key, NULL, env_op_delete, flag)) { in hdelete_r()
474 _hdelete(key, htab, ep, idx); in hdelete_r()
589 ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag, in hexport_r() argument
593 ENTRY *list[htab->size]; in hexport_r()
599 if ((resp == NULL) || (htab == NULL)) { in hexport_r()
605 htab, htab->size, htab->filled, (ulong)size); in hexport_r()
611 for (i = 1, n = 0, totlen = 0; i <= htab->size; ++i) { in hexport_r()
613 if (htab->table[i].used > 0) { in hexport_r()
614 ENTRY *ep = &htab->table[i].entry; in hexport_r()
776 int himport_r(struct hsearch_data *htab, in himport_r() argument
785 if (htab == NULL) { in himport_r()
806 debug("Destroy Hash Table: %p table = %p\n", htab, in himport_r()
807 htab->table); in himport_r()
808 if (htab->table) in himport_r()
809 hdestroy_r(htab); in himport_r()
830 if (!htab->table) { in himport_r()
838 if (hcreate_r(nent, htab) == 0) { in himport_r()
892 if (hdelete_r(name, htab, flag) == 0) in himport_r()
923 hsearch_r(e, ENTER, &rv, htab, flag); in himport_r()
929 htab, htab->filled, htab->size, in himport_r()
948 if (hdelete_r(localvars[i], htab, flag) == 0) in himport_r()
966 int hwalk_r(struct hsearch_data *htab, int (*callback)(ENTRY *)) in hwalk_r() argument
971 for (i = 1; i <= htab->size; ++i) { in hwalk_r()
972 if (htab->table[i].used > 0) { in hwalk_r()
973 retval = callback(&htab->table[i].entry); in hwalk_r()