(my)TinyLibC 0.0.1
little tiny pretty lib c
Loading...
Searching...
No Matches
tlcllists.h
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2022
3** (my) Tiny Lib C
4** File description:
5** linked list part
6*/
7
8#ifndef TLS_LLISTS_H_
9 #define TLS_LLISTS_H_
10
11 #include <stdbool.h>
12 #include "tlcutils.h"
13
14typedef struct llnode node_t;
15struct llnode {
16 node_t *next;
17 void *data;
18 void (*destroy)(void *data);
19 void *(*copy)(void *data);
20};
21
22typedef struct llist list_t;
23struct llist {
24 node_t *start;
25 node_t *end;
26 int len;
27};
28
29typedef struct llnodesearch node_result_t;
31 node_t *node_ptr;
33};
34
35 #define _COPY_CHECK(x) (x != 0 && (x)->copy != 0)
36 #define _DESTROY_CHECK(x) (x != 0 && (x)->destroy != 0)
37 #define _VOID(c, e) ((c) ? e : return_void())
38
45 #define L_LEN(x) ((x != 0) ? (x)->len : 0)
52 #define L_NEXT(x) ((x != 0) ? (x)->next : 0)
59 #define L_FIRST(list) ((list != 0) ? (list)->start : 0)
66 #define L_LAST(list) ((list != 0) ? (list)->end : 0)
73 #define L_COPY(x) ((_COPY_CHECK(x)) ? (x)->copy((x)->data) : 0)
80 #define L_DATA(x) ((x != 0) ? (x)->data : 0)
87 #define L_DESTROY(x) (_VOID(_DESTROY_CHECK(x), (x)->destroy(L_DATA(x))))
88
95 #define L_DECL_FIRST(x, list) node_t *x = L_FIRST(list)
102 #define L_DECL_LAST(x, list) node_t *x = L_LAST(list)
110 #define L_EACH(x, list) L_DECL_FIRST(x, list); x != 0; x = L_NEXT(x)
111
112 #undef _COPY_CHECK
113 #undef _DESTROY_CHECK
114 #undef _VOID
115
129list_t *list_append(list_t *list, void *data, void (*destroy)(void *data),
130 void *(*copy)(void *data));
131
137list_t *list_create(void);
138
151node_t *node_create(void *data, void (*destroy)(void *data),
152 void *(*copy)(void *data));
153
159void list_delete(list_t *list);
160
168list_t *list_duplicate(list_t *list);
169
178node_result_t list_find_ptrdata(list_t *list, void *data);
179
188int list_find_ptrnode(list_t *list, node_t *node_ptr);
189
199node_result_t list_find_f(list_t *list,
200 bool (is_this_result)(void *node_data, void *param), void *param);
201
213node_t *list_index(list_t *list, int index);
214
223list_t *list_insert_end(list_t *list, node_t *node);
224
233list_t *list_insert_start(list_t *list, node_t *node);
234
246list_t *list_insert(list_t *list, node_t *node, int index);
247
255int list_remove_start(list_t *list);
256
264int list_remove_end(list_t *list);
265
274int list_remove_ptrnode(list_t *list, node_t *node);
275
284int list_remove_ptrdata(list_t *list, void *ptrdata);
285
286#endif
node_t * start
Definition tlcllists.h:24
int len
Definition tlcllists.h:26
node_t * end
Definition tlcllists.h:25
node_t * next
Definition tlcllists.h:16
void(* destroy)(void *data)
Definition tlcllists.h:18
void * data
Definition tlcllists.h:17
node_t * node_ptr
Definition tlcllists.h:31
list_t * list_duplicate(list_t *list)
duplicate list
int list_remove_ptrdata(list_t *list, void *ptrdata)
remove node where node data is ptdrdata
int list_remove_ptrnode(list_t *list, node_t *node)
remove node where its ptr is node
int list_find_ptrnode(list_t *list, node_t *node_ptr)
find node index that have node == node_ptr
int list_remove_start(list_t *list)
remove the first node of list
node_result_t list_find_f(list_t *list, bool(is_this_result)(void *node_data, void *param), void *param)
find node where is_this_result(node->data, param) = 1
list_t * list_insert_start(list_t *list, node_t *node)
insert node at start of list
list_t * list_create(void)
create an empty list
void list_delete(list_t *list)
delete the list
list_t * list_insert(list_t *list, node_t *node, int index)
insert node at index index
list_t * list_append(list_t *list, void *data, void(*destroy)(void *data), void *(*copy)(void *data))
append new data to list
node_t * list_index(list_t *list, int index)
return node at index index
list_t * list_insert_end(list_t *list, node_t *node)
insert node at end of list
node_result_t list_find_ptrdata(list_t *list, void *data)
find node that have a node->data == data
node_t * node_create(void *data, void(*destroy)(void *data), void *(*copy)(void *data))
create a node
int list_remove_end(list_t *list)
remove the last node of list