diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-04-03 07:19:25 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-04-03 07:19:25 +0200 |
| commit | d2feec1f97e9f8f201e56ad33662bb663c328a0a (patch) | |
| tree | f97690082352bb1752d867d66f21a7bee1ef126c /include | |
| parent | 948c0953527fe3bef28904b38a16a9e4342e7e98 (diff) | |
| download | libft-d2feec1f97e9f8f201e56ad33662bb663c328a0a.tar.gz libft-d2feec1f97e9f8f201e56ad33662bb663c328a0a.tar.bz2 libft-d2feec1f97e9f8f201e56ad33662bb663c328a0a.zip | |
Changing hash table del function to regular one with a first order internal function, removing a few typedef to instead use standard types
Diffstat (limited to 'include')
| -rw-r--r-- | include/libft.h | 14 | ||||
| -rw-r--r-- | include/libft_algo.h | 11 | ||||
| -rw-r--r-- | include/libft_def.h (renamed from include/libft_types.h) | 14 | ||||
| -rw-r--r-- | include/libft_ht.h | 50 | ||||
| -rw-r--r-- | include/libft_lst.h | 2 | ||||
| -rw-r--r-- | include/libft_mem.h | 2 |
6 files changed, 47 insertions, 46 deletions
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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 <stdarg.h> # include <stdlib.h> # include <stddef.h> +# include <stdbool.h> # include <limits.h> # include <errno.h> -# include "libft_types.h" -# include "libft_ctype.h" -# include "libft_io.h" -# include "libft_mem.h" -# include "libft_str.h" - # ifdef __linux__ # include <stdio.h> # 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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 <stdlib.h> -# include <stddef.h> # 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_types.h b/include/libft_def.h index 3987a80..69a7655 100644 --- a/include/libft_types.h +++ b/include/libft_def.h @@ -1,17 +1,20 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* libft_types.h :+: :+: :+: */ +/* libft_def.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/31 10:36:56 by cacharle #+# #+# */ -/* Updated: 2020/02/28 12:10:02 by cacharle ### ########.fr */ +/* Updated: 2020/04/03 07:04:57 by charles ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef LIBFT_TYPES_H -# define LIBFT_TYPES_H +#ifndef LIBFT_DEF_H +# define LIBFT_DEF_H + +# include <stddef.h> +# include <stdbool.h> # define TRUE 1 # define FALSE 0 @@ -27,4 +30,7 @@ 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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 <stdlib.h> -# 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 <stddef.h> -# 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); |
