feat(hmp): allow the user to specify a callback for dealing with their alloced mem
This commit is contained in:
5
ds.c
5
ds.c
@@ -153,7 +153,7 @@ ds_hmp_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ds_hmp_free(ds_hmp_t **hmp)
|
ds_hmp_free(ds_hmp_t **hmp, void kv_callback(_ds_hmp_kv_t *kv))
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
_ds_hmp_kv_t *kv;
|
_ds_hmp_kv_t *kv;
|
||||||
@@ -167,6 +167,9 @@ ds_hmp_free(ds_hmp_t **hmp)
|
|||||||
ll = (*hmp)->data[i];
|
ll = (*hmp)->data[i];
|
||||||
while (ll && ll->data) {
|
while (ll && ll->data) {
|
||||||
if ((kv = ds_sll_remove(&ll, 0))) {
|
if ((kv = ds_sll_remove(&ll, 0))) {
|
||||||
|
if (kv_callback) {
|
||||||
|
kv_callback(kv);
|
||||||
|
}
|
||||||
free(kv);
|
free(kv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
ds.h
2
ds.h
@@ -89,7 +89,7 @@ ds_hmp_t *ds_hmp_init(int data_len);
|
|||||||
*
|
*
|
||||||
* @param hmp pointer to the hashmap
|
* @param hmp pointer to the hashmap
|
||||||
*/
|
*/
|
||||||
void ds_hmp_free(ds_hmp_t **hmp);
|
void ds_hmp_free(ds_hmp_t **hmp, void kv_callback(_ds_hmp_kv_t *kv));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief generate a numerical hash from a given string. You shouldn't need to
|
* @brief generate a numerical hash from a given string. You shouldn't need to
|
||||||
|
Reference in New Issue
Block a user