-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashtab_remove.c
executable file
·57 lines (53 loc) · 1.97 KB
/
hashtab_remove.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
49
50
51
52
53
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_remove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/07 17:26:14 by akharrou #+# #+# */
/* Updated: 2019/03/09 08:54:11 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
/*
** NAME
** hashtab_remove -- remove and free an entry from a hashtable.
**
** SYNOPSIS
** #include "stdlib_42.h"
** #include "string_42.h"
** #include "hashtable.h"
**
** int
** hashtab_remove(t_hashtable **table, char *key);
**
** PARAMETERS
**
** t_hashtable **table Pointer to a pointer to a
** hashtable.
**
** char *key Key corresponding to an
** entry.
**
** DESCRIPTION
** Looks for an entry based on the 'key', if found, the entry is
** deleted/free'd along with everything it contains. If the entry
** is not found, nothing happens and -1 is returned.
**
** RETURN VALUES
** If successful returns 0; otherwise -1.
*/
#include "../Includes/stdlib_42.h"
#include "../Includes/string_42.h"
#include "../Includes/hashtable.h"
int hashtab_remove(t_hashtable **table, char *key)
{
void *item;
item = hashtab_popitem(table, key);
if (item != NULL)
{
free(item);
return (0);
}
return (-1);
}