-
Notifications
You must be signed in to change notification settings - Fork 0
/
trie_remove.c
executable file
·44 lines (41 loc) · 1.47 KB
/
trie_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* trie_remove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/22 11:38:52 by akharrou #+# #+# */
/* Updated: 2019/03/04 13:17:20 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Includes/stdlib_42.h"
#include "../Includes/trie.h"
void trie_remove(t_trie **root, char *hash,
unsigned int (*char_to_index)(char c))
{
unsigned int index;
if (root && *root && hash)
{
if (*hash == '\0')
{
free((*root)->item);
(*root)->item = NULL;
}
else
{
index = char_to_index(*hash);
if (((*root)->children)[index])
trie_remove(
&(((*root)->children)[index]), hash + 1, char_to_index);
}
if ((*root)->item)
return ;
index = 0;
while (index < SIZE_OF_ARRAY)
if (((*root)->children)[index++])
return ;
free(*root);
(*root) = NULL;
}
}