96 ptrdiff_t loc_prev; |
96 ptrdiff_t loc_prev; |
97 ptrdiff_t loc_next; |
97 ptrdiff_t loc_next; |
98 } cx_linked_list; |
98 } cx_linked_list; |
99 |
99 |
100 int cx_ll_add(cx_list_s *list, void *elem) { |
100 int cx_ll_add(cx_list_s *list, void *elem) { |
101 cx_linked_list *linkedlist = (cx_linked_list *) list; |
101 cx_linked_list *ll = (cx_linked_list *) list; |
102 |
102 |
103 struct cx_linked_list_node *node = cxMalloc(list->allocator, |
103 struct cx_linked_list_node *node = cxMalloc(list->allocator, |
104 sizeof(struct cx_linked_list_node) + list->itemsize); |
104 sizeof(struct cx_linked_list_node) + list->itemsize); |
105 if (node == NULL) |
105 if (node == NULL) |
106 return 1; |
106 return 1; |
107 |
107 |
108 node->next = node->prev = NULL; |
108 node->next = node->prev = NULL; |
109 memcpy(node->payload, elem, list->itemsize); |
109 memcpy(node->payload, elem, list->itemsize); |
110 |
110 |
111 int ret = cx_linked_list_add( |
111 int ret = cx_linked_list_add( |
112 &linkedlist->begin, |
112 &ll->begin, &ll->end, |
113 &linkedlist->end, |
|
114 offsetof(struct cx_linked_list_node, prev), |
113 offsetof(struct cx_linked_list_node, prev), |
115 offsetof(struct cx_linked_list_node, next), |
114 offsetof(struct cx_linked_list_node, next), |
116 node |
115 node |
117 ); |
116 ); |
118 if (ret == 0) { |
117 if (ret == 0) { |
122 return ret; |
121 return ret; |
123 } |
122 } |
124 } |
123 } |
125 |
124 |
126 int cx_ll_insert(cx_list_s *list, size_t index, void *elem) { |
125 int cx_ll_insert(cx_list_s *list, size_t index, void *elem) { |
127 cx_linked_list *linkedList = (cx_linked_list *) list; |
126 cx_linked_list *ll = (cx_linked_list *) list; |
128 // TODO: implement using low level API |
127 // TODO: implement using low level API |
129 return 1; |
128 return 1; |
130 } |
129 } |
131 |
130 |
132 void *cx_ll_remove(cx_list_s *list, size_t index) { |
131 void *cx_ll_remove(cx_list_s *list, size_t index) { |
133 cx_linked_list *linkedList = (cx_linked_list *) list; |
132 cx_linked_list *ll = (cx_linked_list *) list; |
134 // TODO: implement using low level API |
133 // TODO: implement using low level API |
135 return NULL; |
134 return NULL; |
136 } |
135 } |
137 |
136 |
138 size_t cx_ll_find(cx_list_s *list, void *elem) { |
137 size_t cx_ll_find(cx_list_s *list, void *elem) { |
139 cx_linked_list *linkedList = (cx_linked_list *) list; |
138 CxListComparator cmp = list->cmpfunc; |
140 // TODO: implement using low level API |
139 cx_linked_list *ll = (cx_linked_list *) list; |
141 return 0; |
140 |
|
141 size_t index; |
|
142 struct cx_linked_list_node* node = ll->begin; |
|
143 for (index = 0 ; index < list->size ; index++) { |
|
144 void* current = node->payload; |
|
145 if (cmp(current, elem) == 0) { |
|
146 return index; |
|
147 } |
|
148 node = node->next; |
|
149 } |
|
150 return index; |
142 } |
151 } |
143 |
152 |
144 void *cx_ll_last(cx_list_s *list) { |
153 void *cx_ll_last(cx_list_s *list) { |
145 cx_linked_list *linkedList = (cx_linked_list *) list; |
154 cx_linked_list *linkedList = (cx_linked_list *) list; |
146 struct cx_linked_list_node *last = cx_linked_list_last( |
155 struct cx_linked_list_node *last = cx_linked_list_last( |