From 0aef5828829962e6127275bf2af1f388958d785f Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 31 Mar 2017 21:50:40 +0200 Subject: [PATCH] merged 42sh stuff that wasnt in the submodule --- libft/Makefile | 1 + libft/includes/lst.h | 10 ++++++--- libft/srcs/lst/ft_lst_filterout.c | 36 +++++++++++++++++++++++++++++++ libft/srcs/lst/ft_lstiter.c | 16 ++++++-------- 4 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 libft/srcs/lst/ft_lst_filterout.c diff --git a/libft/Makefile b/libft/Makefile index b6ff4664..2f64d00d 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -79,6 +79,7 @@ lst/ft_lst_cfree.c\ lst/ft_lst_delif.c\ lst/ft_lst_delsub.c\ lst/ft_lst_filter.c\ +lst/ft_lst_filterout.c\ lst/ft_lst_find.c\ lst/ft_lst_merge.c\ lst/ft_lst_order_delsub.c\ diff --git a/libft/includes/lst.h b/libft/includes/lst.h index 2b6a9e24..4b5eb5c0 100644 --- a/libft/includes/lst.h +++ b/libft/includes/lst.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */ -/* Updated: 2017/03/24 20:09:05 by jhalford ### ########.fr */ +/* Updated: 2017/03/28 20:34:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,13 +26,12 @@ typedef struct s_list t_list; int pop(t_list **lst); t_list *push(t_list **stack, int elem); -int top(t_list *top); t_list *ft_lstnew(void const *content, size_t content_size); void ft_lstdel(t_list **alst, void (*del)(void *, size_t)); void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)); void ft_lstadd(t_list **alst, t_list *new); -int ft_lstiter(t_list *lst, int (*f)()); +int ft_lstiter(t_list *lst, int (*f)(), void *data); t_list *ft_lstmap(t_list *lst, void *(*f)(void *)); t_list *ft_lstnew_range(int a, int b); @@ -76,6 +75,11 @@ t_list *ft_lst_find( t_list *ft_lstpop(t_list **lst); void ft_lst_merge(t_list **begin_list1, t_list *begin_list2); void ft_lst_reverse(t_list **begin_list); +void ft_lst_filterout( + t_list **alst, + void *data_ref, + int (*cmp)(), + void (*del)(void *, size_t)); int ft_diff(void *a, void *b); t_list *ft_id(t_list *a); diff --git a/libft/srcs/lst/ft_lst_filterout.c b/libft/srcs/lst/ft_lst_filterout.c new file mode 100644 index 00000000..9a97c09d --- /dev/null +++ b/libft/srcs/lst/ft_lst_filterout.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lst_filterout.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/26 16:56:02 by jhalford #+# #+# */ +/* Updated: 2017/03/26 19:10:03 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lst_filterout( + t_list **alst, + void *data_ref, + int (*cmp)(), + void (*del)(void *, size_t)) +{ + t_list *tmp; + t_list **indirect; + + indirect = alst; + while (*indirect) + { + if ((*cmp)((*indirect)->content, data_ref) == 0) + { + tmp = *indirect; + (*indirect) = (*indirect)->next; + ft_lstdelone(&tmp, del); + } + else + indirect = &(*indirect)->next; + } +} diff --git a/libft/srcs/lst/ft_lstiter.c b/libft/srcs/lst/ft_lstiter.c index 217f803c..49a96476 100644 --- a/libft/srcs/lst/ft_lstiter.c +++ b/libft/srcs/lst/ft_lstiter.c @@ -6,19 +6,17 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:19 by jhalford #+# #+# */ -/* Updated: 2017/03/11 16:17:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/28 11:27:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -int ft_lstiter(t_list *lst, int (*f)()) +int ft_lstiter(t_list *lst, int (*f)(), void *data) { - while (lst) - { - if ((*f)(lst->content)) - return (1); - lst = lst->next; - } - return (0); + if (!lst) + return (0); + if ((*f)(lst->content, data)) + return (1); + return (ft_lstiter(lst->next, f, data)); }