-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlist.h
75 lines (65 loc) · 1.64 KB
/
list.h
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
#ifndef LIST_H_
#define LIST_H_
#include <stdio.h>
/* List node pointer. */
typedef struct _node* ListNodePtr;
/* Alias to list node, for defining lists. */
typedef ListNodePtr List;
typedef struct _node {
void* data;
ListNodePtr next;
} ListNode;
/**
* Append a node to the tail of a list.
*
* @param list
* The list head.
* @param data
* Pointer to the data structure.
*
* @return
* Pointer to the head of the list.
*/
List list_append(List list, void* data);
/**
* Add a node to an ordered list.
*
* @param list
* The list head.
* @param data
* Pointer to the data structure.
* @param _compare
* Pointer to a callback function receiving two data structures and returning
* an integer specifying which one of them supposed to be first.
* @param _duplicate
* Optional pointer to function that will be triggered if a duplicated
* element will be inserted.
*
* @return
* Pointer to the head of the list.
*/
List list_add_ordered(List list, void* data, int(*_compare)(void*, void*), void(*_duplicate)(void*));
/**
* Iterate a list and perform a call-back function on each node.
*
* @param list
* The list head.
* @param _callback
* Call-back function to perform on the node's data.
*/
void list_foreach(List list, void(*_callback)(void*));
/**
* Free all the nodes and data from a list.
*
* @param list
* The list head.
* @param _free_data
* Call-back function freeing the data of each node.
*/
void list_destruct(List list, void(*_free_data)(void*));
/**
* Find identical item to the given item.
* @param
*/
void* list_find_item(List list, void* item, int(*_compare)(void*, void*));
#endif