lst functions improvements
This commit is contained in:
parent
38e491df7a
commit
d3ec77154d
13 changed files with 29 additions and 38 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:49:04 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:27:46 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;
|
typedef struct s_list t_list;
|
||||||
|
|
||||||
t_list *ft_lstnew(void const *content, size_t content_size);
|
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_lstdelone(t_list **alst, void (*del)(void *, size_t));
|
||||||
void ft_lstadd(t_list **alst, t_list *new);
|
void ft_lstadd(t_list **alst, t_list *new);
|
||||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
|
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:45 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:48 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/04 11:09:10 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/04 11:09:12 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(
|
void ft_lst_delif(
|
||||||
t_list **alst,
|
t_list **alst,
|
||||||
void *data_ref, int (*cmp)(),
|
void *data_ref,
|
||||||
|
int (*cmp)(),
|
||||||
void (*del)(void *, size_t))
|
void (*del)(void *, size_t))
|
||||||
{
|
{
|
||||||
t_list *last;
|
|
||||||
t_list *current;
|
|
||||||
t_list *tmp;
|
t_list *tmp;
|
||||||
|
t_list **indirect;
|
||||||
|
|
||||||
last = NULL;
|
indirect = alst;
|
||||||
current = *alst;
|
while (*indirect)
|
||||||
tmp = NULL;
|
|
||||||
while (current)
|
|
||||||
{
|
{
|
||||||
if ((*cmp)(current->content, data_ref) == 0)
|
if ((*cmp)((*indirect)->content, data_ref) == 0)
|
||||||
{
|
{
|
||||||
if (current == *alst)
|
tmp = (*indirect);
|
||||||
*alst = current->next;
|
(*indirect) = (*indirect)->next;
|
||||||
else
|
(*del)(tmp->content, tmp->content_size);
|
||||||
last->next = current->next;
|
|
||||||
tmp = current;
|
|
||||||
current = current->next;
|
|
||||||
ft_lstdelone(&tmp, del);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
indirect = &(*indirect)->next;
|
||||||
last = current;
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/04 11:09:15 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/04 11:09:30 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 *tmp;
|
||||||
t_list **indirect;
|
t_list **indirect;
|
||||||
|
|
||||||
tmp = NULL;
|
|
||||||
indirect = alst;
|
indirect = alst;
|
||||||
while (*indirect)
|
while (*indirect)
|
||||||
{
|
{
|
||||||
if ((*cmp)((*indirect)->content, data_ref) == 0)
|
if ((*cmp)((*indirect)->content, data_ref) == 0)
|
||||||
{
|
{
|
||||||
tmp = (*indirect);
|
tmp = (*indirect);
|
||||||
tmp->next = NULL;
|
|
||||||
(*indirect) = (*indirect)->next;
|
(*indirect) = (*indirect)->next;
|
||||||
|
tmp->next = NULL;
|
||||||
return (tmp);
|
return (tmp);
|
||||||
}
|
}
|
||||||
indirect = &(*indirect)->next;
|
indirect = &(*indirect)->next;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 15:18:57 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))
|
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_lstdel(&(*alst)->next, del);
|
||||||
ft_lstdelone(&(*alst), del);
|
ft_lstdelone(alst, del);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 14:57:15 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))
|
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t))
|
||||||
{
|
{
|
||||||
if (*alst)
|
if (alst && *alst)
|
||||||
{
|
{
|
||||||
if (del)
|
if (del)
|
||||||
(*del)((*alst)->content, (*alst)->content_size);
|
(*del)((*alst)->content, (*alst)->content_size);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 14:57:25 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 14:57:31 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 18:01:04 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;
|
time_t now;
|
||||||
|
|
||||||
now = time(&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);
|
return (1);
|
||||||
else
|
else
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue