forked from WojciechMula/pyahocorasick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slist.h
70 lines (48 loc) · 1.41 KB
/
slist.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
/*
This is part of pyahocorasick Python module.
Linked list declarations.
Const time of:
* append
* prepend
* pop first
* get first/last
Author : Wojciech Muła, [email protected]
WWW : http://0x80.pl
License : public domain
*/
#ifndef ahocorasick_slist_h_included
#define ahocorasick_slist_h_included
#include "common.h"
/** base structure for list */
#define LISTITEM_data struct ListItem* __next
/** list item node */
typedef struct ListItem {
LISTITEM_data;
} ListItem;
/** Create new item */
ListItem* list_item_new(const size_t size);
/** Deallocate list item. */
void list_item_delete(ListItem* item);
/** Returns pointer to next item */
#define list_item_next(item) (((ListItem*)(item))->__next)
/** Set new pointer to next item */
#define list_item_setnext(item, next) list_item_next(item) = (ListItem*)(next)
/** List.
*/
typedef struct {
ListItem* head; ///< first node
ListItem* last; ///< last node
} List;
/** Initialize list. */
void list_init(List* list);
/** Deallocate all elements of list. */
int list_delete(List* list);
/** Append item at the end of list. */
ListItem* list_append(List* list, ListItem* item);
/** Prepend item at front of list. */
ListItem* list_push_front(List* list, ListItem* item);
/** Unlink first item from list. */
ListItem* list_pop_first(List* list);
/** Test if list is empty. */
#define list_empty(list) ((list)->head == NULL)
#endif