-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_htupdate.c
40 lines (37 loc) · 1.37 KB
/
ft_htupdate.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_htupdate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thakala <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/25 22:30:57 by thakala #+# #+# */
/* Updated: 2021/12/26 13:45:22 by thakala ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_htupdate(t_ht *ht, ssize_t seed, void *content)
{
t_list *head;
t_list *iterator;
t_list *addition;
head = ht->t[ft_hthash(seed, ht->size)];
if (head)
{
iterator = head;
while (iterator)
{
if (iterator->content_size == seed)
{
iterator->content = content;
return (iterator->content);
}
iterator = iterator->next;
}
}
addition = ft_lstnew(content, seed);
if (!addition)
return (NULL);
ft_lstadd(&head, addition);
return (addition->content);
}