aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-02-17 05:03:15 +0100
committerCharles <sircharlesaze@gmail.com>2020-02-17 05:03:15 +0100
commit0362f55a094b5ec813d940b66f397abfa13fbe49 (patch)
tree98283bdff3d1a0bb876fc55fa535d60d4aa2a6a9 /src
parenteb0678367c5cb09b43423f77d6f1c3063fae9a91 (diff)
downloadlibft-0362f55a094b5ec813d940b66f397abfa13fbe49.tar.gz
libft-0362f55a094b5ec813d940b66f397abfa13fbe49.tar.bz2
libft-0362f55a094b5ec813d940b66f397abfa13fbe49.zip
amend me
Diffstat (limited to 'src')
-rw-r--r--src/ht/ft_htcontent_new.c2
-rw-r--r--src/ht/ft_htset.c15
2 files changed, 13 insertions, 4 deletions
diff --git a/src/ht/ft_htcontent_new.c b/src/ht/ft_htcontent_new.c
index 4ffa9bf..214e125 100644
--- a/src/ht/ft_htcontent_new.c
+++ b/src/ht/ft_htcontent_new.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/30 08:45:36 by cacharle #+# #+# */
-/* Updated: 2020/01/30 09:52:28 by cacharle ### ########.fr */
+/* Updated: 2020/02/17 04:09:50 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/src/ht/ft_htset.c b/src/ht/ft_htset.c
index 5ace788..4157134 100644
--- a/src/ht/ft_htset.c
+++ b/src/ht/ft_htset.c
@@ -6,21 +6,31 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/30 08:41:52 by cacharle #+# #+# */
-/* Updated: 2020/01/31 10:33:39 by cacharle ### ########.fr */
+/* Updated: 2020/02/17 05:02:15 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "libft_ht.h"
-t_ftht_content *ft_htset(t_ftht *ht, char *key, void *value)
+t_ftht_content *ft_htset(t_ftht *ht, char *key, void *value, void (*del)(void*))
{
t_ftht_digest digest;
t_ftht_content *content;
t_ftht_entry entry;
+ t_ftlst *tmp;
if (ht == NULL || key == NULL)
return (NULL);
+ digest = ft_hthash(ht, key);
+ tmp = ft_lstlfind(ht->entries[digest], ft_inter_htkey_cmp, entry);
+ if (tmp != NULL)
+ {
+ if (del != NULL)
+ del(((t_ftht_content*)tmp->content)->value);
+ ((t_ftht_content*)tmp->content)->value = value;
+ return ((t_ftht_content*)tmp->content);
+ }
if ((content = ft_htcontent_new(key, value)) == NULL)
return (NULL);
if ((entry = ft_lstnew(content)) == NULL)
@@ -28,7 +38,6 @@ t_ftht_content *ft_htset(t_ftht *ht, char *key, void *value)
free(content);
return (NULL);
}
- digest = ft_hthash(ht, key);
ft_lstadd_front(ht->entries + digest, entry);
return (content);
}