some name changes

This commit is contained in:
Jack Halford 2016-09-10 15:25:47 +02:00
parent 258a00cfeb
commit e590988c7d
7 changed files with 56 additions and 15 deletions

View file

@ -1,6 +1,6 @@
#include "libft.h" #include "libft.h"
void *ft_id(void *a) t_list *ft_id(t_list *a)
{ {
return (a); return (a);
} }

8
libft/ft_lst_cfree.c Normal file
View file

@ -0,0 +1,8 @@
#include "libft.h"
void ft_lst_cfree(void *ptr, size_t size)
{
(void)size;
if (ptr)
free(ptr);
}

View file

@ -1,29 +1,25 @@
#include "libft.h" #include "libft.h"
void ft_lst_remove_if( void ft_lst_delif(t_list **alst, void *data_ref, int (*cmp)(), void (*del)(void *, size_t))
t_list **begin_list,
void *data_ref,
int (*cmp)())
{ {
t_list *last; t_list *last;
t_list *current; t_list *current;
t_list *tmp; t_list *tmp;
last = NULL; last = NULL;
current = *begin_list; current = *alst;
tmp = NULL; tmp = NULL;
fflush(stdout);
while (current) while (current)
{ {
if ((*cmp)(current->content, &data_ref) == 0) if ((*cmp)(current->content, data_ref) == 0)
{ {
if (current == *begin_list) if (current == *alst)
*begin_list = current->next; *alst = current->next;
else else
last->next = current->next; last->next = current->next;
tmp = current; tmp = current;
current = current->next; current = current->next;
free(tmp); ft_lstdelone(&tmp, del);
} }
else else
{ {

View file

@ -1,6 +1,6 @@
#include "libft.h" #include "libft.h"
void ft_lstdelsub(t_list **alst, t_list *sub, int (*cmp)(), void (*del)(void *, size_t)) void ft_lst_delsub(t_list **alst, t_list *sub, int (*cmp)(), void (*del)(void *, size_t))
{ {
t_list *last; t_list *last;
t_list *current; t_list *current;
@ -11,6 +11,11 @@ void ft_lstdelsub(t_list **alst, t_list *sub, int (*cmp)(), void (*del)(void *,
tmp = NULL; tmp = NULL;
while (current && sub) while (current && sub)
{ {
if ((*cmp)(current->content, sub->content) > 0)
{
sub = sub->next;
continue ;
}
if ((*cmp)(current->content, sub->content) == 0) if ((*cmp)(current->content, sub->content) == 0)
{ {
if (current == *alst) if (current == *alst)

24
libft/ft_lst_filter.c Normal file
View file

@ -0,0 +1,24 @@
#include "libft.h"
t_list *ft_lst_filter(t_list *lst, void const *data_ref, t_list *(*f)(t_list *elem, void const *))
{
t_list *out;
t_list *elem;
out = NULL;
while (lst)
{
elem = (*f)(lst, data_ref);
/* printf("size=%zu\n", elem->content_size); */
/* printf("content=%i\n", *(int*)elem->content); */
/* fflush(stdout); */
elem = ft_lstnew(elem->content, elem->content_size);
/* printf("size=%zu\n", elem->content_size); */
/* printf("content=%i\n", *(int*)elem->content); */
/* fflush(stdout); */
ft_lsteadd(&out, elem);
lst = lst->next;
}
/* ft_lst_print(out, &ft_putnbr); */
return (out);
}

View file

@ -2,7 +2,11 @@
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 (del)
(*del)((*alst)->content, (*alst)->content_size); (*del)((*alst)->content, (*alst)->content_size);
free(*alst); free(*alst);
}
*alst = NULL; *alst = NULL;
} }

View file

@ -89,7 +89,11 @@ t_list *ft_lstlast(t_list *lst);
void ft_lst_sorted_merge(t_list **begin_list1, t_list *begin_list2, int (*cmp)()); void ft_lst_sorted_merge(t_list **begin_list1, t_list *begin_list2, int (*cmp)());
void ft_lst_sorted_insert(t_list **begin_list, t_list *insert, int (*cmp)()); void ft_lst_sorted_insert(t_list **begin_list, t_list *insert, int (*cmp)());
t_list *ft_lstnew_range(int a, int b); t_list *ft_lstnew_range(int a, int b);
void ft_lst_delif(t_list **alist, void *data_ref, int (*cmp)(), void (*del)(void *, size_t));
void ft_lst_delsub(t_list **alst, t_list *sub, int (*cmp)(), void (*del)(void *, size_t));
void ft_lst_cfree(void *ptr, size_t size);
t_list *ft_lst_filter(t_list *lst, void const *data_ref, t_list *(*f)(t_list *elem, void const *));
int ft_diff(void *a, void *b); int ft_diff(void *a, void *b);
void *ft_id(void *a); t_list *ft_id(t_list *a);
#endif #endif