From d2feec1f97e9f8f201e56ad33662bb663c328a0a Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 3 Apr 2020 07:19:25 +0200 Subject: Changing hash table del function to regular one with a first order internal function, removing a few typedef to instead use standard types --- include/libft.h | 14 +++++++------- include/libft_algo.h | 11 ++++------- include/libft_def.h | 36 ++++++++++++++++++++++++++++++++++++ include/libft_ht.h | 50 ++++++++++++++++++++++++-------------------------- include/libft_lst.h | 2 +- include/libft_mem.h | 2 +- include/libft_types.h | 30 ------------------------------ 7 files changed, 73 insertions(+), 72 deletions(-) create mode 100644 include/libft_def.h delete mode 100644 include/libft_types.h (limited to 'include') diff --git a/include/libft.h b/include/libft.h index 74f074b..e982608 100644 --- a/include/libft.h +++ b/include/libft.h @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 09:45:02 by cacharle #+# #+# */ -/* Updated: 2020/02/10 02:19:47 by cacharle ### ########.fr */ +/* Updated: 2020/04/03 06:32:37 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,18 +17,18 @@ # include # include # include +# include # include # include -# include "libft_types.h" -# include "libft_ctype.h" -# include "libft_io.h" -# include "libft_mem.h" -# include "libft_str.h" - # ifdef __linux__ # include # define OPEN_MAX FOPEN_MAX # endif +# include "libft_io.h" +# include "libft_mem.h" +# include "libft_str.h" +# include "libft_ctype.h" + #endif diff --git a/include/libft_algo.h b/include/libft_algo.h index 7223e7b..04191e6 100644 --- a/include/libft_algo.h +++ b/include/libft_algo.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_algo.h :+: :+: :+: */ +/* libft_algo.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/19 07:22:57 by cacharle #+# #+# */ -/* Updated: 2020/02/10 05:58:26 by cacharle ### ########.fr */ +/* Updated: 2020/04/03 07:05:04 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,11 +14,8 @@ # define LIBFT_ALGO_H # include -# include # include "libft_mem.h" -# include "libft_types.h" - -typedef int (*t_ftcompar_func)(const void*, const void*); +# include "libft_def.h" typedef struct { @@ -39,7 +36,7 @@ typedef struct s_ft_search_const t_ftcompar_func compar; } t_ftsearch_const; -t_ftbool ft_is_set(void *base, size_t nel, size_t width, +bool ft_is_set(void *base, size_t nel, size_t width, t_ftcompar_func compar); int ft_compar_int(const void *a, const void *b); void ft_qsort(void *base, size_t nel, size_t width, diff --git a/include/libft_def.h b/include/libft_def.h new file mode 100644 index 0000000..69a7655 --- /dev/null +++ b/include/libft_def.h @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_def.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/31 10:36:56 by cacharle #+# #+# */ +/* Updated: 2020/04/03 07:04:57 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_DEF_H +# define LIBFT_DEF_H + +# include +# include + +# define TRUE 1 +# define FALSE 0 + +typedef unsigned char t_ftbyte; +typedef int t_ftbool; +typedef unsigned int t_ftsize; + +typedef char t_ftchar; +typedef unsigned char t_ftuchar; +typedef int t_ftint; +typedef unsigned int t_ftuint; +typedef long int t_ftlong; +typedef unsigned long int t_ftulong; + +typedef void (*t_ftdel_func)(void*); +typedef int (*t_ftcompar_func)(const void*, const void*); + +#endif diff --git a/include/libft_ht.h b/include/libft_ht.h index 10c6fc7..b3c1d2d 100644 --- a/include/libft_ht.h +++ b/include/libft_ht.h @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/31 10:36:09 by cacharle #+# #+# */ -/* Updated: 2020/04/01 17:59:35 by charles ### ########.fr */ +/* Updated: 2020/04/03 07:12:12 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ */ # include "libft.h" +# include "libft_def.h" # include "libft_lst.h" /* @@ -27,45 +28,42 @@ ** \param value Pointer to data */ -typedef struct s_ftht_entry +typedef struct s_ftht_entry { - char *key; - void *value; -} t_ftht_entry; - -typedef t_ftlst* t_ftht_bucket; + char *key; + void *value; +} t_ftht_entry; /* ** \brief Hash table struct ** \param size Number of buckets -** \param buckets Bucket array +** \param buckets Bucket array, each bucket is a linked list */ -typedef struct s_ftht +typedef struct s_ftht { - t_ftsize size; - t_ftht_bucket *buckets; -} t_ftht; - -typedef t_ftuint t_ftht_digest; + size_t size; + t_ftlst **buckets; +} t_ftht; -t_ftht_digest ft_hthash(t_ftht *ht, char *key); +size_t ft_hthash(t_ftht *ht, char *key); -t_ftht *ft_htnew(t_ftsize size); -void ft_htdestroy(t_ftht *ht, void (*del)(t_ftht_entry*)); -void *ft_htget(t_ftht *ht, char *key); -t_ftht_entry *ft_htset(t_ftht *ht, char *key, void *value, - void (*del)(t_ftht_entry*)); -void ft_htdelone(t_ftht *ht, char *key, - void (*del)(t_ftht_entry*)); -t_ftht_entry *ft_htentry_new(char *key, void *value); -void ft_htiter(t_ftht *ht, void (*f)(t_ftht_entry*)); +t_ftht *ft_htnew(size_t size); +void ft_htdestroy(t_ftht *ht, t_ftdel_func del); +void *ft_htget(t_ftht *ht, char *key); +t_ftht_entry *ft_htset(t_ftht *ht, char *key, void *value, + t_ftdel_func del); +void ft_htdelone(t_ftht *ht, char *key, t_ftdel_func del); +t_ftht_entry *ft_htentry_new(char *key, void *value); +void ft_htiter(t_ftht *ht, void (*f)(t_ftht_entry*)); /* ** internals */ -int ft_inter_htkey_cmp(const void *ref_key, - const void *content); +int ft_inter_htkey_cmp(const void *ref_key, const void *content); +void ft_inter_htdel_first_order(t_ftht_entry *entry); +void ft_inter_htdel_first_order_setup(t_ftdel_func del); +void ft_inter_htdel_first_order_teardown(void); #endif diff --git a/include/libft_lst.h b/include/libft_lst.h index d7157a9..2938bd2 100644 --- a/include/libft_lst.h +++ b/include/libft_lst.h @@ -19,7 +19,7 @@ */ # include -# include "libft_types.h" +# include "libft_def.h" # include "libft_algo.h" /* diff --git a/include/libft_mem.h b/include/libft_mem.h index 37c072e..26b4ccd 100644 --- a/include/libft_mem.h +++ b/include/libft_mem.h @@ -14,7 +14,7 @@ # define LIBFT_MEM_H # include -# include "libft_types.h" +# include "libft_def.h" void ft_bzero(void *s, size_t n); void *ft_memset(void *s, int c, size_t n); diff --git a/include/libft_types.h b/include/libft_types.h deleted file mode 100644 index 3987a80..0000000 --- a/include/libft_types.h +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* libft_types.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/01/31 10:36:56 by cacharle #+# #+# */ -/* Updated: 2020/02/28 12:10:02 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LIBFT_TYPES_H -# define LIBFT_TYPES_H - -# define TRUE 1 -# define FALSE 0 - -typedef unsigned char t_ftbyte; -typedef int t_ftbool; -typedef unsigned int t_ftsize; - -typedef char t_ftchar; -typedef unsigned char t_ftuchar; -typedef int t_ftint; -typedef unsigned int t_ftuint; -typedef long int t_ftlong; -typedef unsigned long int t_ftulong; - -#endif -- cgit