-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_btreefrom_map.c
36 lines (32 loc) · 1.37 KB
/
ft_btreefrom_map.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_btreefrom_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tle-meur <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/23 14:46:26 by tle-meur #+# #+# */
/* Updated: 2015/11/23 14:54:35 by tle-meur ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int my_cmp(const t_btree *a, const t_btree *b)
{
if (a->content_size != b->content_size)
return (a->content_size - b->content_size);
return (ft_memcmp(a->content, b->content, a->content_size));
}
t_btree *ft_btreefrom_map(t_map *map)
{
t_data add;
t_btree *root;
root = NULL;
while (map)
{
add.data = ((t_list*)map->value)->content;
add.data_size = ((t_list*)map->value)->content_size;
ft_btreeadd(&root, &add, &my_cmp);
map = map->next;
}
return (root);
}