-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.h
102 lines (81 loc) · 2 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
100
101
102
#ifndef LIST_H
#define LIST_H
#include <stdlib.h>
typedef struct list_t
{
size_t el_size;
void* data;
size_t count;
size_t capacity;
size_t prealloc;
} list_t;
/*
Initialize a new empty list with custom settings.
It's safe to call list_free() afterwards even if no items were added to it.
Parameters:
list - pointer to an uninitialized list
el_size - size of an element
prealloc - number of elements to preallocate space for
*/
void list_init_ex(list_t* list, size_t el_size, size_t prealloc);
/*
Initialize a new empty list with default settings.
It's safe to call list_free() afterwards even if no items were added to it.
Parameters:
list - pointer to an uninitialized list
*/
void list_init(list_t* list, size_t el_size);
/*
Initialize a new list, copying data and settings from another.
Parameters:
list - pointer to an uninitialized list
other - list to be copied
Return:
1 - success
0 - no memory
*/
int list_init_copy(list_t* list, const list_t* other);
/*
Add elements to a list.
If this operation fails, contents of list remain in the same state as before.
Parameters:
list - destination list
el - pointer to elements
count - number of elements to be added, a value of 0 has no effect
Return:
1 - success
0 - no memory
*/
int list_add(list_t* list, const void* el, size_t count);
/*
Remove an element from a list.
Parameters:
list - list
index - index of target element, must be smaller than list->count
*/
void list_remove(list_t* list, size_t index);
/*
Shrink a lists memory to only contain as little memory as needed.
Parameters:
list - list
Return:
1 - success
0 - no memory
*/
int list_shrink(list_t* list);
/*
Move other to list.
It's safe to call list_free() on other afterwards.
Parameters:
list - destination list
other - other list
*/
void list_move(list_t* list, list_t* other);
/*
Free a list.
Has to be called when you're done with a list after calling list_init*().
Parameters:
list - list
*/
void list_free(list_t* list);
#endif