-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.h
99 lines (83 loc) · 2.03 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* File: list.h
* Author: Project2100
* Brief: A loosely OO implementation of a linked list, along with some useful
* methods. It is NOT thread-safe, nor async-signal safe.
*
* Created on 31 January 2018, 14:33
*/
#ifndef SITH_LIST_H
#define SITH_LIST_H
#ifdef __cplusplus
extern "C" {
#endif
#define SITH_NOTFOUND 1
typedef struct sith_linkedlist LinkedList;
/**
* Creates a new linked list. It is dynamically allocated
*
* @return A pointer to the new linked list
*/
LinkedList* CreateLinkedList();
/**
* Adds the data pointed by 'data' to the end of the given list
*
* @param this
* @param data
* @return
*/
int AppendToList(LinkedList* list, void* data);
/**
* Removes the first occurrence of the pointer 'data' in the given list
*
* @param this
* @param data
* @return
*/
int removeFirst(LinkedList* list, void* data);
/**
* Applies the function pointed by 'function' to each element of the given list.
* Depending on the 'mode' argument:
* - LLIST_SERIAL: Applications are done sequentially and in the order the
* elements are currently linked to the list
* - LLIST_PARALLEL: [UNIMPLEMENTED] Applications are concurrent
*
* @param this
* @param function
* @param parallel
* @return
*/
int ApplyOnList(LinkedList* list, void (*function)(const void*));
/**
* Empties the given list from its elements
*
* @param this the list to be emptied
* @return
*/
int EmptyLinkedList(LinkedList* this);
/**
* Frees all resources of a dynamically allocated linked list.
* Do not call on statically allocated lists
*
* @param list
* @return
*/
int DestroyLinkedList(LinkedList* list);
/**
* Returns the length of the given list
*
* @param list
* @return
*/
long GetLinkedListSize(LinkedList* list);
/**
* Removes the head from the given list and returns its data pointer
*
* @param list
* @return
*/
void* PopHeadFromList(LinkedList* list);
#ifdef __cplusplus
}
#endif
#endif /* SITH_LIST_H */