From 3c3f1115f6e9a9b914e2dcbd796501ca7ce85342 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 19 Feb 2020 02:51:44 +0100 Subject: Tested ht* --- src/ht/ft_htdelone.c | 6 +++--- src/ht/ft_htdelone_key.c | 19 ------------------- src/ht/ft_htdestroy_all.c | 26 -------------------------- src/ht/ft_htdestroy_key.c | 26 -------------------------- src/ht/ft_htget.c | 9 ++++++--- src/ht/ft_htset.c | 16 +++++++++------- src/ht/ft_inter_htkey_cmp.c | 2 +- src/lst/ft_lstlfind.c | 2 +- src/lst/ft_lstremove_if.c | 4 ++-- 9 files changed, 22 insertions(+), 88 deletions(-) delete mode 100644 src/ht/ft_htdelone_key.c delete mode 100644 src/ht/ft_htdestroy_all.c delete mode 100644 src/ht/ft_htdestroy_key.c (limited to 'src') diff --git a/src/ht/ft_htdelone.c b/src/ht/ft_htdelone.c index 00a0b11..2c54721 100644 --- a/src/ht/ft_htdelone.c +++ b/src/ht/ft_htdelone.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 09:27:18 by cacharle #+# #+# */ -/* Updated: 2020/02/17 03:06:58 by cacharle ### ########.fr */ +/* Updated: 2020/02/19 02:35:06 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,6 @@ void ft_htdelone(t_ftht *ht, char *key, void (*del)(t_ftht_content*)) { ft_lstremove_if(ht->entries + ft_hthash(ht, key), - ft_inter_htkey_cmp, key, - (void (*)(void*))del); + ft_inter_htkey_cmp, key, + (void (*)(void*))del); } diff --git a/src/ht/ft_htdelone_key.c b/src/ht/ft_htdelone_key.c deleted file mode 100644 index 96d55ec..0000000 --- a/src/ht/ft_htdelone_key.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_htdelone_key.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/01/30 09:45:11 by cacharle #+# #+# */ -/* Updated: 2020/01/30 09:46:42 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" -#include "libft_ht.h" - -void ft_htdelone_key(t_ftht *ht, char *key) -{ - ft_htdelone(ht, key, ft_inter_htdelcontent_key); -} diff --git a/src/ht/ft_htdestroy_all.c b/src/ht/ft_htdestroy_all.c deleted file mode 100644 index 6f98a43..0000000 --- a/src/ht/ft_htdestroy_all.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_htdestroy_all.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/01/30 08:29:58 by cacharle #+# #+# */ -/* Updated: 2020/01/31 10:43:13 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft_ht.h" - -static void st_htdelcontent_all(t_ftht_content *content) -{ - if (content == NULL) - return ; - free(content->key); - free(content->value); -} - -void ft_htdestroy_all(t_ftht *ht) -{ - ft_htdestroy(ht, *st_htdelcontent_all); -} diff --git a/src/ht/ft_htdestroy_key.c b/src/ht/ft_htdestroy_key.c deleted file mode 100644 index a704314..0000000 --- a/src/ht/ft_htdestroy_key.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_htdestroy_key.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/01/30 08:31:02 by cacharle #+# #+# */ -/* Updated: 2020/01/31 10:43:45 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" -#include "libft_ht.h" - -void ft_inter_htdelcontent_key(t_ftht_content *content) -{ - if (content == NULL) - return ; - free(content->key); -} - -void ft_htdestroy_key(t_ftht *ht) -{ - ft_htdestroy(ht, *ft_inter_htdelcontent_key); -} diff --git a/src/ht/ft_htget.c b/src/ht/ft_htget.c index c5e7234..76e4fb2 100644 --- a/src/ht/ft_htget.c +++ b/src/ht/ft_htget.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 08:33:21 by cacharle #+# #+# */ -/* Updated: 2020/02/17 03:06:07 by cacharle ### ########.fr */ +/* Updated: 2020/02/19 01:44:41 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,10 +17,13 @@ void *ft_htget(t_ftht *ht, char *key) { t_ftht_digest digest; + t_ftlst *found; if (ht == NULL || key == NULL) return (NULL); digest = ft_hthash(ht, key); - return (((t_ftht_content*)ft_lstlfind(ht->entries[digest], - ft_inter_htkey_cmp, key)->content)->value); + found = ft_lstlfind(ht->entries[digest], ft_inter_htkey_cmp, key); + if (found == NULL) + return (NULL); + return (((t_ftht_content*)found->content)->value); } diff --git a/src/ht/ft_htset.c b/src/ht/ft_htset.c index 4157134..c7068d5 100644 --- a/src/ht/ft_htset.c +++ b/src/ht/ft_htset.c @@ -6,14 +6,15 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 08:41:52 by cacharle #+# #+# */ -/* Updated: 2020/02/17 05:02:15 by cacharle ### ########.fr */ +/* Updated: 2020/02/19 02:44:10 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" #include "libft_ht.h" -t_ftht_content *ft_htset(t_ftht *ht, char *key, void *value, void (*del)(void*)) +t_ftht_content *ft_htset(t_ftht *ht, char *key, void *value, + void (*del)(t_ftht_content*)) { t_ftht_digest digest; t_ftht_content *content; @@ -22,17 +23,18 @@ t_ftht_content *ft_htset(t_ftht *ht, char *key, void *value, void (*del)(void*)) if (ht == NULL || key == NULL) return (NULL); + if ((content = ft_htcontent_new(key, value)) == NULL) + return (NULL); digest = ft_hthash(ht, key); - tmp = ft_lstlfind(ht->entries[digest], ft_inter_htkey_cmp, entry); + tmp = ft_lstlfind(ht->entries[digest], ft_inter_htkey_cmp, key); if (tmp != NULL) { if (del != NULL) - del(((t_ftht_content*)tmp->content)->value); - ((t_ftht_content*)tmp->content)->value = value; + (*del)(tmp->content); + tmp->content = content; return ((t_ftht_content*)tmp->content); } - if ((content = ft_htcontent_new(key, value)) == NULL) - return (NULL); + if ((entry = ft_lstnew(content)) == NULL) { free(content); diff --git a/src/ht/ft_inter_htkey_cmp.c b/src/ht/ft_inter_htkey_cmp.c index c91663d..6f04ecc 100644 --- a/src/ht/ft_inter_htkey_cmp.c +++ b/src/ht/ft_inter_htkey_cmp.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 09:24:39 by cacharle #+# #+# */ -/* Updated: 2020/02/16 02:25:43 by cacharle ### ########.fr */ +/* Updated: 2020/02/19 02:03:14 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/lst/ft_lstlfind.c b/src/lst/ft_lstlfind.c index ddb890b..92d37d8 100644 --- a/src/lst/ft_lstlfind.c +++ b/src/lst/ft_lstlfind.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/17 03:04:52 by cacharle #+# #+# */ -/* Updated: 2020/02/17 03:34:19 by cacharle ### ########.fr */ +/* Updated: 2020/02/19 02:03:11 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/lst/ft_lstremove_if.c b/src/lst/ft_lstremove_if.c index 488539e..5221ae4 100644 --- a/src/lst/ft_lstremove_if.c +++ b/src/lst/ft_lstremove_if.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 09:36:49 by cacharle #+# #+# */ -/* Updated: 2020/02/16 03:57:07 by cacharle ### ########.fr */ +/* Updated: 2020/02/19 02:06:22 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ void ft_lstremove_if(t_ftlst **lst, t_ftcompar_func cmp, if (lst == NULL || *lst == NULL) return ; - if (cmp((*lst)->content, ref) == 0) + if (cmp(ref, (*lst)->content) == 0) { saved_next = (*lst)->next; ft_lstdelone(*lst, del); -- cgit