patch: add hash_valid_size()

This commit is contained in:
Alfred E. Heggestad 2011-03-11 11:32:46 +00:00
parent f6ce8b7a93
commit f8b6ec4c24
2 changed files with 18 additions and 0 deletions

View file

@ -18,6 +18,7 @@ struct le *hash_apply(const struct hash *h, list_apply_h *ah, void *arg);
struct list *hash_list(const struct hash *h, uint32_t key);
uint32_t hash_bsize(const struct hash *h);
void hash_flush(struct hash *h);
uint32_t hash_valid_size(uint32_t size);
/* Hash functions */

View file

@ -181,3 +181,20 @@ void hash_flush(struct hash *h)
for (i=0; i<h->bsize; i++)
list_flush(&h->bucket[i]);
}
/**
* Calculate a valid hash size from a random size
*
* @param size Requested size
*
* @return Valid hash size
*/
uint32_t hash_valid_size(uint32_t size)
{
uint32_t x;
for (x=0; (uint32_t)1<<x < size && x < 31; x++);
return 1<<x;
}