diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-04-01 21:51:51 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-04-01 21:58:05 +0200 |
| commit | 65c5d5157e890e9f9445a94fb2d7f660e5492d8e (patch) | |
| tree | 78613f26bdc531104c3e32d76ffcaf3c2f7013f5 /src/lst | |
| parent | c128213daa677d548bfc2905496257fe4a4faf79 (diff) | |
| parent | a1675f56b35f5521a91851bae8ca650706374ae6 (diff) | |
| download | libft-65c5d5157e890e9f9445a94fb2d7f660e5492d8e.tar.gz libft-65c5d5157e890e9f9445a94fb2d7f660e5492d8e.tar.bz2 libft-65c5d5157e890e9f9445a94fb2d7f660e5492d8e.zip | |
Merge branch 'minishell'
Diffstat (limited to 'src/lst')
| -rw-r--r-- | src/lst/ft_lstbsearch.c | 6 | ||||
| -rw-r--r-- | src/lst/ft_lstdelone.c | 10 | ||||
| -rw-r--r-- | src/lst/ft_lstdestroy.c (renamed from src/lst/ft_lstclear.c) | 12 | ||||
| -rw-r--r-- | src/lst/ft_lstiter.c | 10 | ||||
| -rw-r--r-- | src/lst/ft_lstlast.c | 8 | ||||
| -rw-r--r-- | src/lst/ft_lstlfind.c | 6 | ||||
| -rw-r--r-- | src/lst/ft_lstlsearch.c | 6 | ||||
| -rw-r--r-- | src/lst/ft_lstmap.c | 21 | ||||
| -rw-r--r-- | src/lst/ft_lstnew.c | 12 | ||||
| -rw-r--r-- | src/lst/ft_lstpop_front.c | 10 | ||||
| -rw-r--r-- | src/lst/ft_lstpush_back.c (renamed from src/lst/ft_lstadd_back.c) | 10 | ||||
| -rw-r--r-- | src/lst/ft_lstpush_front.c (renamed from src/lst/ft_lstadd_front.c) | 10 | ||||
| -rw-r--r-- | src/lst/ft_lstremove_if.c | 12 | ||||
| -rw-r--r-- | src/lst/ft_lstreverse.c | 5 | ||||
| -rw-r--r-- | src/lst/ft_lstreverse_ret.c | 6 | ||||
| -rw-r--r-- | src/lst/ft_lstsize.c | 8 | ||||
| -rw-r--r-- | src/lst/ft_lstsort.c | 6 | ||||
| -rw-r--r-- | src/lst/ft_lstsorted_merge.c | 10 |
18 files changed, 119 insertions, 49 deletions
diff --git a/src/lst/ft_lstbsearch.c b/src/lst/ft_lstbsearch.c index d694209..0c48eb0 100644 --- a/src/lst/ft_lstbsearch.c +++ b/src/lst/ft_lstbsearch.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ @@ -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_lstdelone.c b/src/lst/ft_lstdelone.c index 63dcc35..3dfbbbb 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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -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_lstclear.c b/src/lst/ft_lstdestroy.c index 0bacb4f..35da2a5 100644 --- a/src/lst/ft_lstclear.c +++ b/src/lst/ft_lstdestroy.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstclear_bonus.c :+: :+: :+: */ +/* ft_lstdestroy.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,16 +10,20 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" -void ft_lstclear(t_ftlst **lst, void (*del)(void *)) +/* +** \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_lstclear(&((*lst)->next), del); + 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..e46b507 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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -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..97b853d 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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -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 92d37d8..fd7e688 100644 --- a/src/lst/ft_lstlfind.c +++ b/src/lst/ft_lstlfind.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* 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 */ /* */ /* ************************************************************************** */ @@ -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 8d2acc8..11c528c 100644 --- a/src/lst/ft_lstlsearch.c +++ b/src/lst/ft_lstlsearch.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* 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 */ /* */ /* ************************************************************************** */ @@ -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..3182bb0 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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -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..1616b71 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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -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 ff386f9..a61350a 100644 --- a/src/lst/ft_lstpop_front.c +++ b/src/lst/ft_lstpop_front.c @@ -5,14 +5,18 @@ /* +:+ +:+ +:+ */ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* 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 */ /* */ /* ************************************************************************** */ -#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_lstadd_back.c b/src/lst/ft_lstpush_back.c index 8f39a75..1dca078 100644 --- a/src/lst/ft_lstadd_back.c +++ b/src/lst/ft_lstpush_back.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstadd_back_bonus.c :+: :+: :+: */ +/* ft_lstpush_back.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,10 +10,14 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" -void ft_lstadd_back(t_ftlst **alst, t_ftlst *new) +/* +** \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 ; diff --git a/src/lst/ft_lstadd_front.c b/src/lst/ft_lstpush_front.c index bcd5ad9..85df649 100644 --- a/src/lst/ft_lstadd_front.c +++ b/src/lst/ft_lstpush_front.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstadd_front_bonus.c :+: :+: :+: */ +/* ft_lstpush_front.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -10,10 +10,14 @@ /* */ /* ************************************************************************** */ -#include "libft.h" #include "libft_lst.h" -void ft_lstadd_front(t_ftlst **alst, t_ftlst *new) +/* +** \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 ; diff --git a/src/lst/ft_lstremove_if.c b/src/lst/ft_lstremove_if.c index 5221ae4..4070355 100644 --- a/src/lst/ft_lstremove_if.c +++ b/src/lst/ft_lstremove_if.c @@ -6,13 +6,19 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ -#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..7c2778d 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..36c0c5c 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..3c6956b 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 <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -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..9945a0f 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..995785f 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); |
