From 8131a5d26441c5152ab151b4bb49b561e5ca6e81 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 31 Jan 2020 10:44:30 +0100 Subject: hash table unit testing, norming --- src/ht/ft_htdelone.c | 2 +- src/ht/ft_htdestroy.c | 4 ++-- src/ht/ft_htget.c | 2 +- src/ht/ft_htnew.c | 2 +- src/ht/ft_htset.c | 2 +- src/ht/ft_inter_htkey_cmp.c | 2 +- src/io/ft_next_line.c | 2 +- src/lst/ft_lstbsearch.c | 2 +- src/lst/ft_lstpop_front.c | 4 ++-- src/lst/ft_lstremove_if.c | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ht/ft_htdelone.c b/src/ht/ft_htdelone.c index 2c54721..77eae58 100644 --- a/src/ht/ft_htdelone.c +++ b/src/ht/ft_htdelone.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 09:27:18 by cacharle #+# #+# */ -/* Updated: 2020/02/19 02:35:06 by cacharle ### ########.fr */ +/* Updated: 2020/02/28 12:10:16 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/ht/ft_htdestroy.c b/src/ht/ft_htdestroy.c index e0442c6..900f76e 100644 --- a/src/ht/ft_htdestroy.c +++ b/src/ht/ft_htdestroy.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2020/01/30 08:19:06 by cacharle #+# #+# */ -/* Updated: 2020/01/30 08:33:09 by cacharle ### ########.fr */ +/* Created: 2020/01/30 08:31:02 by cacharle #+# #+# */ +/* Updated: 2020/02/28 12:10:31 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/ht/ft_htget.c b/src/ht/ft_htget.c index 76e4fb2..1562eb0 100644 --- a/src/ht/ft_htget.c +++ b/src/ht/ft_htget.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 08:33:21 by cacharle #+# #+# */ -/* Updated: 2020/02/19 01:44:41 by cacharle ### ########.fr */ +/* Updated: 2020/02/28 12:21:09 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/ht/ft_htnew.c b/src/ht/ft_htnew.c index d98a724..f77398f 100644 --- a/src/ht/ft_htnew.c +++ b/src/ht/ft_htnew.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 08:19:16 by cacharle #+# #+# */ -/* Updated: 2020/02/10 02:16:20 by cacharle ### ########.fr */ +/* Updated: 2020/02/28 12:10:51 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/ht/ft_htset.c b/src/ht/ft_htset.c index c7068d5..81aba97 100644 --- a/src/ht/ft_htset.c +++ b/src/ht/ft_htset.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 08:41:52 by cacharle #+# #+# */ -/* Updated: 2020/02/19 02:44:10 by cacharle ### ########.fr */ +/* Updated: 2020/02/28 12:11:00 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/ht/ft_inter_htkey_cmp.c b/src/ht/ft_inter_htkey_cmp.c index 6f04ecc..be2e52f 100644 --- a/src/ht/ft_inter_htkey_cmp.c +++ b/src/ht/ft_inter_htkey_cmp.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 09:24:39 by cacharle #+# #+# */ -/* Updated: 2020/02/19 02:03:14 by cacharle ### ########.fr */ +/* Updated: 2020/02/28 12:20:43 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/io/ft_next_line.c b/src/io/ft_next_line.c index 0f4cc2c..74afa71 100644 --- a/src/io/ft_next_line.c +++ b/src/io/ft_next_line.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/31 10:39:38 by cacharle #+# #+# */ -/* Updated: 2020/02/14 03:38:01 by cacharle ### ########.fr */ +/* Updated: 2020/02/28 12:11:35 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/lst/ft_lstbsearch.c b/src/lst/ft_lstbsearch.c index d694209..d3dc7e4 100644 --- a/src/lst/ft_lstbsearch.c +++ b/src/lst/ft_lstbsearch.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 09:17:51 by cacharle #+# #+# */ -/* Updated: 2020/02/17 03:03:21 by cacharle ### ########.fr */ +/* Updated: 2020/02/28 12:12:12 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/lst/ft_lstpop_front.c b/src/lst/ft_lstpop_front.c index ff386f9..5bf2c60 100644 --- a/src/lst/ft_lstpop_front.c +++ b/src/lst/ft_lstpop_front.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/25 03:32:51 by cacharle #+# #+# */ -/* Updated: 2020/01/15 12:46:28 by cacharle ### ########.fr */ +/* Created: 2020/01/30 08:29:58 by cacharle #+# #+# */ +/* Updated: 2020/02/28 12:12:47 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/lst/ft_lstremove_if.c b/src/lst/ft_lstremove_if.c index 5221ae4..03643fa 100644 --- a/src/lst/ft_lstremove_if.c +++ b/src/lst/ft_lstremove_if.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 09:36:49 by cacharle #+# #+# */ -/* Updated: 2020/02/19 02:06:22 by cacharle ### ########.fr */ +/* Updated: 2020/02/28 12:20:51 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -- cgit From 915f1b888cf9c05e4b61321f84ac045eacd8ddd1 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 27 Feb 2020 18:07:57 +0100 Subject: Added ft_lstlfind,ft_lstlsearch and ft_split_destroy --- src/ht/ft_htnew.c | 2 +- src/lst/ft_lstlfind.c | 4 ++-- src/lst/ft_lstlsearch.c | 4 ++-- src/util/ft_split_destroy.c | 24 ++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 src/util/ft_split_destroy.c (limited to 'src') diff --git a/src/ht/ft_htnew.c b/src/ht/ft_htnew.c index f77398f..6827c36 100644 --- a/src/ht/ft_htnew.c +++ b/src/ht/ft_htnew.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 08:19:16 by cacharle #+# #+# */ -/* Updated: 2020/02/28 12:10:51 by cacharle ### ########.fr */ +/* Updated: 2020/02/28 12:23:43 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/lst/ft_lstlfind.c b/src/lst/ft_lstlfind.c index 92d37d8..c399b6e 100644 --- a/src/lst/ft_lstlfind.c +++ b/src/lst/ft_lstlfind.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/17 03:04:52 by cacharle #+# #+# */ -/* Updated: 2020/02/19 02:03:11 by cacharle ### ########.fr */ +/* Created: 2020/02/27 18:00:37 by cacharle #+# #+# */ +/* Updated: 2020/02/28 12:24:05 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/lst/ft_lstlsearch.c b/src/lst/ft_lstlsearch.c index 8d2acc8..f59b5de 100644 --- a/src/lst/ft_lstlsearch.c +++ b/src/lst/ft_lstlsearch.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/17 02:57:12 by cacharle #+# #+# */ -/* Updated: 2020/02/17 03:35:45 by cacharle ### ########.fr */ +/* Created: 2020/02/27 16:18:33 by cacharle #+# #+# */ +/* Updated: 2020/02/28 12:24:31 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/util/ft_split_destroy.c b/src/util/ft_split_destroy.c new file mode 100644 index 0000000..bc3f4e6 --- /dev/null +++ b/src/util/ft_split_destroy.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split_destroy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/27 16:30:55 by cacharle #+# #+# */ +/* Updated: 2020/02/27 17:52:31 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_util.h" + +void *ft_split_destroy(char **strs) +{ + int i; + + i = -1; + while (strs[++i] != NULL) + free(strs[i]); + free(strs); + return (NULL); +} -- cgit From 2a9133a87109f9430e4827a858ff86596c5f98d5 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 4 Mar 2020 12:49:31 +0100 Subject: Added hash table documentation --- src/ht/ft_htcontent_new.c | 6 ++++++ src/ht/ft_htdelone.c | 4 ++++ src/ht/ft_htdestroy.c | 5 +++++ src/ht/ft_htget.c | 7 ++++++- src/ht/ft_hthash.c | 5 +++++ src/ht/ft_htnew.c | 6 ++++++ src/ht/ft_htset.c | 12 +++++++++--- src/ht/ft_inter_htkey_cmp.c | 4 ++++ 8 files changed, 45 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ht/ft_htcontent_new.c b/src/ht/ft_htcontent_new.c index 214e125..7dd4f20 100644 --- a/src/ht/ft_htcontent_new.c +++ b/src/ht/ft_htcontent_new.c @@ -13,6 +13,12 @@ #include "libft.h" #include "libft_ht.h" +/* +** Create a new hash table key/value pair. +** `key` is always duplicated. +** Return a pointer to the created content or NULL is an allocation failed. +*/ + t_ftht_content *ft_htcontent_new(char *key, void *value) { t_ftht_content *content; diff --git a/src/ht/ft_htdelone.c b/src/ht/ft_htdelone.c index 77eae58..e3bb355 100644 --- a/src/ht/ft_htdelone.c +++ b/src/ht/ft_htdelone.c @@ -13,6 +13,10 @@ #include "libft.h" #include "libft_ht.h" +/* +** Delete one hash table entry at `key`. +*/ + void ft_htdelone(t_ftht *ht, char *key, void (*del)(t_ftht_content*)) { ft_lstremove_if(ht->entries + ft_hthash(ht, key), diff --git a/src/ht/ft_htdestroy.c b/src/ht/ft_htdestroy.c index 900f76e..a788a78 100644 --- a/src/ht/ft_htdestroy.c +++ b/src/ht/ft_htdestroy.c @@ -13,6 +13,11 @@ #include "libft.h" #include "libft_ht.h" +/* +** Destroy an hash table. +** The `del` function is used to destroy each key/value pair +*/ + void ft_htdestroy(t_ftht *ht, void (*del)(t_ftht_content*)) { if (ht == NULL) diff --git a/src/ht/ft_htget.c b/src/ht/ft_htget.c index 1562eb0..94a4164 100644 --- a/src/ht/ft_htget.c +++ b/src/ht/ft_htget.c @@ -13,9 +13,14 @@ #include "libft.h" #include "libft_ht.h" +/* +** Retrieve a value with associated key. +** Returns NULL if there is no value at `key`. +*/ + void *ft_htget(t_ftht *ht, char *key) { - + t_ftht_digest digest; t_ftlst *found; diff --git a/src/ht/ft_hthash.c b/src/ht/ft_hthash.c index e7e696c..ba922e7 100644 --- a/src/ht/ft_hthash.c +++ b/src/ht/ft_hthash.c @@ -12,6 +12,11 @@ #include "libft_ht.h" +/* +** Hash a string according to the size of the hash table. +*/ + +// maybe use a less efficient but understandable function t_ftht_digest ft_hthash(t_ftht *ht, char *key) { t_ftht_digest digest; diff --git a/src/ht/ft_htnew.c b/src/ht/ft_htnew.c index 6827c36..465eabf 100644 --- a/src/ht/ft_htnew.c +++ b/src/ht/ft_htnew.c @@ -13,6 +13,12 @@ #include "libft.h" #include "libft_ht.h" +/* +** Create a new hash table. +** `size` is the size of the underlying array of linked list (buckets) +** Return NULL is an allocation failed. +*/ + t_ftht *ft_htnew(t_ftsize size) { t_ftht *ht; 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); diff --git a/src/ht/ft_inter_htkey_cmp.c b/src/ht/ft_inter_htkey_cmp.c index be2e52f..397177e 100644 --- a/src/ht/ft_inter_htkey_cmp.c +++ b/src/ht/ft_inter_htkey_cmp.c @@ -13,6 +13,10 @@ #include "libft.h" #include "libft_ht.h" +/* +** Hash table internal function to compare key string in linked list. +*/ + int ft_inter_htkey_cmp(const void *ref_key, const void *content) { if (ref_key == NULL || content == NULL) -- cgit From e792d0a3ff1c1da456c241530571263df0b887b5 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 4 Mar 2020 16:19:05 +0100 Subject: Added ft_htiter.c --- src/ht/ft_htiter.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/ht/ft_htiter.c (limited to 'src') diff --git a/src/ht/ft_htiter.c b/src/ht/ft_htiter.c new file mode 100644 index 0000000..5473412 --- /dev/null +++ b/src/ht/ft_htiter.c @@ -0,0 +1,17 @@ +#include "libft_ht.h" + +/* +** Iterate function `f` over every pair in `ht`. +*/ + +void ft_htiter(t_ftht *ht, void (*f)(t_ftht_content*)) +{ + size_t i; + + i = 0; + while (i < ht->size) + { + ft_lstiter(ht->entries[i], (void (*)(void*))f); + i++; + } +} -- cgit From 8bba48a8326d9e7a703c3f6f6ab70b8a8a393473 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 28 Mar 2020 12:07:44 +0100 Subject: Added ft_strjoin3 --- src/str/ft_strjoin3.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/str/ft_strjoin3.c (limited to 'src') diff --git a/src/str/ft_strjoin3.c b/src/str/ft_strjoin3.c new file mode 100644 index 0000000..69de060 --- /dev/null +++ b/src/str/ft_strjoin3.c @@ -0,0 +1,16 @@ +#include "libft.h" + +char *ft_strjoin3(char const *s1, char const *s2, char const *s3) +{ + char *joined; + + if (s1 == NULL || s2 == NULL || s3 == NULL) + return (NULL); + if ((joined = (char*)malloc(sizeof(char) + * (ft_strlen(s1) + ft_strlen(s2) + ft_strlen(s3) + 1))) == NULL) + return (NULL); + ft_strcpy(joined, s1); + ft_strcat(joined, s2); + ft_strcat(joined, s3); + return (joined); +} -- cgit From 40ed37c023627726a5c9c6928284e9f042dc0fa4 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 30 Mar 2020 16:38:30 +0200 Subject: Added Doxygen config file --- src/str/ft_atoi.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/str/ft_atoi.c b/src/str/ft_atoi.c index fa31407..1b9bfc4 100644 --- a/src/str/ft_atoi.c +++ b/src/str/ft_atoi.c @@ -12,6 +12,10 @@ #include "libft.h" +/** +** Convert a string to an int +*/ + int ft_atoi(const char *str) { return ((int)ft_strtol(str, (char**)NULL, 10)); -- cgit From 901402c99018422c994bdb297e3ba404969c88ea Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 30 Mar 2020 22:26:36 +0200 Subject: Added documentation for ht and lst --- src/ht/ft_htcontent_new.c | 37 ------------------------------------- src/ht/ft_htdelone.c | 12 ++++++++---- src/ht/ft_htdestroy.c | 13 +++++++------ src/ht/ft_htentry_new.c | 37 +++++++++++++++++++++++++++++++++++++ src/ht/ft_htget.c | 12 +++++++----- src/ht/ft_hthash.c | 7 +++++-- src/ht/ft_htiter.c | 10 ++++++---- src/ht/ft_htnew.c | 12 ++++++------ src/ht/ft_htset.c | 36 ++++++++++++++++++++---------------- src/ht/ft_inter_htkey_cmp.c | 2 +- src/io/ft_printf/internals/list.c | 4 ++-- src/io/ft_printf/internals/parse.c | 2 +- src/lst/ft_lstadd_back.c | 26 -------------------------- src/lst/ft_lstadd_front.c | 22 ---------------------- src/lst/ft_lstbsearch.c | 4 ++-- src/lst/ft_lstclear.c | 25 ------------------------- src/lst/ft_lstdelone.c | 10 +++++++--- src/lst/ft_lstdestroy.c | 29 +++++++++++++++++++++++++++++ src/lst/ft_lstiter.c | 10 +++++++--- src/lst/ft_lstlast.c | 8 ++++++-- src/lst/ft_lstlfind.c | 2 +- src/lst/ft_lstlsearch.c | 2 +- src/lst/ft_lstmap.c | 21 ++++++++++++++------- src/lst/ft_lstnew.c | 12 ++++++++---- src/lst/ft_lstpop_front.c | 6 +++++- src/lst/ft_lstpush_back.c | 30 ++++++++++++++++++++++++++++++ src/lst/ft_lstpush_front.c | 26 ++++++++++++++++++++++++++ src/lst/ft_lstremove_if.c | 10 ++++++++-- src/lst/ft_lstreverse.c | 5 ++++- src/lst/ft_lstreverse_ret.c | 6 +++++- src/lst/ft_lstsize.c | 8 ++++++-- src/lst/ft_lstsort.c | 6 ++++++ src/lst/ft_lstsorted_merge.c | 10 +++++++++- 33 files changed, 274 insertions(+), 188 deletions(-) delete mode 100644 src/ht/ft_htcontent_new.c create mode 100644 src/ht/ft_htentry_new.c delete mode 100644 src/lst/ft_lstadd_back.c delete mode 100644 src/lst/ft_lstadd_front.c delete mode 100644 src/lst/ft_lstclear.c create mode 100644 src/lst/ft_lstdestroy.c create mode 100644 src/lst/ft_lstpush_back.c create mode 100644 src/lst/ft_lstpush_front.c (limited to 'src') diff --git a/src/ht/ft_htcontent_new.c b/src/ht/ft_htcontent_new.c deleted file mode 100644 index 7dd4f20..0000000 --- a/src/ht/ft_htcontent_new.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_htcontent_new.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/01/30 08:45:36 by cacharle #+# #+# */ -/* Updated: 2020/02/17 04:09:50 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" -#include "libft_ht.h" - -/* -** Create a new hash table key/value pair. -** `key` is always duplicated. -** Return a pointer to the created content or NULL is an allocation failed. -*/ - -t_ftht_content *ft_htcontent_new(char *key, void *value) -{ - t_ftht_content *content; - - if (key == NULL) - return (NULL); - if ((content = (t_ftht_content*)malloc(sizeof(t_ftht_content))) == NULL) - return (NULL); - if ((content->key = ft_strdup(key)) == NULL) - { - free(content); - return (NULL); - } - content->value = value; - return (content); -} diff --git a/src/ht/ft_htdelone.c b/src/ht/ft_htdelone.c index e3bb355..3672b23 100644 --- a/src/ht/ft_htdelone.c +++ b/src/ht/ft_htdelone.c @@ -13,13 +13,17 @@ #include "libft.h" #include "libft_ht.h" -/* -** Delete one hash table entry at `key`. +/** +** \brief Delete one hash table entry +** \param key Key of entry to delete +** \param del Function to destroy the entry +** \warning The del function HAS to free the key +** \note Do nothing if their is to entry which correspond to key */ -void ft_htdelone(t_ftht *ht, char *key, void (*del)(t_ftht_content*)) +void ft_htdelone(t_ftht *ht, char *key, void (*del)(t_ftht_entry*)) { - ft_lstremove_if(ht->entries + ft_hthash(ht, key), + ft_lstremove_if(ht->buckets + ft_hthash(ht, key), ft_inter_htkey_cmp, key, (void (*)(void*))del); } diff --git a/src/ht/ft_htdestroy.c b/src/ht/ft_htdestroy.c index a788a78..ef4b257 100644 --- a/src/ht/ft_htdestroy.c +++ b/src/ht/ft_htdestroy.c @@ -13,17 +13,18 @@ #include "libft.h" #include "libft_ht.h" -/* -** Destroy an hash table. -** The `del` function is used to destroy each key/value pair +/** +** \brief Destroy an hash table. +** \param del Function to delete each entry +** \warning The del function HAS to free the key */ -void ft_htdestroy(t_ftht *ht, void (*del)(t_ftht_content*)) +void ft_htdestroy(t_ftht *ht, void (*del)(t_ftht_entry*)) { if (ht == NULL) return ; while (ht->size-- > 0) - ft_lstclear(ht->entries + ht->size, (void (*)(void*))del); - free(ht->entries); + ft_lstdestroy(ht->buckets + ht->size, (void (*)(void*))del); + free(ht->buckets); free(ht); } diff --git a/src/ht/ft_htentry_new.c b/src/ht/ft_htentry_new.c new file mode 100644 index 0000000..03c0980 --- /dev/null +++ b/src/ht/ft_htentry_new.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htentry_new.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 08:45:36 by cacharle #+# #+# */ +/* Updated: 2020/02/17 04:09:50 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_ht.h" + +/** +** \brief Create a new hash table key/value pair. +** \param key Hash entry string key (always duplicated) +** \return Content or NULL if an allocation failed. +*/ + +t_ftht_entry *ft_htentry_new(char *key, void *value) +{ + t_ftht_entry *content; + + if (key == NULL) + return (NULL); + if ((content = (t_ftht_entry*)malloc(sizeof(t_ftht_entry))) == NULL) + return (NULL); + if ((content->key = ft_strdup(key)) == NULL) + { + free(content); + return (NULL); + } + content->value = value; + return (content); +} diff --git a/src/ht/ft_htget.c b/src/ht/ft_htget.c index 94a4164..6b5df48 100644 --- a/src/ht/ft_htget.c +++ b/src/ht/ft_htget.c @@ -13,9 +13,11 @@ #include "libft.h" #include "libft_ht.h" -/* -** Retrieve a value with associated key. -** Returns NULL if there is no value at `key`. +/** +** \brief Retrieve a value with a key +** \param ht Hash table where key is searched +** \param key Searched key +** \return Value void pointer at key or NULL if not found */ void *ft_htget(t_ftht *ht, char *key) @@ -27,8 +29,8 @@ void *ft_htget(t_ftht *ht, char *key) if (ht == NULL || key == NULL) return (NULL); digest = ft_hthash(ht, key); - found = ft_lstlfind(ht->entries[digest], ft_inter_htkey_cmp, key); + found = ft_lstlfind(ht->buckets[digest], ft_inter_htkey_cmp, key); if (found == NULL) return (NULL); - return (((t_ftht_content*)found->content)->value); + return (((t_ftht_entry*)found->data)->value); } diff --git a/src/ht/ft_hthash.c b/src/ht/ft_hthash.c index ba922e7..2670e31 100644 --- a/src/ht/ft_hthash.c +++ b/src/ht/ft_hthash.c @@ -12,8 +12,11 @@ #include "libft_ht.h" -/* -** Hash a string according to the size of the hash table. +/** +** \brief Hash a string +** \param ht So that the index is in the hash table bound +** \param key String to hash +** \return Hash */ // maybe use a less efficient but understandable function diff --git a/src/ht/ft_htiter.c b/src/ht/ft_htiter.c index 5473412..e5ab2eb 100644 --- a/src/ht/ft_htiter.c +++ b/src/ht/ft_htiter.c @@ -1,17 +1,19 @@ #include "libft_ht.h" -/* -** Iterate function `f` over every pair in `ht`. +/** +** \brief Iterate over entry of hash table +** \param ht Iterated hash table +** \param f Function applied to each entry */ -void ft_htiter(t_ftht *ht, void (*f)(t_ftht_content*)) +void ft_htiter(t_ftht *ht, void (*f)(t_ftht_entry*)) { size_t i; i = 0; while (i < ht->size) { - ft_lstiter(ht->entries[i], (void (*)(void*))f); + ft_lstiter(ht->buckets[i], (void (*)(void*))f); i++; } } diff --git a/src/ht/ft_htnew.c b/src/ht/ft_htnew.c index 465eabf..e28b544 100644 --- a/src/ht/ft_htnew.c +++ b/src/ht/ft_htnew.c @@ -13,10 +13,10 @@ #include "libft.h" #include "libft_ht.h" -/* -** Create a new hash table. -** `size` is the size of the underlying array of linked list (buckets) -** Return NULL is an allocation failed. +/** +** \brief Create a new hash table. +** \param size Size of the underlying array of linked list (buckets) +** \return Created hash table or NULL is an allocation failed */ t_ftht *ft_htnew(t_ftsize size) @@ -27,8 +27,8 @@ t_ftht *ft_htnew(t_ftsize size) return (NULL); if ((ht = (t_ftht*)malloc(sizeof(t_ftht))) == NULL) return (NULL); - ht->entries = (t_ftht_entry*)ft_calloc(size, sizeof(t_ftht_entry)); - if (ht->entries == NULL) + ht->buckets = (t_ftht_bucket*)ft_calloc(size, sizeof(t_ftht_entry)); + if (ht->buckets == NULL) { free(ht); return (NULL); diff --git a/src/ht/ft_htset.c b/src/ht/ft_htset.c index 0755889..9738c14 100644 --- a/src/ht/ft_htset.c +++ b/src/ht/ft_htset.c @@ -13,39 +13,43 @@ #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. +/** +** \brief Create/Update a entry in hash table. +** \note If `key` already exist in `ht`, only updates the list node content. +** Else create a new list node in addition the list content. +** \param ht Hash table where the entry is modified +** \param key Key of the new entry +** \param value Value of the new entry +** \param del Destroy function in case the entry is modified. +** \return 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*)) +t_ftht_entry *ft_htset(t_ftht *ht, char *key, void *value, + void (*del)(t_ftht_entry*)) { t_ftht_digest digest; - t_ftht_content *content; - t_ftht_entry entry; + t_ftht_entry *content; + t_ftht_bucket bucket; t_ftlst *tmp; if (ht == NULL || key == NULL) return (NULL); - if ((content = ft_htcontent_new(key, value)) == NULL) + if ((content = ft_htentry_new(key, value)) == NULL) return (NULL); digest = ft_hthash(ht, key); - tmp = ft_lstlfind(ht->entries[digest], ft_inter_htkey_cmp, key); + tmp = ft_lstlfind(ht->buckets[digest], ft_inter_htkey_cmp, key); if (tmp != NULL) { if (del != NULL) - del(tmp->content); - tmp->content = content; - return ((t_ftht_content*)tmp->content); + del(tmp->data); + tmp->data = content; + return ((t_ftht_entry*)tmp->data); } - if ((entry = ft_lstnew(content)) == NULL) + if ((bucket = ft_lstnew(content)) == NULL) { del(content); return (NULL); } - ft_lstadd_front(ht->entries + digest, entry); + ft_lstpush_front(ht->buckets + digest, bucket); return (content); } diff --git a/src/ht/ft_inter_htkey_cmp.c b/src/ht/ft_inter_htkey_cmp.c index 397177e..e8a0375 100644 --- a/src/ht/ft_inter_htkey_cmp.c +++ b/src/ht/ft_inter_htkey_cmp.c @@ -21,5 +21,5 @@ int ft_inter_htkey_cmp(const void *ref_key, const void *content) { if (ref_key == NULL || content == NULL) return (-1); - return (ft_strcmp((char*)ref_key, ((t_ftht_content*)content)->key)); + return (ft_strcmp((char*)ref_key, ((t_ftht_entry*)content)->key)); } diff --git a/src/io/ft_printf/internals/list.c b/src/io/ft_printf/internals/list.c index 99491f4..37f8013 100644 --- a/src/io/ft_printf/internals/list.c +++ b/src/io/ft_printf/internals/list.c @@ -18,7 +18,7 @@ t_flist *list_new(t_pformat *content) if ((lst = (t_flist*)malloc(sizeof(t_flist))) == NULL) return (NULL); - lst->content = content; + lst->data = content; lst->next = NULL; return (lst); } @@ -47,7 +47,7 @@ void list_pop_front(t_flist **lst) if (lst == NULL || *lst == NULL) return ; tmp = (*lst)->next; - free((*lst)->content); + free((*lst)->data); free(*lst); *lst = tmp; } diff --git a/src/io/ft_printf/internals/parse.c b/src/io/ft_printf/internals/parse.c index 33928a0..4650481 100644 --- a/src/io/ft_printf/internals/parse.c +++ b/src/io/ft_printf/internals/parse.c @@ -28,7 +28,7 @@ int parse(const char *format, t_flist **flist) if ((tmp = list_new(parsed)) == NULL) return ((int)list_destroy(flist)); list_push_front(flist, tmp); - format += (*flist)->content->fmt_len; + format += (*flist)->data->fmt_len; } *flist = list_reverse(*flist); return (1); diff --git a/src/lst/ft_lstadd_back.c b/src/lst/ft_lstadd_back.c deleted file mode 100644 index 8f39a75..0000000 --- a/src/lst/ft_lstadd_back.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd_back_bonus.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/09 09:02:03 by cacharle #+# #+# */ -/* Updated: 2019/11/20 04:01:26 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" -#include "libft_lst.h" - -void ft_lstadd_back(t_ftlst **alst, t_ftlst *new) -{ - if (alst == NULL) - return ; - if (*alst == NULL) - { - *alst = new; - return ; - } - ft_lstlast(*alst)->next = new; -} diff --git a/src/lst/ft_lstadd_front.c b/src/lst/ft_lstadd_front.c deleted file mode 100644 index bcd5ad9..0000000 --- a/src/lst/ft_lstadd_front.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd_front_bonus.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/09 09:02:25 by cacharle #+# #+# */ -/* Updated: 2019/10/18 12:16:06 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" -#include "libft_lst.h" - -void ft_lstadd_front(t_ftlst **alst, t_ftlst *new) -{ - if (alst == NULL || new == NULL) - return ; - new->next = *alst; - *alst = new; -} diff --git a/src/lst/ft_lstbsearch.c b/src/lst/ft_lstbsearch.c index d3dc7e4..0c48eb0 100644 --- a/src/lst/ft_lstbsearch.c +++ b/src/lst/ft_lstbsearch.c @@ -46,11 +46,11 @@ static t_ftlst *st_lstbsearch_rec(t_ftlst *lst, t_ftlst *last, return (NULL); if (mid->next == NULL) { - if (cmp(ref, mid->content) == 0) + if (cmp(ref, mid->data) == 0) return (mid); return (NULL); } - res = cmp(ref, mid->next->content); + res = cmp(ref, mid->next->data); if (res < 0) return (st_lstbsearch_rec(lst, mid, cmp, ref)); else if (res > 0) diff --git a/src/lst/ft_lstclear.c b/src/lst/ft_lstclear.c deleted file mode 100644 index 0bacb4f..0000000 --- a/src/lst/ft_lstclear.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstclear_bonus.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/09 09:02:39 by cacharle #+# #+# */ -/* Updated: 2019/11/20 04:02:37 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" -#include "libft_lst.h" - -void ft_lstclear(t_ftlst **lst, void (*del)(void *)) -{ - if (lst == NULL) - return ; - if (*lst == NULL) - return ; - ft_lstclear(&((*lst)->next), del); - ft_lstdelone(*lst, del); - *lst = NULL; -} diff --git a/src/lst/ft_lstdelone.c b/src/lst/ft_lstdelone.c index 63dcc35..40e25cd 100644 --- a/src/lst/ft_lstdelone.c +++ b/src/lst/ft_lstdelone.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstdelone_bonus.c :+: :+: :+: */ +/* ft_lstdelone.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,14 +10,18 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Delete list node +** \param del Delete function for node's data +*/ + void ft_lstdelone(t_ftlst *lst, void (*del)(void *)) { if (lst == NULL) return ; if (del != NULL) - (*del)(lst->content); + (*del)(lst->data); free(lst); } diff --git a/src/lst/ft_lstdestroy.c b/src/lst/ft_lstdestroy.c new file mode 100644 index 0000000..5e55f04 --- /dev/null +++ b/src/lst/ft_lstdestroy.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdestroy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:02:39 by cacharle #+# #+# */ +/* Updated: 2019/11/20 04:02:37 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_lst.h" + +/** +** \brief Destroy a list and set his pointer to NULL +** \param del Delete Function for data of each node +*/ + +void ft_lstdestroy(t_ftlst **lst, void (*del)(void *)) +{ + if (lst == NULL) + return ; + if (*lst == NULL) + return ; + ft_lstdestroy(&((*lst)->next), del); + ft_lstdelone(*lst, del); + *lst = NULL; +} diff --git a/src/lst/ft_lstiter.c b/src/lst/ft_lstiter.c index 9b2895b..39d870b 100644 --- a/src/lst/ft_lstiter.c +++ b/src/lst/ft_lstiter.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstiter_bonus.c :+: :+: :+: */ +/* ft_lstiter.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,16 +10,20 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Iterate of list +** \param f Funtion applied to data of each node +*/ + void ft_lstiter(t_ftlst *lst, void (*f)(void *)) { if (f == NULL) return ; while (lst != NULL) { - (*f)(lst->content); + (*f)(lst->data); lst = lst->next; } } diff --git a/src/lst/ft_lstlast.c b/src/lst/ft_lstlast.c index 728cbf2..12fdeee 100644 --- a/src/lst/ft_lstlast.c +++ b/src/lst/ft_lstlast.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstlast_bonus.c :+: :+: :+: */ +/* ft_lstlast.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,9 +10,13 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Last node +** \return List's last node +*/ + t_ftlst *ft_lstlast(t_ftlst *lst) { if (lst == NULL) diff --git a/src/lst/ft_lstlfind.c b/src/lst/ft_lstlfind.c index c399b6e..fd7e688 100644 --- a/src/lst/ft_lstlfind.c +++ b/src/lst/ft_lstlfind.c @@ -16,7 +16,7 @@ t_ftlst *ft_lstlfind(t_ftlst *lst, t_ftcompar_func cmp, const void *ref) { if (lst == NULL) return (NULL); - if (cmp(ref, lst->content) == 0) + if (cmp(ref, lst->data) == 0) return (lst); return (ft_lstlfind(lst->next, cmp, ref)); } diff --git a/src/lst/ft_lstlsearch.c b/src/lst/ft_lstlsearch.c index f59b5de..11c528c 100644 --- a/src/lst/ft_lstlsearch.c +++ b/src/lst/ft_lstlsearch.c @@ -16,7 +16,7 @@ t_ftlst *ft_lstlsearch(t_ftlst *lst, t_ftcompar_func cmp, const void *ref) { if (lst == NULL) return (ft_lstnew(ref)); - if (cmp(ref, lst->content) == 0) + if (cmp(ref, lst->data) == 0) return (lst); if (lst->next == NULL) { diff --git a/src/lst/ft_lstmap.c b/src/lst/ft_lstmap.c index dda15de..bf96892 100644 --- a/src/lst/ft_lstmap.c +++ b/src/lst/ft_lstmap.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstmap_bonus.c :+: :+: :+: */ +/* ft_lstmap.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,9 +10,16 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Clone a list and map a function to each node data +** \param lst Origin list +** \param f Function applied to each node's data +** \param del Delete function for cleanning up in case of failed allocation +** \return Mapped clone list +*/ + t_ftlst *ft_lstmap(t_ftlst *lst, void *(*f)(void *), void (*del)(void *)) { t_ftlst *mapped; @@ -23,12 +30,12 @@ t_ftlst *ft_lstmap(t_ftlst *lst, void *(*f)(void *), void (*del)(void *)) mapped = NULL; while (lst != NULL) { - if ((tmp = ft_lstnew((*f)(lst->content))) == NULL) + if ((tmp = ft_lstnew((*f)(lst->data))) == NULL) { - ft_lstclear(&mapped, del); + ft_lstdestroy(&mapped, del); return (NULL); } - ft_lstadd_back(&mapped, tmp); + ft_lstpush_back(&mapped, tmp); lst = lst->next; } return (mapped); @@ -41,9 +48,9 @@ t_ftlst *ft_lstmap(t_ftlst *lst, void *(*f)(void *), void (*del)(void *)) ** ** if (lst == NULL) ** return (NULL); -** if ((tmp = ft_lstnew(lst->content)) == NULL) +** if ((tmp = ft_lstnew(lst->data)) == NULL) ** return (NULL); -** tmp->content = (*f)(tmp->content); +** tmp->data = (*f)(tmp->data); ** tmp->next = ft_lstmap(lst->next, f); ** return (tmp); */ diff --git a/src/lst/ft_lstnew.c b/src/lst/ft_lstnew.c index 11cf223..41c8153 100644 --- a/src/lst/ft_lstnew.c +++ b/src/lst/ft_lstnew.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstnew_bonus.c :+: :+: :+: */ +/* ft_lstnew.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,16 +10,20 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" -t_ftlst *ft_lstnew(void const *content) +/** +** \brief Create a list node +** \param data Pointer to data of node +*/ + +t_ftlst *ft_lstnew(void const *data) { t_ftlst *elem; if ((elem = (t_ftlst*)malloc(sizeof(t_ftlst))) == NULL) return (NULL); - elem->content = (void*)content; + elem->data = (void*)data; elem->next = NULL; return (elem); } diff --git a/src/lst/ft_lstpop_front.c b/src/lst/ft_lstpop_front.c index 5bf2c60..798bf83 100644 --- a/src/lst/ft_lstpop_front.c +++ b/src/lst/ft_lstpop_front.c @@ -10,9 +10,13 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Delete head node and replace it with next node +** \param del Delete function for node data +*/ + void ft_lstpop_front(t_ftlst **lst, void (*del)(void *)) { t_ftlst *tmp; diff --git a/src/lst/ft_lstpush_back.c b/src/lst/ft_lstpush_back.c new file mode 100644 index 0000000..372c18c --- /dev/null +++ b/src/lst/ft_lstpush_back.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstpush_back.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:02:03 by cacharle #+# #+# */ +/* Updated: 2019/11/20 04:01:26 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_lst.h" + +/** +** \brief Push new node to the list end +** \param new Pushed node +*/ + +void ft_lstpush_back(t_ftlst **alst, t_ftlst *new) +{ + if (alst == NULL) + return ; + if (*alst == NULL) + { + *alst = new; + return ; + } + ft_lstlast(*alst)->next = new; +} diff --git a/src/lst/ft_lstpush_front.c b/src/lst/ft_lstpush_front.c new file mode 100644 index 0000000..c17a586 --- /dev/null +++ b/src/lst/ft_lstpush_front.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstpush_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:02:25 by cacharle #+# #+# */ +/* Updated: 2019/10/18 12:16:06 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_lst.h" + +/** +** \brief Push node to list front +** \param new Pushed node +*/ + +void ft_lstpush_front(t_ftlst **alst, t_ftlst *new) +{ + if (alst == NULL || new == NULL) + return ; + new->next = *alst; + *alst = new; +} diff --git a/src/lst/ft_lstremove_if.c b/src/lst/ft_lstremove_if.c index 03643fa..fdac710 100644 --- a/src/lst/ft_lstremove_if.c +++ b/src/lst/ft_lstremove_if.c @@ -10,9 +10,15 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Remove node on some condition +** \param cmp Comparison function, return 0 if equal +** \param ref Reference data passed has the first arg of `cmp` +** \param del Delete function to free removed node data +*/ + void ft_lstremove_if(t_ftlst **lst, t_ftcompar_func cmp, const void *ref, t_ftdel_func del) { @@ -20,7 +26,7 @@ void ft_lstremove_if(t_ftlst **lst, t_ftcompar_func cmp, if (lst == NULL || *lst == NULL) return ; - if (cmp(ref, (*lst)->content) == 0) + if (cmp(ref, (*lst)->data) == 0) { saved_next = (*lst)->next; ft_lstdelone(*lst, del); diff --git a/src/lst/ft_lstreverse.c b/src/lst/ft_lstreverse.c index 61c9daf..fd5259b 100644 --- a/src/lst/ft_lstreverse.c +++ b/src/lst/ft_lstreverse.c @@ -10,9 +10,12 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Reverse a list +*/ + void ft_lstreverse(t_ftlst **lst) { *lst = ft_lstreverse_ret(*lst); diff --git a/src/lst/ft_lstreverse_ret.c b/src/lst/ft_lstreverse_ret.c index c115ac5..259af9e 100644 --- a/src/lst/ft_lstreverse_ret.c +++ b/src/lst/ft_lstreverse_ret.c @@ -10,9 +10,13 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief Reverse list +** \return Pointer to reversed list +*/ + t_ftlst *ft_lstreverse_ret(t_ftlst *lst) { t_ftlst *tmp; diff --git a/src/lst/ft_lstsize.c b/src/lst/ft_lstsize.c index 922b581..6a92b99 100644 --- a/src/lst/ft_lstsize.c +++ b/src/lst/ft_lstsize.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstsize_bonus.c :+: :+: :+: */ +/* ft_lstsize.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,9 +10,13 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" +/** +** \brief List size +** \return Number of node in list +*/ + int ft_lstsize(t_ftlst *lst) { int counter; diff --git a/src/lst/ft_lstsort.c b/src/lst/ft_lstsort.c index e1c9913..fbd046a 100644 --- a/src/lst/ft_lstsort.c +++ b/src/lst/ft_lstsort.c @@ -12,6 +12,12 @@ #include "libft_lst.h" +/** +** \brief Sort list +** \param cmp Comparison function, <0 if less, 0 if equal, >0 if greater +** \note Use merge sort algorithm +*/ + void ft_lstsort(t_ftlst **begin_list, t_ftcompar_func cmp) { t_ftlst *fast; diff --git a/src/lst/ft_lstsorted_merge.c b/src/lst/ft_lstsorted_merge.c index 4f5332c..0cd5721 100644 --- a/src/lst/ft_lstsorted_merge.c +++ b/src/lst/ft_lstsorted_merge.c @@ -12,6 +12,14 @@ #include "libft_lst.h" +/** +** \brief Merge sorted lists, the new list is also sorted +** \param l1 First list +** \param l2 Second list +** \param cmp Comparison function, <0 if less, 0 if equal, >0 if greater +** \return Pointer to first node of merged list +*/ + t_ftlst *ft_lstsorted_merge(t_ftlst *l1, t_ftlst *l2, t_ftcompar_func cmp) { t_ftlst *merged; @@ -21,7 +29,7 @@ t_ftlst *ft_lstsorted_merge(t_ftlst *l1, t_ftlst *l2, t_ftcompar_func cmp) return (l2); if (l2 == NULL) return (l1); - if (cmp(l1->content, l2->content) < 0) + if (cmp(l1->data, l2->data) < 0) { merged = l1; merged->next = ft_lstsorted_merge(l1->next, l2, cmp); -- cgit From 9316f2063255bd4a0abd5c38d4c065969a8980bb Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 1 Apr 2020 18:10:36 +0200 Subject: Norm compliant comment format, dirty script for doxygen comments --- src/ht/ft_htdelone.c | 2 +- src/ht/ft_htdestroy.c | 2 +- src/ht/ft_htentry_new.c | 2 +- src/ht/ft_htget.c | 5 ++--- src/ht/ft_hthash.c | 2 +- src/ht/ft_htiter.c | 14 +++++++++++++- src/ht/ft_htnew.c | 2 +- src/ht/ft_htset.c | 7 ++++--- src/lst/ft_lstdelone.c | 2 +- src/lst/ft_lstdestroy.c | 2 +- src/lst/ft_lstiter.c | 2 +- src/lst/ft_lstlast.c | 2 +- src/lst/ft_lstmap.c | 2 +- src/lst/ft_lstnew.c | 2 +- src/lst/ft_lstpop_front.c | 2 +- src/lst/ft_lstpush_back.c | 2 +- src/lst/ft_lstpush_front.c | 2 +- src/lst/ft_lstremove_if.c | 2 +- src/lst/ft_lstreverse.c | 2 +- src/lst/ft_lstreverse_ret.c | 2 +- src/lst/ft_lstsize.c | 2 +- src/lst/ft_lstsort.c | 2 +- src/lst/ft_lstsorted_merge.c | 2 +- src/str/ft_atoi.c | 2 +- src/str/ft_strjoin3.c | 20 ++++++++++++++++++++ 25 files changed, 60 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/ht/ft_htdelone.c b/src/ht/ft_htdelone.c index 3672b23..7374a44 100644 --- a/src/ht/ft_htdelone.c +++ b/src/ht/ft_htdelone.c @@ -13,7 +13,7 @@ #include "libft.h" #include "libft_ht.h" -/** +/* ** \brief Delete one hash table entry ** \param key Key of entry to delete ** \param del Function to destroy the entry diff --git a/src/ht/ft_htdestroy.c b/src/ht/ft_htdestroy.c index ef4b257..ff362d2 100644 --- a/src/ht/ft_htdestroy.c +++ b/src/ht/ft_htdestroy.c @@ -13,7 +13,7 @@ #include "libft.h" #include "libft_ht.h" -/** +/* ** \brief Destroy an hash table. ** \param del Function to delete each entry ** \warning The del function HAS to free the key diff --git a/src/ht/ft_htentry_new.c b/src/ht/ft_htentry_new.c index 03c0980..12a1159 100644 --- a/src/ht/ft_htentry_new.c +++ b/src/ht/ft_htentry_new.c @@ -13,7 +13,7 @@ #include "libft.h" #include "libft_ht.h" -/** +/* ** \brief Create a new hash table key/value pair. ** \param key Hash entry string key (always duplicated) ** \return Content or NULL if an allocation failed. diff --git a/src/ht/ft_htget.c b/src/ht/ft_htget.c index 6b5df48..a6383fe 100644 --- a/src/ht/ft_htget.c +++ b/src/ht/ft_htget.c @@ -6,14 +6,14 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 08:33:21 by cacharle #+# #+# */ -/* Updated: 2020/02/28 12:21:09 by cacharle ### ########.fr */ +/* Updated: 2020/04/01 18:02:57 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" #include "libft_ht.h" -/** +/* ** \brief Retrieve a value with a key ** \param ht Hash table where key is searched ** \param key Searched key @@ -22,7 +22,6 @@ void *ft_htget(t_ftht *ht, char *key) { - t_ftht_digest digest; t_ftlst *found; diff --git a/src/ht/ft_hthash.c b/src/ht/ft_hthash.c index 2670e31..3369d24 100644 --- a/src/ht/ft_hthash.c +++ b/src/ht/ft_hthash.c @@ -12,7 +12,7 @@ #include "libft_ht.h" -/** +/* ** \brief Hash a string ** \param ht So that the index is in the hash table bound ** \param key String to hash diff --git a/src/ht/ft_htiter.c b/src/ht/ft_htiter.c index e5ab2eb..b854993 100644 --- a/src/ht/ft_htiter.c +++ b/src/ht/ft_htiter.c @@ -1,6 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/01 18:02:24 by charles #+# #+# */ +/* Updated: 2020/04/01 18:02:32 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft_ht.h" -/** +/* ** \brief Iterate over entry of hash table ** \param ht Iterated hash table ** \param f Function applied to each entry diff --git a/src/ht/ft_htnew.c b/src/ht/ft_htnew.c index e28b544..e5335d2 100644 --- a/src/ht/ft_htnew.c +++ b/src/ht/ft_htnew.c @@ -13,7 +13,7 @@ #include "libft.h" #include "libft_ht.h" -/** +/* ** \brief Create a new hash table. ** \param size Size of the underlying array of linked list (buckets) ** \return Created hash table or NULL is an allocation failed diff --git a/src/ht/ft_htset.c b/src/ht/ft_htset.c index 9738c14..68d3752 100644 --- a/src/ht/ft_htset.c +++ b/src/ht/ft_htset.c @@ -6,16 +6,17 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/30 08:41:52 by cacharle #+# #+# */ -/* Updated: 2020/02/28 12:11:00 by cacharle ### ########.fr */ +/* Updated: 2020/04/01 18:02:12 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" #include "libft_ht.h" -/** +/* ** \brief Create/Update a entry in hash table. -** \note If `key` already exist in `ht`, only updates the list node content. +** \note If `key` already exist in `ht` +** only updates the list node content. ** Else create a new list node in addition the list content. ** \param ht Hash table where the entry is modified ** \param key Key of the new entry diff --git a/src/lst/ft_lstdelone.c b/src/lst/ft_lstdelone.c index 40e25cd..3dfbbbb 100644 --- a/src/lst/ft_lstdelone.c +++ b/src/lst/ft_lstdelone.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Delete list node ** \param del Delete function for node's data */ diff --git a/src/lst/ft_lstdestroy.c b/src/lst/ft_lstdestroy.c index 5e55f04..35da2a5 100644 --- a/src/lst/ft_lstdestroy.c +++ b/src/lst/ft_lstdestroy.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Destroy a list and set his pointer to NULL ** \param del Delete Function for data of each node */ diff --git a/src/lst/ft_lstiter.c b/src/lst/ft_lstiter.c index 39d870b..e46b507 100644 --- a/src/lst/ft_lstiter.c +++ b/src/lst/ft_lstiter.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Iterate of list ** \param f Funtion applied to data of each node */ diff --git a/src/lst/ft_lstlast.c b/src/lst/ft_lstlast.c index 12fdeee..97b853d 100644 --- a/src/lst/ft_lstlast.c +++ b/src/lst/ft_lstlast.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Last node ** \return List's last node */ diff --git a/src/lst/ft_lstmap.c b/src/lst/ft_lstmap.c index bf96892..3182bb0 100644 --- a/src/lst/ft_lstmap.c +++ b/src/lst/ft_lstmap.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Clone a list and map a function to each node data ** \param lst Origin list ** \param f Function applied to each node's data diff --git a/src/lst/ft_lstnew.c b/src/lst/ft_lstnew.c index 41c8153..1616b71 100644 --- a/src/lst/ft_lstnew.c +++ b/src/lst/ft_lstnew.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Create a list node ** \param data Pointer to data of node */ diff --git a/src/lst/ft_lstpop_front.c b/src/lst/ft_lstpop_front.c index 798bf83..a61350a 100644 --- a/src/lst/ft_lstpop_front.c +++ b/src/lst/ft_lstpop_front.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Delete head node and replace it with next node ** \param del Delete function for node data */ diff --git a/src/lst/ft_lstpush_back.c b/src/lst/ft_lstpush_back.c index 372c18c..1dca078 100644 --- a/src/lst/ft_lstpush_back.c +++ b/src/lst/ft_lstpush_back.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Push new node to the list end ** \param new Pushed node */ diff --git a/src/lst/ft_lstpush_front.c b/src/lst/ft_lstpush_front.c index c17a586..85df649 100644 --- a/src/lst/ft_lstpush_front.c +++ b/src/lst/ft_lstpush_front.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Push node to list front ** \param new Pushed node */ diff --git a/src/lst/ft_lstremove_if.c b/src/lst/ft_lstremove_if.c index fdac710..4070355 100644 --- a/src/lst/ft_lstremove_if.c +++ b/src/lst/ft_lstremove_if.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Remove node on some condition ** \param cmp Comparison function, return 0 if equal ** \param ref Reference data passed has the first arg of `cmp` diff --git a/src/lst/ft_lstreverse.c b/src/lst/ft_lstreverse.c index fd5259b..7c2778d 100644 --- a/src/lst/ft_lstreverse.c +++ b/src/lst/ft_lstreverse.c @@ -12,7 +12,7 @@ #include "libft_lst.h" -/** +/* ** \brief Reverse a list */ diff --git a/src/lst/ft_lstreverse_ret.c b/src/lst/ft_lstreverse_ret.c index 259af9e..36c0c5c 100644 --- a/src/lst/ft_lstreverse_ret.c +++ b/src/lst