src/linked_list.c

changeset 412
af766caea48d
parent 409
5d167af0eadb
child 416
a79b2388db5e
equal deleted inserted replaced
411:2842f729caab 412:af766caea48d
154 cx_ll_find, 154 cx_ll_find,
155 cx_ll_last 155 cx_ll_last
156 }; 156 };
157 157
158 CxList cxLinkedListCreate(CxAllocator allocator, CxListComparator comparator, size_t item_size) { 158 CxList cxLinkedListCreate(CxAllocator allocator, CxListComparator comparator, size_t item_size) {
159 CxLinkedListDesc desc; 159 CxList list = cxMalloc(allocator, sizeof(cx_list_s) + sizeof(cx_linked_list));
160 desc.item_size = item_size;
161 desc.begin = NULL;
162 desc.loc_prev = offsetof(struct cx_linked_list_node, prev);
163 desc.loc_next = offsetof(struct cx_linked_list_node, next);
164
165 return cxLinkedListWrap(allocator, comparator, desc);
166 }
167
168 CxList cxLinkedListWrap(CxAllocator allocator, CxListComparator comparator, CxLinkedListDesc desc) {
169 CxList list = cxMalloc(allocator, sizeof(list) + sizeof(cx_linked_list));
170 if (list == NULL) 160 if (list == NULL)
171 return NULL; 161 return NULL;
172 162
173 list->cl = &cx_linked_list_class; 163 list->cl = &cx_linked_list_class;
174 list->data.allocator = allocator; 164 list->data.allocator = allocator;
175 list->data.cmpfunc = comparator; 165 list->data.cmpfunc = comparator;
176 list->data.itemsize = desc.item_size; 166 list->data.itemsize = item_size;
177 list->data.capacity = SIZE_MAX; 167 list->data.capacity = SIZE_MAX;
178 168
179 cx_linked_list *ll = (cx_linked_list *) list->data.listdata; 169 cx_linked_list *ll = (cx_linked_list *) list->data.listdata;
180 ll->begin = desc.begin; 170 ll->begin = NULL;
181 ll->loc_prev = desc.loc_prev; 171 ll->loc_prev = offsetof(struct cx_linked_list_node, prev);
182 ll->loc_next = desc.loc_next; 172 ll->loc_next = offsetof(struct cx_linked_list_node, next);
183 cxLinkedListRecalculateSize(list); 173 cxLinkedListRecalculateSize(list);
184 174
185 return list; 175 return list;
186 } 176 }
187 177

mercurial