Lines Matching defs:handle

28  * table entries. A handle is associated with each table, which is used
32 * |handle|---> |index 0|--->|item|--->|item|--->
51 static size_t ht_default_hash(HT_HANDLE *handle, const char *key);
77 * The handle and the table are are malloc'd using a single call, to
79 * handle.
81 * On success a pointer to an opaque handle is returned. Otherwise a
129 ht_destroy_table(HT_HANDLE *handle)
134 if (handle == 0)
138 (void) ht_clean_table(handle);
139 while ((item = ht_findfirst(handle, &iterator)) != 0)
140 (void) ht_remove_item(handle, item->hi_key);
142 free(handle);
150 * handle is invalid.
153 ht_get_total_items(HT_HANDLE *handle)
155 if (handle == 0)
158 return (handle->ht_total_items);
167 * corresponding item in the hash table. The handle and key pointers
173 ht_default_hash(HT_HANDLE *handle, const char *key)
178 if ((handle->ht_flags & HTHF_FIXED_KEY) == 0) {
184 int key_len = handle->ht_key_size;
192 rval = (hash_ndx * HASH_MESH_VALUE) & handle->ht_table_mask;
205 ht_set_cmpfn(HT_HANDLE *handle, HT_CMP cmpfn)
207 if (handle)
208 handle->ht_cmp = cmpfn;
215 * handle and the key is used to generate a hashed index. The data
226 ht_add_item(HT_HANDLE *handle, const char *key, const void *data)
232 if (handle == 0 || key == 0)
235 if (handle->ht_flags & HTHF_FIXED_KEY) {
236 key_len = handle->ht_key_size;
240 if (key_len > handle->ht_key_size)
257 h_index = handle->ht_hash(handle, key);
262 item->hi_next = handle->ht_table[h_index].he_head;
263 handle->ht_table[h_index].he_head = item;
265 handle->ht_table[h_index].he_count++;
266 handle->ht_total_items++;
267 handle->ht_sequence++;
283 ht_replace_item(HT_HANDLE *handle, const char *key, const void *data)
285 (void) ht_remove_item(handle, key);
287 return (ht_add_item(handle, key, data));
304 ht_remove_item(HT_HANDLE *handle, const char *key)
311 if (handle == 0 || key == 0)
314 if ((handle->ht_flags & HTHF_FIXED_KEY) == 0)
317 key_len = handle->ht_key_size;
319 h_index = handle->ht_hash(handle, key);
321 cur = handle->ht_table[h_index].he_head;
326 (handle->ht_cmp(cur->hi_key, key, key_len) == 0)) {
329 handle->ht_table[h_index].he_head =
334 if (handle->ht_callback)
335 handle->ht_callback(cur);
345 handle->ht_table[h_index].he_count--;
346 handle->ht_total_items--;
347 handle->ht_sequence++;
368 ht_find_item(HT_HANDLE *handle, const char *key)
374 if (handle == 0 || key == 0)
377 if ((handle->ht_flags & HTHF_FIXED_KEY) == 0)
380 key_len = handle->ht_key_size;
382 h_index = handle->ht_hash(handle, key);
383 cur = handle->ht_table[h_index].he_head;
387 (handle->ht_cmp(cur->hi_key, key, key_len) == 0))
409 ht_register_callback(HT_HANDLE *handle, HT_CALLBACK callback)
413 if (handle == 0)
416 old_callback = handle->ht_callback;
417 handle->ht_callback = callback;
433 * Returns 0 if the handle is valid; otherwise returns -1.
436 ht_clean_table(HT_HANDLE *handle)
441 if (handle == 0)
444 for (i = 0; i < handle->ht_table_size; i++) {
445 cur = handle->ht_table[i].he_head;
454 handle->ht_table[i].he_head =
459 if (handle->ht_callback)
460 handle->ht_callback(cur);
468 handle->ht_table[i].he_count--;
469 handle->ht_sequence++;
472 cur = handle->ht_table[i].he_head;
495 ht_mark_delete(HT_HANDLE *handle, HT_ITEM *item)
497 if (handle && item) {
499 handle->ht_total_items--;
509 ht_clear_delete(HT_HANDLE *handle, HT_ITEM *item)
511 if (handle && item) {
513 handle->ht_total_items++;
544 ht_findfirst(HT_HANDLE *handle, HT_ITERATOR *iterator)
549 if (handle == 0 || iterator == 0 || handle->ht_total_items == 0)
553 iterator->hti_handle = handle;
554 iterator->hti_sequence = handle->ht_sequence;
556 for (h_index = 0; h_index < handle->ht_table_size; ++h_index) {
557 item = ht_bucket_search(handle->ht_table[h_index].he_head);
586 HT_HANDLE *handle;
597 handle = iterator->hti_handle;
600 iterator->hti_sequence != handle->ht_sequence) {
621 total = handle->ht_table_size;
623 item = ht_bucket_search(handle->ht_table[index].he_head);