1 /* 2 This is part of pyahocorasick Python module. 3 4 Linked list declarations. 5 6 Const time of: 7 * append 8 * prepend 9 * pop first 10 * get first/last 11 12 Author : Wojciech Muła, wojciech_mula@poczta.onet.pl 13 WWW : http://0x80.pl 14 License : public domain 15 */ 16 #ifndef ahocorasick_slist_h_included 17 #define ahocorasick_slist_h_included 18 19 #include "common.h" 20 21 /** base structure for list */ 22 #define LISTITEM_data struct ListItem* __next 23 24 /** list item node */ 25 typedef struct ListItem { 26 LISTITEM_data; 27 } ListItem; 28 29 /** Create new item */ 30 ListItem* list_item_new(const size_t size); 31 32 /** Deallocate list item. */ 33 void list_item_delete(ListItem* item); 34 35 /** Returns pointer to next item */ 36 #define list_item_next(item) (((ListItem*)(item))->__next) 37 38 /** Set new pointer to next item */ 39 #define list_item_setnext(item, next) list_item_next(item) = (ListItem*)(next) 40 41 42 /** List. 43 44 */ 45 typedef struct { 46 ListItem* head; ///< first node 47 ListItem* last; ///< last node 48 } List; 49 50 51 /** Initialize list. */ 52 void list_init(List* list); 53 54 /** Deallocate all elements of list. */ 55 int list_delete(List* list); 56 57 /** Append item at the end of list. */ 58 ListItem* list_append(List* list, ListItem* item); 59 60 /** Prepend item at front of list. */ 61 ListItem* list_push_front(List* list, ListItem* item); 62 63 /** Unlink first item from list. */ 64 ListItem* list_pop_first(List* list); 65 66 /** Test if list is empty. */ 67 #define list_empty(list) ((list)->head == NULL) 68 69 70 #endif 71