-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.h
More file actions
76 lines (65 loc) · 2.12 KB
/
list.h
File metadata and controls
76 lines (65 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef LIST_H
# define LIST_H
/**
** Structure of a list, NULL is considered as an empty list.
**/
struct list
{
void *data;
struct list *next;
};
/**
** Applies the function <fn> on all elements of the list.
**/
void list_foreach(const struct list *l, void (*fn)(const void *));
/**
** Free the list (but not the elements contained in it).
**/
void list_free(struct list *l);
/**
** Add an element to the head of the list.
**/
struct list *list_add(struct list *l, void *e);
/**
** Find an element in the list. Returns the list beginning by this element.
** If the element is not found, returns NULL.
**/
const struct list *list_find(const struct list *l,
const void *e,
int(*cmp_fn)(const void *left, const void *right));
/**
** Applies the function <map_fn> on the list. Returns a new list with the
** new values.
**/
struct list *list_map(const struct list *l, void *(map_fn)(const void *));
/**
** Copies a list. This function does not copy the list data.
**/
struct list *list_copy(const struct list *l, struct list **tail);
/**
** Flatten a list of list (change the depth of a list from n to n - 1) and
** then returns the new list.
**/
struct list *list_flatten(const struct list *l);
/**
** Applies the function <map_fn> on all elements of the list, then flatten
** it. The temporary list must be freed using the <free_internal_mapped_list_fn>
** function. The function returns the new list.
**/
struct list *list_flatmap(const struct list *l,
void *(*map_fn)(const void *),
void (*free_internal_mapped_list_fn)(void *));
/**
** Returns a new list with all elements complying with the <predicate_fn>
** function.
**/
struct list *list_filter(const struct list *l,
int (*predicate_fn)(const void *));
/**
** Reduce the list to a single element using the <reduce_fn> function. If the
** list is null, <init> must be return.
**/
void *list_reduce(struct list *l,
void *init,
void *(*reduce_fn)(const void *element, void *accumulator));
#endif /* ! LIST_H */