From d3ec77154d06d504bc414fb809cafd3ce5a22684 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Tue, 8 Nov 2016 16:28:32 +0100 Subject: [PATCH] lst functions improvements --- libftasm/includes/libft.h | 2 +- libftasm/includes/lst.h | 3 ++- libftasm/src/ft_printf/lib_pad.c | 2 +- libftasm/src/ft_printf/lib_pad_sharp.c | 2 +- libftasm/src/lst/ft_lst_cfree.c | 2 +- libftasm/src/lst/ft_lst_delif.c | 31 +++++++++----------------- libftasm/src/lst/ft_lst_delsub.c | 2 +- libftasm/src/lst/ft_lst_removeif.c | 5 ++--- libftasm/src/lst/ft_lstdel.c | 6 ++--- libftasm/src/lst/ft_lstdelone.c | 4 ++-- libftasm/src/mem/ft_memalloc.c | 2 +- libftasm/src/mem/ft_memcpy.c | 2 +- libftasm/src/time/ft_time_isrecent.c | 4 ++-- 13 files changed, 29 insertions(+), 38 deletions(-) diff --git a/libftasm/includes/libft.h b/libftasm/includes/libft.h index 00637c9d..c6e8c0b6 100644 --- a/libftasm/includes/libft.h +++ b/libftasm/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2016/11/07 15:46:27 by jhalford ### ########.fr */ +/* Updated: 2016/11/08 11:25:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/includes/lst.h b/libftasm/includes/lst.h index 241962dd..3b851fff 100644 --- a/libftasm/includes/lst.h +++ b/libftasm/includes/lst.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:31:28 by jhalford ### ########.fr */ +/* Updated: 2016/11/08 11:25:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,7 @@ struct s_list typedef struct s_list t_list; 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); void ft_lstiter(t_list *lst, void (*f)(t_list *elem)); diff --git a/libftasm/src/ft_printf/lib_pad.c b/libftasm/src/ft_printf/lib_pad.c index 0ec1d1bf..f2efe4b8 100644 --- a/libftasm/src/ft_printf/lib_pad.c +++ b/libftasm/src/ft_printf/lib_pad.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:45 by jhalford #+# #+# */ -/* Updated: 2016/11/07 16:58:00 by jhalford ### ########.fr */ +/* Updated: 2016/11/08 10:18:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/ft_printf/lib_pad_sharp.c b/libftasm/src/ft_printf/lib_pad_sharp.c index c1d79a05..e6d57063 100644 --- a/libftasm/src/ft_printf/lib_pad_sharp.c +++ b/libftasm/src/ft_printf/lib_pad_sharp.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */ -/* Updated: 2016/11/07 16:58:09 by jhalford ### ########.fr */ +/* Updated: 2016/11/08 10:18:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/lst/ft_lst_cfree.c b/libftasm/src/lst/ft_lst_cfree.c index 1cd33c11..3297a219 100644 --- a/libftasm/src/lst/ft_lst_cfree.c +++ b/libftasm/src/lst/ft_lst_cfree.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:10 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:09:11 by jhalford ### ########.fr */ +/* Updated: 2016/11/08 11:09:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/lst/ft_lst_delif.c b/libftasm/src/lst/ft_lst_delif.c index 03fe045e..2e319aa9 100644 --- a/libftasm/src/lst/ft_lst_delif.c +++ b/libftasm/src/lst/ft_lst_delif.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:47:22 by jhalford ### ########.fr */ +/* Updated: 2016/11/08 15:00:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,32 +14,23 @@ void ft_lst_delif( t_list **alst, - void *data_ref, int (*cmp)(), + void *data_ref, + int (*cmp)(), void (*del)(void *, size_t)) { - t_list *last; - t_list *current; t_list *tmp; + t_list **indirect; - last = NULL; - current = *alst; - tmp = NULL; - while (current) + indirect = alst; + while (*indirect) { - if ((*cmp)(current->content, data_ref) == 0) + if ((*cmp)((*indirect)->content, data_ref) == 0) { - if (current == *alst) - *alst = current->next; - else - last->next = current->next; - tmp = current; - current = current->next; - ft_lstdelone(&tmp, del); + tmp = (*indirect); + (*indirect) = (*indirect)->next; + (*del)(tmp->content, tmp->content_size); } else - { - last = current; - current = current->next; - } + indirect = &(*indirect)->next; } } diff --git a/libftasm/src/lst/ft_lst_delsub.c b/libftasm/src/lst/ft_lst_delsub.c index baa77125..005e9dd2 100644 --- a/libftasm/src/lst/ft_lst_delsub.c +++ b/libftasm/src/lst/ft_lst_delsub.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:15 by jhalford #+# #+# */ -/* Updated: 2016/11/04 12:00:41 by jhalford ### ########.fr */ +/* Updated: 2016/11/08 13:36:17 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/lst/ft_lst_removeif.c b/libftasm/src/lst/ft_lst_removeif.c index 85874721..747c15dc 100644 --- a/libftasm/src/lst/ft_lst_removeif.c +++ b/libftasm/src/lst/ft_lst_removeif.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:30 by jhalford #+# #+# */ -/* Updated: 2016/11/04 13:07:22 by jhalford ### ########.fr */ +/* Updated: 2016/11/08 11:52:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,15 +17,14 @@ t_list *ft_lst_removeif(t_list **alst, void *data_ref, int (*cmp)()) t_list *tmp; t_list **indirect; - tmp = NULL; indirect = alst; while (*indirect) { if ((*cmp)((*indirect)->content, data_ref) == 0) { tmp = (*indirect); - tmp->next = NULL; (*indirect) = (*indirect)->next; + tmp->next = NULL; return (tmp); } indirect = &(*indirect)->next; diff --git a/libftasm/src/lst/ft_lstdel.c b/libftasm/src/lst/ft_lstdel.c index b8056396..4d4e1312 100644 --- a/libftasm/src/lst/ft_lstdel.c +++ b/libftasm/src/lst/ft_lstdel.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 15:18:57 by jhalford #+# #+# */ -/* Updated: 2016/11/03 16:40:21 by jhalford ### ########.fr */ +/* Updated: 2016/11/08 13:36:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) { - if ((*alst)->next) + if (alst && *alst && (*alst)->next) ft_lstdel(&(*alst)->next, del); - ft_lstdelone(&(*alst), del); + ft_lstdelone(alst, del); } diff --git a/libftasm/src/lst/ft_lstdelone.c b/libftasm/src/lst/ft_lstdelone.c index 1aa876b5..d9b05960 100644 --- a/libftasm/src/lst/ft_lstdelone.c +++ b/libftasm/src/lst/ft_lstdelone.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:15 by jhalford #+# #+# */ -/* Updated: 2016/11/03 15:15:51 by jhalford ### ########.fr */ +/* Updated: 2016/11/08 13:45:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)) { - if (*alst) + if (alst && *alst) { if (del) (*del)((*alst)->content, (*alst)->content_size); diff --git a/libftasm/src/mem/ft_memalloc.c b/libftasm/src/mem/ft_memalloc.c index a94572ed..bb1bd18d 100644 --- a/libftasm/src/mem/ft_memalloc.c +++ b/libftasm/src/mem/ft_memalloc.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:25 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:57:25 by jhalford ### ########.fr */ +/* Updated: 2016/11/08 13:15:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/mem/ft_memcpy.c b/libftasm/src/mem/ft_memcpy.c index 38a72390..37e9051f 100644 --- a/libftasm/src/mem/ft_memcpy.c +++ b/libftasm/src/mem/ft_memcpy.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:31 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:10:31 by jhalford ### ########.fr */ +/* Updated: 2016/11/08 13:17:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/time/ft_time_isrecent.c b/libftasm/src/time/ft_time_isrecent.c index 032feb58..0a01102d 100644 --- a/libftasm/src/time/ft_time_isrecent.c +++ b/libftasm/src/time/ft_time_isrecent.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:01:04 by jhalford #+# #+# */ -/* Updated: 2016/11/03 18:01:19 by jhalford ### ########.fr */ +/* Updated: 2016/11/08 16:12:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ int ft_time_isrecent(time_t event) time_t now; now = time(&now); - if (now - event > 0 && now - event < 6 * 365 / 12 * 24 * 60 * 60) + if (now - event >= 0 && now - event <= 6 * 365 / 12 * 24 * 60 * 60) return (1); else return (0);