Lines Matching refs:ht

327         void **ht;              /* bucket heads */
336 dn_ht_init(struct dn_ht *ht, int buckets, int ofs,
357 * The ht->buckets variable store the bucket size - 1 to simply
358 * do an AND between the index returned by hash function and ht->bucket
389 if (ht) { /* see if we can reuse */
390 if (buckets <= ht->buckets) {
391 ht->buckets = buckets;
394 if (ht->ht != (void *)(ht + 1))
395 free(ht->ht, M_DN_HEAP);
396 free(ht, M_DN_HEAP);
397 ht = NULL;
400 if (ht == NULL) {
404 l = sizeof(*ht) + (buckets + 1) * sizeof(void **);
405 ht = malloc(l, M_DN_HEAP, M_NOWAIT | M_ZERO);
407 if (ht) {
408 ht->ht = (void **)(ht + 1);
409 ht->buckets = buckets;
410 ht->ofs = ofs;
411 ht->hash = h;
412 ht->match = match;
413 ht->newh = newh;
415 return ht;
428 dn_ht_free(struct dn_ht *ht, int flags)
430 if (ht == NULL)
433 (void)dn_ht_scan(ht, do_del, NULL);
435 if (ht->ht && ht->ht != (void *)(ht + 1))
436 free(ht->ht, M_DN_HEAP);
437 free(ht, M_DN_HEAP);
442 dn_ht_entries(struct dn_ht *ht)
444 return ht ? ht->entries : 0;
449 dn_ht_find(struct dn_ht *ht, uintptr_t key, int flags, void *arg)
454 if (ht == NULL) /* easy on an empty hash */
456 i = (ht->buckets == 1) ? 0 :
457 (ht->hash(key, flags, arg) & ht->buckets);
459 for (pp = &ht->ht[i]; (p = *pp); pp = (void **)((char *)p + ht->ofs)) {
463 } else if (ht->match(p, key, flags, arg)) /* found match */
469 *pp = *(void **)((char *)p + ht->ofs);
470 *(void **)((char *)p + ht->ofs) = NULL;
471 ht->entries--;
475 // __FUNCTION__, i, ht->ofs);
476 p = ht->newh ? ht->newh(key, flags, arg) : (void *)key;
479 ht->entries++;
480 *(void **)((char *)p + ht->ofs) = ht->ht[i];
481 ht->ht[i] = p;
492 dn_ht_scan(struct dn_ht *ht, int (*fn)(void *, void *), void *arg)
497 if (ht == NULL || fn == NULL)
499 for (i = 0; i <= ht->buckets; i++) {
500 curp = &ht->ht[i];
502 next = *(void **)((char *)cur + ht->ofs);
506 ht->entries--;
509 curp = (void **)((char *)cur + ht->ofs);
522 * If the callback returns DNHT_SCAN_END, the function move the ht->ht[i]
527 dn_ht_scan_bucket(struct dn_ht *ht, int *bucket, int (*fn)(void *, void *),
533 if (ht == NULL || fn == NULL)
535 if (*bucket > ht->buckets)
539 curp = &ht->ht[i];
541 next = *(void **)((char *)cur + ht->ofs);
545 ht->entries--;
548 curp = (void **)((char *)cur + ht->ofs);