-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap_delete.c
48 lines (44 loc) · 1.44 KB
/
map_delete.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map_delete.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mihykim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/01 13:01:23 by mihykim #+# #+# */
/* Updated: 2020/06/01 13:17:28 by mihykim ### ########.fr */
/* */
/* ************************************************************************** */
#include "map.h"
# define SUCCESS 1
# define FAILURE 0
void *map_delete(t_hash_map *map, const char *key)
{
t_node *curr;
unsigned int i;
if (map == NULL)
return (NULL);
i = get_hash(key);
curr = map->map[i];
if (curr == NULL)
return (FAILURE);
if (strcmp(curr->key, key) == 0)
{
map->map[i] = curr->next;
free(curr);
map->size--;
return (curr->value);
}
while (curr->next)
{
if (strcmp(curr->key, key) == 0)
{
curr->next = curr->next->next;
free(curr);
map->size--;
return (curr->value);
}
curr = curr->next;
}
return (NULL);
}