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;
426 dn_ht_free(struct dn_ht *ht, int flags)
428 if (ht == NULL)
431 (void)dn_ht_scan(ht, do_del, NULL);
433 if (ht->ht && ht->ht != (void *)(ht + 1))
434 free(ht->ht, M_DN_HEAP);
435 free(ht, M_DN_HEAP);
440 dn_ht_entries(struct dn_ht *ht)
442 return ht ? ht->entries : 0;
447 dn_ht_find(struct dn_ht *ht, uintptr_t key, int flags, void *arg)
452 if (ht == NULL) /* easy on an empty hash */
454 i = (ht->buckets == 1) ? 0 :
455 (ht->hash(key, flags, arg) & ht->buckets);
457 for (pp = &ht->ht[i]; (p = *pp); pp = (void **)((char *)p + ht->ofs)) {
461 } else if (ht->match(p, key, flags, arg)) /* found match */
467 *pp = *(void **)((char *)p + ht->ofs);
468 *(void **)((char *)p + ht->ofs) = NULL;
469 ht->entries--;
473 // __FUNCTION__, i, ht->ofs);
474 p = ht->newh ? ht->newh(key, flags, arg) : (void *)key;
477 ht->entries++;
478 *(void **)((char *)p + ht->ofs) = ht->ht[i];
479 ht->ht[i] = p;
490 dn_ht_scan(struct dn_ht *ht, int (*fn)(void *, void *), void *arg)
495 if (ht == NULL || fn == NULL)
497 for (i = 0; i <= ht->buckets; i++) {
498 curp = &ht->ht[i];
500 next = *(void **)((char *)cur + ht->ofs);
504 ht->entries--;
507 curp = (void **)((char *)cur + ht->ofs);
520 * If the callback returns DNHT_SCAN_END, the function move the ht->ht[i]
525 dn_ht_scan_bucket(struct dn_ht *ht, int *bucket, int (*fn)(void *, void *),
531 if (ht == NULL || fn == NULL)
533 if (*bucket > ht->buckets)
537 curp = &ht->ht[i];
539 next = *(void **)((char *)cur + ht->ofs);
543 ht->entries--;
546 curp = (void **)((char *)cur + ht->ofs);