2016-04-17 16:16:00 +00:00
|
|
|
#ifndef lcthw_List_h
|
|
|
|
#define lcthw_List_h
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2016-04-17 16:25:52 +00:00
|
|
|
#include <assert.h>
|
2016-04-17 16:16:00 +00:00
|
|
|
|
|
|
|
struct ListNode;
|
|
|
|
|
|
|
|
typedef struct ListNode {
|
|
|
|
struct ListNode *next;
|
|
|
|
struct ListNode *prev;
|
|
|
|
void *value;
|
|
|
|
} ListNode;
|
|
|
|
|
|
|
|
typedef struct List {
|
|
|
|
int count;
|
|
|
|
ListNode *first;
|
|
|
|
ListNode *last;
|
|
|
|
} List;
|
|
|
|
|
|
|
|
List *List_create();
|
|
|
|
void List_destroy(List *list);
|
|
|
|
void List_clear(List *list);
|
|
|
|
void List_clear_destroy(List *list);
|
|
|
|
|
|
|
|
#define List_count(A) ((A)->count)
|
|
|
|
#define List_first(A) ((A)->first != NULL ? (A)->first->value : NULL)
|
|
|
|
#define List_last(A) ((A)->last != NULL ? (A)->last->value : NULL)
|
|
|
|
|
|
|
|
void List_push(List *list, void *value);
|
|
|
|
void *List_pop(List *list);
|
|
|
|
|
|
|
|
void List_unshift(List *list, void *value);
|
|
|
|
void *List_shift(List *list);
|
|
|
|
|
|
|
|
void *List_remove(List *list, ListNode *node);
|
|
|
|
|
2016-04-17 17:50:26 +00:00
|
|
|
List *List_copy(List *list);
|
|
|
|
int List_split(List *list, void *split, List *a, List *b);
|
|
|
|
void List_join(List *list, List *b);
|
2016-04-17 22:55:43 +00:00
|
|
|
void List_swap(ListNode *a, ListNode *b);
|
|
|
|
void List_dump(List *list);
|
2016-04-17 17:50:26 +00:00
|
|
|
|
2016-04-17 16:25:52 +00:00
|
|
|
#define List_validate(A) (assert(A != NULL && List_count(A) > -1 &&\
|
|
|
|
(List_count(A) > 0 && List_first(A) != NULL) && "invalid *List"))
|
|
|
|
|
2016-04-17 22:55:43 +00:00
|
|
|
#define LIST_FOREACH(L, F, N, C) ListNode *_node = NULL;\
|
|
|
|
ListNode *C = NULL;\
|
|
|
|
for(C = _node = L->F; _node != NULL; C = _node = _node->N)
|
2016-04-17 16:16:00 +00:00
|
|
|
|
|
|
|
#endif
|