feat(hash_map): destroy_pair_list
This commit is contained in:
parent
0c6c357161
commit
cf5da6f231
1 changed files with 10 additions and 2 deletions
|
|
@ -28,6 +28,14 @@ static size_t hash(const char *key)
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void destroy_pair_list(struct pair_list **p)
|
||||||
|
{
|
||||||
|
free((char *)(*p)->key);
|
||||||
|
free((*p)->value);
|
||||||
|
free((*p));
|
||||||
|
*p = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
struct hash_map *hash_map_init(size_t size)
|
struct hash_map *hash_map_init(size_t size)
|
||||||
{
|
{
|
||||||
struct hash_map *p = malloc(sizeof(struct hash_map));
|
struct hash_map *p = malloc(sizeof(struct hash_map));
|
||||||
|
|
@ -102,7 +110,7 @@ void hash_map_free(struct hash_map *hash_map)
|
||||||
{
|
{
|
||||||
prev = l;
|
prev = l;
|
||||||
l = l->next;
|
l = l->next;
|
||||||
free(prev);
|
destroy_pair_list(&prev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(hash_map->data);
|
free(hash_map->data);
|
||||||
|
|
@ -163,7 +171,7 @@ bool hash_map_remove(struct hash_map *hash_map, const char *key)
|
||||||
p->next = l->next;
|
p->next = l->next;
|
||||||
else
|
else
|
||||||
hash_map->data[i] = l->next;
|
hash_map->data[i] = l->next;
|
||||||
free(l);
|
destroy_pair_list(&l);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
p = l;
|
p = l;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue