Lines Matching refs:ht
329 void **ht; /* bucket heads */ member
338 dn_ht_init(struct dn_ht *ht, int buckets, int ofs, in dn_ht_init() argument
391 if (ht) { /* see if we can reuse */ in dn_ht_init()
392 if (buckets <= ht->buckets) { in dn_ht_init()
393 ht->buckets = buckets; in dn_ht_init()
396 if (ht->ht != (void *)(ht + 1)) in dn_ht_init()
397 free(ht->ht, M_DN_HEAP); in dn_ht_init()
398 free(ht, M_DN_HEAP); in dn_ht_init()
399 ht = NULL; in dn_ht_init()
402 if (ht == NULL) { in dn_ht_init()
406 l = sizeof(*ht) + (buckets + 1) * sizeof(void **); in dn_ht_init()
407 ht = malloc(l, M_DN_HEAP, M_NOWAIT | M_ZERO); in dn_ht_init()
409 if (ht) { in dn_ht_init()
410 ht->ht = (void **)(ht + 1); in dn_ht_init()
411 ht->buckets = buckets; in dn_ht_init()
412 ht->ofs = ofs; in dn_ht_init()
413 ht->hash = h; in dn_ht_init()
414 ht->match = match; in dn_ht_init()
415 ht->newh = newh; in dn_ht_init()
417 return ht; in dn_ht_init()
430 dn_ht_free(struct dn_ht *ht, int flags) in dn_ht_free() argument
432 if (ht == NULL) in dn_ht_free()
435 (void)dn_ht_scan(ht, do_del, NULL); in dn_ht_free()
437 if (ht->ht && ht->ht != (void *)(ht + 1)) in dn_ht_free()
438 free(ht->ht, M_DN_HEAP); in dn_ht_free()
439 free(ht, M_DN_HEAP); in dn_ht_free()
444 dn_ht_entries(struct dn_ht *ht) in dn_ht_entries() argument
446 return ht ? ht->entries : 0; in dn_ht_entries()
451 dn_ht_find(struct dn_ht *ht, uintptr_t key, int flags, void *arg) in dn_ht_find() argument
456 if (ht == NULL) /* easy on an empty hash */ in dn_ht_find()
458 i = (ht->buckets == 1) ? 0 : in dn_ht_find()
459 (ht->hash(key, flags, arg) & ht->buckets); in dn_ht_find()
461 for (pp = &ht->ht[i]; (p = *pp); pp = (void **)((char *)p + ht->ofs)) { in dn_ht_find()
465 } else if (ht->match(p, key, flags, arg)) /* found match */ in dn_ht_find()
471 *pp = *(void **)((char *)p + ht->ofs); in dn_ht_find()
472 *(void **)((char *)p + ht->ofs) = NULL; in dn_ht_find()
473 ht->entries--; in dn_ht_find()
478 p = ht->newh ? ht->newh(key, flags, arg) : (void *)key; in dn_ht_find()
481 ht->entries++; in dn_ht_find()
482 *(void **)((char *)p + ht->ofs) = ht->ht[i]; in dn_ht_find()
483 ht->ht[i] = p; in dn_ht_find()
494 dn_ht_scan(struct dn_ht *ht, int (*fn)(void *, void *), void *arg) in dn_ht_scan() argument
499 if (ht == NULL || fn == NULL) in dn_ht_scan()
501 for (i = 0; i <= ht->buckets; i++) { in dn_ht_scan()
502 curp = &ht->ht[i]; in dn_ht_scan()
504 next = *(void **)((char *)cur + ht->ofs); in dn_ht_scan()
508 ht->entries--; in dn_ht_scan()
511 curp = (void **)((char *)cur + ht->ofs); in dn_ht_scan()
529 dn_ht_scan_bucket(struct dn_ht *ht, int *bucket, int (*fn)(void *, void *), in dn_ht_scan_bucket() argument
535 if (ht == NULL || fn == NULL) in dn_ht_scan_bucket()
537 if (*bucket > ht->buckets) in dn_ht_scan_bucket()
541 curp = &ht->ht[i]; in dn_ht_scan_bucket()
543 next = *(void **)((char *)cur + ht->ofs); in dn_ht_scan_bucket()
547 ht->entries--; in dn_ht_scan_bucket()
550 curp = (void **)((char *)cur + ht->ofs); in dn_ht_scan_bucket()