-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.h
69 lines (51 loc) · 1.73 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
#ifndef _LIST_H
#define _LIST_H
#include "element.h"
#include <malloc.h>
#include <stdio.h>
#include <string.h>
typedef struct _list {
elem_t meta;
elem_t *head;
elem_t *tail;
}list_t;
/*****
** initialize an empty list_t
** must be called first after a new list_t is declared
*/ void list_init(list_t *l);
/*****
** if you won't use list l, you must call list_destroy to free memory
*/ void list_destroy(list_t *l);
/****
** list iterator func ***
*/
elem_t* list_first(list_t *l);
elem_t* list_end(list_t *l);
elem_t* list_next(elem_t *l);
/*****
** push a new element to the end of the list_t
** it's up to the client code to allocate and maintain memory of "element"
*/ void list_push_back(list_t *l, void *element, size_t bytes);
/*****
** push a new element to the front of the list_t
** it's up to the client code to allocate and maintain memory of "element"
*/ void list_push_front(list_t *l, void *element, size_t bytes);
/*****
** insert the element (pointer) into the list_t as the index-th element
** set "release" to non-zero if memory deallocation is desired
*/ void list_insert(list_t *l, size_t index, void *element, size_t bytes);
/*****
** return the index-th element in the list_t, or NULL when the list_t is empty
*/ void *list_index_of(list_t *l, size_t index);
/*****
** remove the index-th element (pointer) from the list_t
** set "release" to non-zero if memory deallocation is desired
*/ void list_erase(list_t *l, size_t index);
/*****
** remove all elements (pointers) from the list_t
** set "release" to non-zero if memory deallocation is desired
*/ void list_clear(list_t *l);
/*****
** return current number of elements in the list_t, or 0 when list_t is empty
*/ int list_size(list_t *l);
#endif