diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-02-19 02:51:44 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-02-19 02:51:44 +0100 |
| commit | 3c3f1115f6e9a9b914e2dcbd796501ca7ce85342 (patch) | |
| tree | 29803aac5bd1fe039b9a8179e8c2a4f07e68ec82 /src/ht | |
| parent | 0362f55a094b5ec813d940b66f397abfa13fbe49 (diff) | |
| download | libft-3c3f1115f6e9a9b914e2dcbd796501ca7ce85342.tar.gz libft-3c3f1115f6e9a9b914e2dcbd796501ca7ce85342.tar.bz2 libft-3c3f1115f6e9a9b914e2dcbd796501ca7ce85342.zip | |
Tested ht*
Diffstat (limited to 'src/ht')
| -rw-r--r-- | src/ht/ft_htdelone.c | 6 | ||||
| -rw-r--r-- | src/ht/ft_htdelone_key.c | 19 | ||||
| -rw-r--r-- | src/ht/ft_htdestroy_all.c | 26 | ||||
| -rw-r--r-- | src/ht/ft_htdestroy_key.c | 26 | ||||
| -rw-r--r-- | src/ht/ft_htget.c | 9 | ||||
| -rw-r--r-- | src/ht/ft_htset.c | 16 | ||||
| -rw-r--r-- | src/ht/ft_inter_htkey_cmp.c | 2 |
7 files changed, 19 insertions, 85 deletions
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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ |
