/* * Here we simply round the number of elements up to the nearest power of two. * I tried also other options like rounding down or rounding to the closest * power of two (up or down based on which is closer), but I was unable to * find any significant difference in lookup/insert performance that would * justify switching to a different (less intuitive) formula. It could be that * a different formula is actually more optimal, but any future changes here * should be supported with performance/memory usage data. * * The total memory used by the htable arrays (only) with Fedora policy loaded * is approximately 163 KB at the time of writing.
*/ static u32 hashtab_compute_size(u32 nel)
{ return nel == 0 ? 0 : roundup_pow_of_two(nel);
}
for (i = 0; i < h->size; i++) {
cur = h->htable[i]; while (cur) {
temp = cur;
cur = cur->next;
kmem_cache_free(hashtab_node_cachep, temp);
}
h->htable[i] = NULL;
}
kfree(h->htable);
h->htable = NULL;
}
int hashtab_map(struct hashtab *h, int (*apply)(void *k, void *d, void *args), void *args)
{
u32 i; int ret; struct hashtab_node *cur;
for (i = 0; i < h->size; i++) {
cur = h->htable[i]; while (cur) {
ret = apply(cur->key, cur->datum, args); if (ret) return ret;
cur = cur->next;
}
} return 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.