lst functions improvements

This commit is contained in:
Jack Halford 2016-11-08 16:28:32 +01:00
parent ed8b34bc5d
commit 99ebd75ca7
13 changed files with 29 additions and 38 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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));

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);