summaryrefslogtreecommitdiff
path: root/ckcapi-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'ckcapi-util.c')
-rw-r--r--ckcapi-util.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/ckcapi-util.c b/ckcapi-util.c
index 3c587ac..7fd1d1d 100644
--- a/ckcapi-util.c
+++ b/ckcapi-util.c
@@ -202,7 +202,7 @@ typedef struct _HashEntry
unsigned int hash;
const void* key;
size_t klen;
- const void* val;
+ void* val;
}
HashEntry;
@@ -252,17 +252,19 @@ ckcapi_hash_new()
}
void
-ckcapi_hash_free(CkCapiHash* ht)
+ckcapi_hash_free(CkCapiHash* ht, CkCapiHashDestroy destroy_func)
{
HashEntry* he;
HashEntry* next;
size_t i;
- for(i = 0; i < ht->max; ++i)
+ for(i = 0; i <= ht->max; ++i)
{
for(he = ht->array[i]; he; )
{
next = he->next;
+ if(destroy_func)
+ (destroy_func)((void*)he->val);
free(he);
he = next;
}
@@ -290,13 +292,13 @@ expand_array(CkCapiHash* ht)
if(!new_array)
return 0;
- for(i = 0; i < ht->max; ++i)
+ for(i = 0; i <= ht->max; ++i)
{
for(he = ht->array[i]; he; he = he->next)
{
- unsigned int i = he->hash & new_max;
- he->next = new_array[i];
- new_array[i] = he;
+ unsigned int j = he->hash & new_max;
+ he->next = new_array[j];
+ new_array[j] = he;
}
}
@@ -318,7 +320,7 @@ expand_array(CkCapiHash* ht)
*/
static HashEntry**
-find_entry(CkCapiHash* ht, const void* key, size_t klen, const void* val)
+find_entry(CkCapiHash* ht, const void* key, size_t klen, void* val)
{
HashEntry** hep;
HashEntry* he;