37 #include <sys/cdefs.h>
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/malloc.h>
55 KASSERT(elements > 0, (
"%s: bad elements", __func__));
57 KASSERT((flags & HASH_WAITOK) ^ (flags & HASH_NOWAIT),
58 (
"Bad flags (0x%x) passed to hashinit_flags", flags));
60 for (hashsize = 1; hashsize <= elements; hashsize <<= 1)
64 if (flags & HASH_NOWAIT)
65 hashtbl =
malloc((u_long)hashsize *
sizeof(*hashtbl),
68 hashtbl =
malloc((u_long)hashsize *
sizeof(*hashtbl),
71 if (hashtbl != NULL) {
72 for (i = 0; i < hashsize; i++)
73 LIST_INIT(&hashtbl[i]);
74 *hashmask = hashsize - 1;
92 LIST_HEAD(
generic,
generic) *hashtbl, *hp;
95 for (hp = hashtbl; hp <= &hashtbl[hashmask]; hp++)
96 KASSERT(LIST_EMPTY(hp), (
"%s: hash not empty", __func__));
100 static const int primes[] = { 1, 13, 31, 61, 127, 251, 509, 761, 1021, 1531,
101 2039, 2557, 3067, 3583, 4093, 4603, 5119, 5623, 6143,
102 6653, 7159, 7673, 8191, 12281, 16381, 24571, 32749 };
103 #define NPRIMES (sizeof(primes) / sizeof(primes[0]))
115 KASSERT(elements > 0, (
"%s: bad elements", __func__));
116 for (i = 1, hashsize =
primes[1]; hashsize <= elements;) {
123 hashtbl =
malloc((u_long)hashsize *
sizeof(*hashtbl), type, M_WAITOK);
124 for (i = 0; i < hashsize; i++)
125 LIST_INIT(&hashtbl[i]);
126 *nentries = hashsize;
static const int primes[]
void * hashinit(int elements, struct malloc_type *type, u_long *hashmask)
void * malloc(unsigned long size, struct malloc_type *mtp, int flags)
void * phashinit(int elements, struct malloc_type *type, u_long *nentries)
void * hashinit_flags(int elements, struct malloc_type *type, u_long *hashmask, int flags)
void free(void *addr, struct malloc_type *mtp)
void hashdestroy(void *vhashtbl, struct malloc_type *type, u_long hashmask)