MCPcopy Index your code
hub / github.com/F-Stack/f-stack / phashinit_flags

Function phashinit_flags

lib/ff_kern_subr.c:115–143  ·  view source on GitHub ↗

* General routine to allocate a prime number sized hash table with control of * memory flags. */

Source from the content-addressed store, hash-verified

113 * memory flags.
114 */
115void *
116phashinit_flags(int elements, struct malloc_type *type, u_long *nentries, int flags)
117{
118 long hashsize, i;
119 LIST_HEAD(generic, generic) *hashtbl;
120
121 KASSERT(elements > 0, ("%s: bad elements", __func__));
122 /* Exactly one of HASH_WAITOK and HASH_NOWAIT must be set. */
123 KASSERT((flags & HASH_WAITOK) ^ (flags & HASH_NOWAIT),
124 ("Bad flags (0x%x) passed to phashinit_flags", flags));
125
126 for (i = 1, hashsize = primes[1]; hashsize <= elements;) {
127 i++;
128 if (i == NPRIMES)
129 break;
130 hashsize = primes[i];
131 }
132 hashsize = primes[i - 1];
133
134 hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl), type,
135 hash_mflags(flags));
136 if (hashtbl == NULL)
137 return (NULL);
138
139 for (i = 0; i < hashsize; i++)
140 LIST_INIT(&hashtbl[i]);
141 *nentries = hashsize;
142 return (hashtbl);
143}
144
145/*
146 * Allocate and initialize a prime number sized hash table with default flag:

Callers 1

phashinitFunction · 0.70

Calls 3

LIST_HEADFunction · 0.85
mallocFunction · 0.85
hash_mflagsFunction · 0.70

Tested by

no test coverage detected