data_structures
hashmap_delete.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* hashmap_delete.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/21 19:04:25 by unite #+# #+# */
10 /* Updated: 2020/09/03 22:30:05 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "hashmap.h"
15 
17 {
18  size_t i;
19 
20  if (!hm)
21  return ;
22  if (hm->keys)
23  {
24  i = 0;
25  while (i < hm->capacity)
26  hm->key_type->del(hm->keys[i++]);
27  free(hm->keys);
28  }
29  if (hm->vals)
30  {
31  i = 0;
32  while (i < hm->capacity)
33  hm->val_type->del(hm->vals[i++]);
34  free(hm->vals);
35  }
36  free(hm);
37 }
s_hashmap::key_type
const t_type * key_type
The type of keys in the hashmap.
Definition: hashmap.h:54
hashmap.h
s_hashmap::keys
void ** keys
The keys.
Definition: hashmap.h:50
hashmap_delete
void hashmap_delete(t_hashmap *hm)
Deletes this hashmap and free all its items and the associated data.
Definition: hashmap_delete.c:16
s_hashmap
A symbol table of generic key-value pairs, implemented as a dynamically resizing linear-probing hashm...
Definition: hashmap.h:48
s_type::del
void(* del)(void *)
A function pointer used to free the memory taken by the data type.
Definition: types.h:51
s_hashmap::val_type
const t_type * val_type
The type of values in the hashmap.
Definition: hashmap.h:55
s_hashmap::vals
void ** vals
The values.
Definition: hashmap.h:51