removing the libft of rparodi

This commit is contained in:
Raphael 2024-11-08 19:37:30 +01:00
parent 0391323626
commit be6038dcc8
523 changed files with 724 additions and 3336 deletions

View file

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dl_add.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/10 12:17:48 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:00:43 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
void ft_dl_add_back(t_dlist **head, t_dlist *const added)
{
t_dlist *last;
if (!head || !added)
return ;
if (!*head)
return (ft_dl_add_front(head, added));
last = ft_dl_end(*head);
last->next = added;
added->prev = last;
}
void ft_dl_add_front(t_dlist **head, t_dlist *const added)
{
if (!head || !added)
return ;
if (!*head)
return ((void)(*head = added));
added->next = *head;
(*head)->prev = added;
*head = added;
}

View file

@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dl_apply.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/23 18:59:42 by bgoulard #+# #+# */
/* Updated: 2024/06/23 18:59:43 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
size_t ft_dl_apply(const t_dlist *start, t_data_apply applied)
{
return (ft_dl_apply_range(start, NULL, applied));
}
size_t ft_dl_apply_range(const t_dlist *start, const t_dlist *end,
t_data_apply applied)
{
size_t i;
t_dlist *it;
it = (t_dlist *)start;
i = 0;
while (it != end)
{
applied(it->data);
it = it->next;
i++;
}
return (i);
}
size_t ft_dl_apply_range_node(const t_dlist *start, const t_dlist *end,
t_dnode_apply applied)
{
size_t i;
t_dlist *it;
it = (t_dlist *)start;
i = 0;
while (it != end)
{
applied(it);
it = it->next;
i++;
}
return (i);
}

View file

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dl_clear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/27 21:33:59 by iron #+# #+# */
/* Updated: 2024/06/23 18:59:49 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
size_t ft_dl_clear(t_dlist **head, t_data_apply del)
{
size_t ret;
ret = ft_dl_delete_range(*head, NULL, del);
*head = NULL;
return (ret);
}
size_t ft_dl_clear_range(t_dlist *start, t_dlist *end, t_data_apply del)
{
size_t i;
i = 0;
if (!start)
return (0);
while (start != end)
{
if (del)
del(start->data);
start->data = NULL;
start = start->next;
i++;
}
return (i);
}

View file

@ -0,0 +1,65 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dl_create.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/27 21:34:05 by iron #+# #+# */
/* Updated: 2024/06/23 18:59:53 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
t_dlist *ft_dl_create(const void *data)
{
t_dlist *ret;
ret = ft_dl_new();
if (!ret)
return (ret);
ret->data = (void *)data;
return (ret);
}
t_dlist *ft_dl_copy_node(const t_dlist *const other)
{
t_dlist *ret;
ret = ft_dl_new();
if (!ret)
return (ret);
ret->data = (void *)other->data;
ret->next = (t_dlist *)other->next;
ret->prev = (t_dlist *)other->prev;
return (ret);
}
t_dlist *ft_dl_copy_list(const t_dlist *const other)
{
t_dlist *node;
t_dlist *head;
t_dlist *prev;
t_dlist *it;
it = (t_dlist *)other;
node = NULL;
head = NULL;
prev = NULL;
while (it)
{
node = ft_dl_copy_node(it);
if (!node)
return (ft_dl_delete(&head, NULL), head);
node->prev = prev;
if (prev)
prev->next = node;
else
head = node;
if (it->next)
prev = node;
it = it->next;
}
return (head);
}

View file

@ -0,0 +1,102 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dl_delete.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/27 21:34:10 by iron #+# #+# */
/* Updated: 2024/06/23 19:00:01 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
#include <stdlib.h>
int ft_dl_delete_self(t_dlist *node, t_data_apply del)
{
if (!node)
return (FTLIST_FAILURE);
if (del)
del(node->data);
if (node->prev)
node->prev->next = node->next;
if (node->next)
node->next->prev = node->prev;
free(node);
return (FTLIST_SUCCESS);
}
size_t ft_dl_delete_range(t_dlist *start, const t_dlist *target,
t_data_apply del)
{
t_dlist *next;
t_dlist *prev;
size_t i;
i = 0;
next = NULL;
prev = NULL;
if (start && start->prev)
prev = start->prev;
while (start != target)
{
next = start->next;
if (del)
del(start->data);
free(start);
start = next;
i++;
}
if (prev)
prev->next = next;
if (next)
next->prev = prev;
return (i);
}
size_t ft_dl_delete(t_dlist **head, t_data_apply del)
{
size_t i;
t_dlist *firs_elem;
if (!head)
return (0);
firs_elem = ft_dl_begin(*head);
i = ft_dl_delete_range(firs_elem, NULL, del);
*head = NULL;
return (i);
}
/*
size_t ft_dl_delete_dup(t_dlist **src)
{
t_dlist **node_ptrs;
size_t nb_del;
size_t length;
node_ptrs = NULL;
nb_del = 0;
length = 0;
if (!*src)
return (0);
node_ptrs = ft_dl_get_nodes(*src);
if (!node_ptrs)
return (0);
length = ft_dl_count(*src);
for (size_t j = 0; j + 1 != length; j++) {
for (size_t k = j + 1; k != length; k++) {
if (!node_ptrs[j] || !node_ptrs[k])
continue ;
if (node_ptrs[j]->data == node_ptrs[k]->data) {
ft_dl_delete_self(node_ptrs[k]);
node_ptrs[k] = NULL;
nb_del++;
j++;
}
}
}
free(node_ptrs);
return (nb_del);
}
*/

