diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-08-02 11:05:33 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-08-02 11:05:33 +0200 |
| commit | 5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde (patch) | |
| tree | 80911dc3c32e9f230750e7e1042d413dfb6efab2 /include/libft_ht.h | |
| parent | ee32953ea79616e72f5428cdf40c834714a891c9 (diff) | |
| parent | b96b82194ccad2cddbb46b77aa1962a57c47ff44 (diff) | |
| download | libft-5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde.tar.gz libft-5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde.tar.bz2 libft-5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde.zip | |
Merge branch 'master' into ft_ssl
Diffstat (limited to 'include/libft_ht.h')
| -rw-r--r-- | include/libft_ht.h | 71 |
1 files changed, 42 insertions, 29 deletions
diff --git a/include/libft_ht.h b/include/libft_ht.h index 62f2ee1..c53ee4d 100644 --- a/include/libft_ht.h +++ b/include/libft_ht.h @@ -6,52 +6,65 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/31 10:36:09 by cacharle #+# #+# */ -/* Updated: 2020/02/19 02:38:28 by cacharle ### ########.fr */ +/* Updated: 2020/04/04 22:34:53 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef LIBFT_HT_H # define LIBFT_HT_H +/* +** \file libft_ht.h +** \brief Hash table manipulation +*/ + # include "libft.h" +# include "libft_def.h" # include "libft_lst.h" +# include "libft_mem.h" + +/* +** \brief Hash table entry, key/value pair +** \param key String key +** \param value Pointer to data +*/ -typedef struct s_ftht_content +typedef struct s_ftht_entry { - char *key; - void *value; -} t_ftht_content; + char *key; + void *value; +} t_ftht_entry; -typedef t_ftlst* t_ftht_entry; +/* +** \brief Hash table struct +** \param size Number of buckets +** \param buckets Bucket array, each bucket is a linked list +*/ -typedef struct s_ftht +typedef struct s_ftht { - t_ftsize size; - t_ftht_entry *entries; -} t_ftht; - -typedef t_ftuint t_ftht_digest; - -t_ftht_digest ft_hthash(t_ftht *ht, char *key); - -t_ftht *ft_htnew(t_ftsize size); -void ft_htdestroy(t_ftht *ht, void (*del)(t_ftht_content*)); -void ft_htdestroy_all(t_ftht *ht); -void ft_htdestroy_key(t_ftht *ht); -void *ft_htget(t_ftht *ht, char *key); -t_ftht_content *ft_htset(t_ftht *ht, char *key, void *value, - void (*del)(t_ftht_content*)); -void ft_htdelone(t_ftht *ht, char *key, - void (*del)(t_ftht_content*)); -void ft_htdelone_key(t_ftht *ht, char *key); -t_ftht_content *ft_htcontent_new(char *key, void *value); + size_t size; + t_ftlst **buckets; +} t_ftht; + +size_t ft_hthash(t_ftht *ht, char *key); + +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 */ -void ft_inter_htdelcontent_key(t_ftht_content *content); -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 |
