diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-01-30 20:57:29 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-01-30 20:57:29 +0100 |
| commit | 3b884e3836c70b1a19eb7778308fadbc608b0384 (patch) | |
| tree | e57b327c39e4c16fbd8ad1b1a1511f143df71cdd /src/ht | |
| parent | 6500b1ca9ce911d3db7c94ee3f4ee38489b8861a (diff) | |
| download | libft-3b884e3836c70b1a19eb7778308fadbc608b0384.tar.gz libft-3b884e3836c70b1a19eb7778308fadbc608b0384.tar.bz2 libft-3b884e3836c70b1a19eb7778308fadbc608b0384.zip | |
making hashtable compile
Diffstat (limited to 'src/ht')
| -rw-r--r-- | src/ht/ft_htdelone.c | 4 | ||||
| -rw-r--r-- | src/ht/ft_htdelone_key.c | 3 | ||||
| -rw-r--r-- | src/ht/ft_htdestroy.c | 3 | ||||
| -rw-r--r-- | src/ht/ft_htdestroy_all.c | 4 | ||||
| -rw-r--r-- | src/ht/ft_htdestroy_key.c | 3 | ||||
| -rw-r--r-- | src/ht/ft_htdestroy_value.c | 25 | ||||
| -rw-r--r-- | src/ht/ft_htget.c | 4 | ||||
| -rw-r--r-- | src/ht/ft_hthash.c | 6 | ||||
| -rw-r--r-- | src/ht/ft_htnew.c | 1 | ||||
| -rw-r--r-- | src/ht/ft_htset.c | 5 |
10 files changed, 22 insertions, 36 deletions
diff --git a/src/ht/ft_htdelone.c b/src/ht/ft_htdelone.c index 8d350ae..b376d8b 100644 --- a/src/ht/ft_htdelone.c +++ b/src/ht/ft_htdelone.c @@ -15,5 +15,7 @@ void ft_htdelone(t_ftht *ht, char *key, void (*del)(t_ftht_content*)) { - ft_lstremove_if(ht->entries + ft_hthash(key), ft_iter_htkey_equal, key, del); + ft_lstremove_if(ht->entries + ft_hthash(ht, key), + (t_ftbool (*)(void*, void*))ft_inter_htkey_equal, key, + (void (*)(void*))del); } diff --git a/src/ht/ft_htdelone_key.c b/src/ht/ft_htdelone_key.c index 5dc0c16..96d55ec 100644 --- a/src/ht/ft_htdelone_key.c +++ b/src/ht/ft_htdelone_key.c @@ -11,8 +11,9 @@ /* ************************************************************************** */ #include "libft.h" +#include "libft_ht.h" -void ft_htdelone_key(t_ftht *ht, char *key) +void ft_htdelone_key(t_ftht *ht, char *key) { ft_htdelone(ht, key, ft_inter_htdelcontent_key); } diff --git a/src/ht/ft_htdestroy.c b/src/ht/ft_htdestroy.c index 6e04386..e0442c6 100644 --- a/src/ht/ft_htdestroy.c +++ b/src/ht/ft_htdestroy.c @@ -11,13 +11,14 @@ /* ************************************************************************** */ #include "libft.h" +#include "libft_ht.h" void ft_htdestroy(t_ftht *ht, void (*del)(t_ftht_content*)) { if (ht == NULL) return ; while (ht->size-- > 0) - ft_lstclear(ht->entries + ht->size, del); + ft_lstclear(ht->entries + ht->size, (void (*)(void*))del); free(ht->entries); free(ht); } diff --git a/src/ht/ft_htdestroy_all.c b/src/ht/ft_htdestroy_all.c index 761f577..ec54044 100644 --- a/src/ht/ft_htdestroy_all.c +++ b/src/ht/ft_htdestroy_all.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "libft.h" +#include "libft_ht.h" static void st_htdelcontent_all(t_ftht_content *content) { @@ -22,5 +22,5 @@ static void st_htdelcontent_all(t_ftht_content *content) void ft_htdestroy_all(t_ftht *ht) { - ft_htdestroy(ht, *st_dtdelcontent_all); + ft_htdestroy(ht, *st_htdelcontent_all); } diff --git a/src/ht/ft_htdestroy_key.c b/src/ht/ft_htdestroy_key.c index e3d562f..1cae2fd 100644 --- a/src/ht/ft_htdestroy_key.c +++ b/src/ht/ft_htdestroy_key.c @@ -11,6 +11,7 @@ /* ************************************************************************** */ #include "libft.h" +#include "libft_ht.h" void ft_inter_htdelcontent_key(t_ftht_content *content) { @@ -21,5 +22,5 @@ void ft_inter_htdelcontent_key(t_ftht_content *content) void ft_htdestroy_key(t_ftht *ht) { - ft_htdestroy(ht, *st_dtdelcontent_key); + ft_htdestroy(ht, *ft_inter_htdelcontent_key); } diff --git a/src/ht/ft_htdestroy_value.c b/src/ht/ft_htdestroy_value.c deleted file mode 100644 index b71b960..0000000 --- a/src/ht/ft_htdestroy_value.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_htdestroy_value.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/01/30 08:31:29 by cacharle #+# #+# */ -/* Updated: 2020/01/30 08:31:49 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static void st_htdelcontent_value(t_ftht_content *content) -{ - if (content == NULL) - return ; - free(content->value); -} - -void ft_htdestroy_value(t_ftht *ht) -{ - ft_htdestroy(ht, *st_dtdelcontent_value); -} diff --git a/src/ht/ft_htget.c b/src/ht/ft_htget.c index 983fd74..b4715a3 100644 --- a/src/ht/ft_htget.c +++ b/src/ht/ft_htget.c @@ -11,6 +11,7 @@ /* ************************************************************************** */ #include "libft.h" +#include "libft_ht.h" t_ftht_content *ft_htget(t_ftht *ht, char *key) { @@ -20,5 +21,6 @@ t_ftht_content *ft_htget(t_ftht *ht, char *key) return (NULL); digest = ft_hthash(ht, key); return (ft_lstbsearch(ht->entries[digest], - &ft_inter_htkey_equal, key)->content); + (t_ftbool (*)(void*, void*))ft_inter_htkey_equal, + key)->content); } diff --git a/src/ht/ft_hthash.c b/src/ht/ft_hthash.c index 66f8efb..e7e696c 100644 --- a/src/ht/ft_hthash.c +++ b/src/ht/ft_hthash.c @@ -10,6 +10,8 @@ /* */ /* ************************************************************************** */ +#include "libft_ht.h" + t_ftht_digest ft_hthash(t_ftht *ht, char *key) { t_ftht_digest digest; @@ -19,8 +21,8 @@ t_ftht_digest ft_hthash(t_ftht *ht, char *key) digest = *key++ << 7; while (*key != '\0') { - digest = ((1000003 * digest) ^ *key) & (1<<32); + digest = ((1000003 * digest) ^ *key) & (1 << 16); key++; } - return (digest); + return (digest % ht->size); } diff --git a/src/ht/ft_htnew.c b/src/ht/ft_htnew.c index c3b7cc7..bcf81d1 100644 --- a/src/ht/ft_htnew.c +++ b/src/ht/ft_htnew.c @@ -11,6 +11,7 @@ /* ************************************************************************** */ #include "libft.h" +#include "libft_ht.h" t_ftht *ft_htnew(t_ftsize size) { diff --git a/src/ht/ft_htset.c b/src/ht/ft_htset.c index 32aa448..86e9690 100644 --- a/src/ht/ft_htset.c +++ b/src/ht/ft_htset.c @@ -11,6 +11,7 @@ /* ************************************************************************** */ #include "libft.h" +#include "libft_ht.h" t_ftht_content *ft_htset(t_ftht *ht, char *key, void *value) { @@ -19,10 +20,10 @@ t_ftht_content *ft_htset(t_ftht *ht, char *key, void *value) t_ftht_entry entry; if (ht == NULL || key == NULL) - return (NULL) + return (NULL); if ((content = ft_htcontent_new(key, value)) == NULL) return (NULL); - if ((entry = ft_lstnew(content)) = NULL) + if ((entry = ft_lstnew(content)) == NULL) { free(content); return (NULL); |