View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dl_find.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/10 13:05:32 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:00:05 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
t_dlist *ft_dl_find(const t_dlist *head, const void *data,
int (*cmp)(const void *, const void *))
{
t_dlist *it;
it = (t_dlist *)head;
while (it)
{
if (data == it->data || (cmp && !cmp(it->data, data)))
return (it);
it = it->next;
}
return (NULL);
}

View file

@ -0,0 +1,58 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dl_getters.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/27 21:34:21 by iron #+# #+# */
/* Updated: 2024/07/19 17:36:04 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
#include "ft_string.h"
#include <stdlib.h>
void **ft_dl_get_datas(const t_dlist *src)
{
size_t size;
void **ret;
if (!src)
return (NULL);
size = ft_dl_size(src);
ret = ft_calloc(sizeof(void *), (size + 1));
if (!ret)
return (NULL);
ret[size] = NULL;
size = 0;
while (src)
{
ret[size++] = (void *)src->data;
src = src->next;
}
return (ret);
}
t_dlist **ft_dl_get_nodes(const t_dlist *src)
{
size_t size;
t_dlist **ret;
size = ft_dl_size(src);
ret = NULL;
if (!src)
return (NULL);
ret = ft_calloc(sizeof(t_dlist *), (size + 1));
if (!ret)
return (ret);
ret[size] = NULL;
size = 0;
while (src)
{
ret[size++] = (t_dlist *)src;
src = src->next;
}
return (ret);
}

View file

@ -0,0 +1,48 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dl_iterator.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/27 21:34:27 by iron #+# #+# */
/* Updated: 2024/06/23 19:00:12 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
t_dlist *ft_dl_at(const t_dlist *head, size_t index)
{
size_t i;
t_dlist *it;
it = (t_dlist *)head;
i = 0;
while (i != index)
{
i++;
it = it->next;
}
return (it);
}
t_dlist *ft_dl_end(const t_dlist *head)
{
t_dlist *it;
it = (t_dlist *)head;
while (it->next)
it = it->next;
return (it);
}
t_dlist *ft_dl_begin(const t_dlist *head)
{
t_dlist *it;
it = (t_dlist *)head;
while (it->prev)
it = it->prev;
return (it);
}

View file

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dl_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/10 12:21:43 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:00:16 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
t_dlist *ft_dl_map(const t_dlist *lst, t_data_tr f, t_data_apply del)
{
t_dlist *ret;
t_dlist *tmp;
if (!lst || !f)
return (NULL);
ret = NULL;
while (lst)
{
tmp = ft_dl_create(f(lst->data));
if (!tmp)
return (ft_dl_clear(&ret, del), NULL);
ft_dl_add_back(&ret, tmp);
lst = lst->next;
}
return (ret);
}

View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dl_new.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/10 12:42:00 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:00:19 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
#include "ft_string.h"
t_dlist *ft_dl_new(void)
{
t_dlist *ret;
ret = ft_calloc(1, sizeof(t_dlist));
if (!ret)
return (ret);
ret->data = NULL;
ret->prev = NULL;
ret->next = NULL;
return (ret);
}

View file

@ -0,0 +1,80 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dl_pushpop.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/27 21:34:38 by iron #+# #+# */
/* Updated: 2024/06/23 19:00:22 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
#include <stdlib.h>
t_dlist *ft_dl_push(t_dlist **node, const void *data)
{
t_dlist *added;
added = ft_dl_create(data);
added->next = *node;
if (*node)
(*node)->prev = added;
*node = added;
return (added);
}
t_dlist *ft_dl_push_back(t_dlist **node, const void *data)
{
t_dlist *added;
t_dlist *it;
it = *node;
if (!*node)
return (ft_dl_push(node, data));
added = ft_dl_create(data);
while (it->next)
it = it->next;
it->next = added;
added->prev = it;
return (*node);
}
void *ft_dl_pop(t_dlist **node)
{
void *data;
t_dlist *it;
data = NULL;
if (!node || !*node)
return (NULL);
it = *node;
*node = (*node)->next;
data = it->data;
free(it);
if (*node)
(*node)->prev = NULL;
return (data);
}
void *ft_dl_pop_back(t_dlist **node)
{
void *data;
t_dlist *it;
t_dlist *prev;
data = NULL;
prev = NULL;
if (!node || !*node)
return (NULL);
it = ft_dl_end(*node);
data = it->data;
prev = it->prev;
if (prev)
prev->next = NULL;
else
*node = NULL;
free(it);
return (data);
}

View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dl_rev.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: iron <iron@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/10 12:20:27 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:00:28 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
t_dlist *ft_dl_rev(t_dlist **head)
{
t_dlist *it;
t_dlist *tmp;
if (!head || !*head)
return (NULL);
it = *head;
while (it)
{
tmp = it->next;
it->next = it->prev;
it->prev = tmp;
if (!tmp)
*head = it;
it = tmp;
}
return (*head);
}

View file

@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dl_size.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/27 21:34:50 by iron #+# #+# */
/* Updated: 2024/06/23 19:00:35 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
size_t ft_dl_size(const t_dlist *head)
{
t_dlist *it;
size_t i;
i = 0;
it = (t_dlist *)head;
while (it)
{
it = it->next;
i++;
}
return (i);
}
size_t ft_dl_size_of_data(const t_dlist *head, t_data_is function)
{
t_dlist *it;
size_t i;
it = (t_dlist *)head;
i = 0;
while (it)
{
if (function(it->data))
i++;
it = it->next;
}
return (i);
}

View file

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dl_sub.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/27 21:34:45 by iron #+# #+# */
/* Updated: 2024/06/23 19:00:38 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
t_dlist *ft_dl_subrange(const t_dlist *src, const t_dlist *to)
{
t_dlist *ret;
t_dlist *prev;
t_dlist *new_node;
t_dlist *it;
ret = NULL;
if (!src)
return (ret);
ret = ft_dl_create(src->data);
if (src == to)
return (ret);
prev = ret;
it = src->next;
while (it != to)
{
new_node = ft_dl_create(it->data);
if (!new_node)
return (ft_dl_delete(&prev, NULL), NULL);
new_node->prev = prev;
new_node->next = NULL;
prev->next = new_node;
prev = new_node;
it = it->next;
}
return (ret);
}

View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ll_add.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 23:48:35 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:00:50 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
void ft_ll_add_front(t_list **lst, t_list *new)
{
if (!lst)
return ;
new->next = *lst;
*lst = new;
}
void ft_ll_add_back(t_list **lst, t_list *new)
{
if (!*lst)
*lst = new;
else
ft_ll_end(*lst)->next = new;
}

View file

@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ll_apply.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 09:01:53 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:00:54 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
void ft_ll_apply(const t_list *lst, t_data_apply f)
{
t_list *it;
if (!f)
return ;
it = (t_list *)lst;
while (it)
{
f(it->data);
it = it->next;
}
}
void ft_ll_apply_range(const t_list *lst, const t_list *end, t_data_apply f)
{
t_list *it;
if (!f)
return ;
it = (t_list *)lst;
while (it && it != end)
{
f(it->data);
it = it->next;
}
}
// nxt = lst->next;
// f may modify lst->next, we dont know
void ft_ll_apply_range_node(const t_list *lst, const t_list *end,
t_lnode_apply f)
{
t_list *nxt;
t_list *it;
if (!f)
return ;
it = (t_list *)lst;
while (it && it != end)
{
nxt = it->next;
f(it);
it = nxt;
}
}

View file

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ll_clear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/08 03:12:14 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:00:56 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
#include <stdlib.h>
void ft_ll_clear(t_list **lst, t_data_apply del)
{
t_list *runner;
t_list *next;
if (!lst)
return ;
runner = *lst;
while (runner)
{
next = runner->next;
if (del)
del(runner->data);
runner->data = NULL;
free(runner);
runner = next;
}
*lst = NULL;
}

View file

@ -0,0 +1,61 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ll_create.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/10 11:40:49 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:01:00 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
t_list *ft_ll_create(const void *const data)
{
t_list *ret;
ret = ft_ll_new();
if (!ret)
return (ret);
ret->data = (void *)data;
return (ret);
}
t_list *ft_ll_copy_node(const t_list *const other)
{
t_list *ret;
ret = ft_ll_new();
if (!ret)
return (ret);
ret->data = (void *)other->data;
ret->next = (t_list *)other->next;
return (ret);
}
t_list *ft_ll_copy_list(const t_list *const other)
{
t_list *node;
t_list *head;
t_list *prev;
t_list *it;
it = (t_list *)other;
head = ft_ll_copy_node(it);
if (!head)
return (head);
prev = head;
it = (t_list *)it->next;
while (it)
{
node = ft_ll_copy_node(it);
if (!node)
return (ft_ll_clear(&head, NULL), NULL);
prev->next = node;
prev = node;
it = (t_list *)it->next;
}
return (head);
}

View file

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ll_delete.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/08 03:09:13 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:01:03 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
#include <stdlib.h>
void ft_ll_delone(t_list *lst, t_data_apply del)
{
if (!lst)
return ;
if (del)
del(lst->data);
free(lst);
}
size_t ft_ll_delete_range(t_list *lst, const t_list *end, t_data_apply del)
{
t_list *tmp;
size_t i;
i = 0;
if (!lst || !del)
return (i);
while (lst && lst != end)
{
i++;
tmp = lst->next;
del(lst->data);
free(lst);
lst = tmp;
}
return (i);
}

View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ll_find.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/08 11:12:59 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:01:06 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
void *ft_ll_find(const t_list *list, const void *data,
int (*cmp)(const void *, const void *))
{
t_list *it;
it = (t_list *)list;
while (it)
{
if (data == it->data || (cmp && cmp(it->data, data) == 0))
return (it->data);
it = it->next;
}
return (NULL);
}

View file

@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ll_getters.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/10 11:54:40 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:01:09 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
#include "ft_string.h"
void **ft_ll_get_datas(const t_list *src)
{
void **datas;
size_t i;
if (!src)
return (NULL);
datas = ft_calloc(sizeof(void *), ft_ll_size(src) + 1);
if (!datas)
return (NULL);
i = 0;
while (src)
{
datas[i] = src->data;
src = src->next;
i++;
}
return (datas);
}
t_list **ft_ll_get_nodes(const t_list *src)
{
t_list **nodes;
size_t i;
if (!src)
return (NULL);
nodes = ft_calloc(sizeof(t_list *), ft_ll_size(src) + 1);
if (!nodes)
return (NULL);
i = 0;
while (src)
{
nodes[i] = (t_list *)src;
src = src->next;
i++;
}
return (nodes);
}

View file

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ll_iterator.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 23:43:27 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:01:12 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
t_list *ft_ll_end(const t_list *lst)
{
if (!lst)
return (NULL);
while (lst->next)
lst = lst->next;
return ((t_list *)lst);
}
t_list *ft_ll_at(const t_list *lst, size_t index)
{
size_t i;
i = 0;
while (lst && i < index)
{
lst = lst->next;
i++;
}
if (i != index)
return (NULL);
return ((t_list *)lst);
}

View file

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ll_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 09:04:38 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:01:16 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
t_list *ft_ll_map(const t_list *lst, t_data_tr f, t_data_apply del)
{
t_list *ret;
t_list *node;
ret = NULL;
if (!f || !del || !lst)
return (NULL);
while (lst)
{
node = ft_ll_create(f(lst->data));
if (!node)
return (ft_ll_clear(&ret, del), NULL);
ft_ll_add_back(&ret, node);
lst = lst->next;
}
return (ret);
}

View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ll_new.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 23:30:32 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:01:19 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
#include "ft_string.h"
t_list *ft_ll_new(void)
{
t_list *elem;
elem = ft_calloc(sizeof(t_list), 1);
return (elem);
}

View file

@ -0,0 +1,76 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ll_pushpop.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/10 12:02:47 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:01:22 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
#include "ft_string.h"
t_list *ft_ll_push(t_list **lst, const void *data)
{
t_list *new;
if (!lst)
return (NULL);
new = ft_ll_create(data);
if (!new)
return (NULL);
new->next = *lst;
*lst = new;
return (*lst);
}
t_list *ft_ll_push_back(t_list **lst, const void *data)
{
t_list *added;
if (!lst)
return (NULL);
added = ft_ll_create(data);
if (!added)
return (NULL);
if (!*lst)
*lst = added;
else
ft_ll_end(*lst)->next = added;
return (*lst);
}
void *ft_ll_pop(t_list **lst)
{
t_list *tmp;
void *data;
if (!lst || !*lst)
return (NULL);
tmp = *lst;
data = (*lst)->data;
*lst = (*lst)->next;
ft_free((void **)&tmp);
return (data);
}
void *ft_ll_pop_back(t_list **lst)
{
t_list *pre_last;
void *data;
if (!lst || !*lst)
return (NULL);
if (!(*lst)->next)
return (ft_ll_pop(lst));
pre_last = *lst;
while (pre_last->next->next)
pre_last = pre_last->next;
data = pre_last->next->data;
free(pre_last->next);
pre_last->next = NULL;
return (data);
}

View file

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ll_rev.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: iron <iron@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/21 15:22:54 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:01:25 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
t_list *ft_ll_rev(t_list **head)
{
t_list *next;
t_list *it;
t_list *prev;
if (!head || !*head)
return (NULL);
it = *head;
prev = NULL;
next = it->next;
while (next)
{
next = it->next;
it->next = prev;
prev = it;
it = next;
}
*head = prev;
return (*head);
}

View file

@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ll_size.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 23:38:32 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:01:28 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
size_t ft_ll_size(const t_list *lst)
{
t_list *it;
size_t i;
i = 0;
it = (t_list *)lst;
while (it)
{
it = it->next;
i++;
}
return (i);
}
size_t ft_ll_size_match(const t_list *lst, t_data_is function)
{
size_t i;
t_list *it;
i = 0;
it = (t_list *)lst;
while (it)
{
if (function(it->data))
i++;
it = it->next;
}
return (i);
}

View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ll_sub.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/10 12:10:57 by bgoulard #+# #+# */
/* Updated: 2024/06/23 19:01:31 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_list.h"
t_list *ft_ll_subrange(const t_list *lst, const t_list *end)
{
t_list *sub;
sub = NULL;
if (!lst)
return (sub);
if (lst == end)
return (ft_ll_create(lst->data));
while (lst && lst != end)
{
ft_ll_push_back(&sub, lst->data);
lst = lst->next;
}
return (sub);
}