diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-03-04 12:49:31 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-03-04 12:49:31 +0100 |
| commit | 2a9133a87109f9430e4827a858ff86596c5f98d5 (patch) | |
| tree | dd345d9bafab86de2b2a9f7e07f83c5b7fc6df43 /src/ht/ft_htset.c | |
| parent | 915f1b888cf9c05e4b61321f84ac045eacd8ddd1 (diff) | |
| download | libft-2a9133a87109f9430e4827a858ff86596c5f98d5.tar.gz libft-2a9133a87109f9430e4827a858ff86596c5f98d5.tar.bz2 libft-2a9133a87109f9430e4827a858ff86596c5f98d5.zip | |
Added hash table documentation
Diffstat (limited to 'src/ht/ft_htset.c')
| -rw-r--r-- | src/ht/ft_htset.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/ht/ft_htset.c b/src/ht/ft_htset.c index 81aba97..0755889 100644 --- a/src/ht/ft_htset.c +++ b/src/ht/ft_htset.c @@ -13,6 +13,13 @@ #include "libft.h" #include "libft_ht.h" +/* +** Create/Update a entry in an hash table. +** If `key` already exist in `ht`, updates only the list element content. +** else create a new list node in addition the list content. +** Return a pointer to the created entry, NULL if an allocation failed. +*/ + t_ftht_content *ft_htset(t_ftht *ht, char *key, void *value, void (*del)(t_ftht_content*)) { @@ -30,14 +37,13 @@ t_ftht_content *ft_htset(t_ftht *ht, char *key, void *value, if (tmp != NULL) { if (del != NULL) - (*del)(tmp->content); + del(tmp->content); tmp->content = content; return ((t_ftht_content*)tmp->content); } - if ((entry = ft_lstnew(content)) == NULL) { - free(content); + del(content); return (NULL); } ft_lstadd_front(ht->entries + digest, entry); |
