32,7 → 32,7 |
|
/** |
* @file |
* @brief Implementation of generic chained hash table. |
* @brief Implementation of generic chained hash table. |
* |
* This file contains implementation of generic chained hash table. |
*/ |
56,13 → 56,15 |
index_t i; |
|
ASSERT(h); |
ASSERT(op && op->hash && op->compare); |
ASSERT(op); |
ASSERT(op->hash); |
ASSERT(op->compare); |
ASSERT(max_keys > 0); |
|
h->entry = (link_t *) malloc(m * sizeof(link_t), 0); |
if (!h->entry) { |
panic("cannot allocate memory for hash table\n"); |
} |
if (!h->entry) |
panic("Cannot allocate memory for hash table."); |
|
memsetb(h->entry, m * sizeof(link_t), 0); |
|
for (i = 0; i < m; i++) |
82,10 → 84,13 |
void hash_table_insert(hash_table_t *h, unative_t key[], link_t *item) |
{ |
index_t chain; |
|
|
ASSERT(item); |
ASSERT(h && h->op && h->op->hash && h->op->compare); |
|
ASSERT(h); |
ASSERT(h->op); |
ASSERT(h->op->hash); |
ASSERT(h->op->compare); |
|
chain = h->op->hash(key); |
ASSERT(chain < h->entries); |
|
103,9 → 108,12 |
{ |
link_t *cur; |
index_t chain; |
|
ASSERT(h && h->op && h->op->hash && h->op->compare); |
|
|
ASSERT(h); |
ASSERT(h->op); |
ASSERT(h->op->hash); |
ASSERT(h->op->compare); |
|
chain = h->op->hash(key); |
ASSERT(chain < h->entries); |
|
123,7 → 131,7 |
|
/** Remove all matching items from hash table. |
* |
* For each removed item, h->remove_callback() is called. |
* For each removed item, h->remove_callback() is called (if not NULL). |
* |
* @param h Hash table. |
* @param key Array of keys that will be compared against items of the hash table. |
133,12 → 141,15 |
{ |
index_t chain; |
link_t *cur; |
|
ASSERT(h && h->op && h->op->hash && h->op->compare && h->op->remove_callback); |
|
ASSERT(h); |
ASSERT(h->op); |
ASSERT(h->op->hash); |
ASSERT(h->op->compare); |
ASSERT(keys <= h->max_keys); |
|
if (keys == h->max_keys) { |
|
|
/* |
* All keys are known, hash_table_find() can be used to find the entry. |
*/ |
146,7 → 157,8 |
cur = hash_table_find(h, key); |
if (cur) { |
list_remove(cur); |
h->op->remove_callback(cur); |
if (h->op->remove_callback) |
h->op->remove_callback(cur); |
} |
return; |
} |
164,7 → 176,8 |
cur = cur->prev; |
|
list_remove(hlp); |
h->op->remove_callback(hlp); |
if (h->op->remove_callback) |
h->op->remove_callback(hlp); |
|
continue; |
} |