src/linked_list.c

changeset 403
8fa43b732980
parent 402
a34b93911956
child 404
86ebc3745e62
equal deleted inserted replaced
402:a34b93911956 403:8fa43b732980
80 /* HIGH LEVEL LINKED LIST IMPLEMENTATION */ 80 /* HIGH LEVEL LINKED LIST IMPLEMENTATION */
81 81
82 struct cx_linked_list_node { 82 struct cx_linked_list_node {
83 void *prev; 83 void *prev;
84 void *next; 84 void *next;
85 int payload; 85 char payload[];
86 }; 86 };
87 87
88 typedef struct { 88 typedef struct {
89 void *begin; 89 void *begin;
90 void *end; 90 void *end;
93 int cx_ll_add(cx_list *list, void *elem) { 93 int cx_ll_add(cx_list *list, void *elem) {
94 cx_linked_list *listdata = list->listdata; 94 cx_linked_list *listdata = list->listdata;
95 CxAllocator allocator = list->allocator; 95 CxAllocator allocator = list->allocator;
96 96
97 struct cx_linked_list_node *node = cxMalloc(allocator, 97 struct cx_linked_list_node *node = cxMalloc(allocator,
98 sizeof(struct cx_linked_list_node) - sizeof(int) + list->itemsize); 98 sizeof(struct cx_linked_list_node) + list->itemsize);
99 if (node == NULL) 99 if (node == NULL)
100 return 1; 100 return 1;
101 101
102 node->next = NULL; 102 node->next = NULL;
103 memcpy(&node->payload, elem, list->itemsize); 103 memcpy(&node->payload, elem, list->itemsize);

mercurial