ucx/list.c

changeset 101
7b3a3130be44
parent 49
2f71f4ee247a
equal deleted inserted replaced
100:d2bd73d28ff1 101:7b3a3130be44
57 struct cx_collection_s *l = (struct cx_collection_s*) &list->collection; 57 struct cx_collection_s *l = (struct cx_collection_s*) &list->collection;
58 l->cmpfunc = cx_pl_cmpfunc_impl; 58 l->cmpfunc = cx_pl_cmpfunc_impl;
59 } 59 }
60 60
61 static void cx_pl_destructor(struct cx_list_s *list) { 61 static void cx_pl_destructor(struct cx_list_s *list) {
62 list->climpl->destructor(list); 62 list->climpl->deallocate(list);
63 } 63 }
64 64
65 static int cx_pl_insert_element( 65 static int cx_pl_insert_element(
66 struct cx_list_s *list, 66 struct cx_list_s *list,
67 size_t index, 67 size_t index,
97 ) { 97 ) {
98 struct cx_list_s *list = iter->src_handle.m; 98 struct cx_list_s *list = iter->src_handle.m;
99 return list->climpl->insert_iter(iter, &elem, prepend); 99 return list->climpl->insert_iter(iter, &elem, prepend);
100 } 100 }
101 101
102 static int cx_pl_remove( 102 static size_t cx_pl_remove(
103 struct cx_list_s *list, 103 struct cx_list_s *list,
104 size_t index 104 size_t index,
105 ) { 105 size_t num,
106 return list->climpl->remove(list, index); 106 void *targetbuf
107 ) {
108 return list->climpl->remove(list, index, num, targetbuf);
107 } 109 }
108 110
109 static void cx_pl_clear(struct cx_list_s *list) { 111 static void cx_pl_clear(struct cx_list_s *list) {
110 list->climpl->clear(list); 112 list->climpl->clear(list);
111 } 113 }
208 210
209 // </editor-fold> 211 // </editor-fold>
210 212
211 // <editor-fold desc="empty list implementation"> 213 // <editor-fold desc="empty list implementation">
212 214
213 static void cx_emptyl_noop(__attribute__((__unused__)) CxList *list) { 215 static void cx_emptyl_noop(cx_attr_unused CxList *list) {
214 // this is a noop, but MUST be implemented 216 // this is a noop, but MUST be implemented
215 } 217 }
216 218
217 static void *cx_emptyl_at( 219 static void *cx_emptyl_at(
218 __attribute__((__unused__)) const struct cx_list_s *list, 220 cx_attr_unused const struct cx_list_s *list,
219 __attribute__((__unused__)) size_t index 221 cx_attr_unused size_t index
220 ) { 222 ) {
221 return NULL; 223 return NULL;
222 } 224 }
223 225
224 static ssize_t cx_emptyl_find_remove( 226 static ssize_t cx_emptyl_find_remove(
225 __attribute__((__unused__)) struct cx_list_s *list, 227 cx_attr_unused struct cx_list_s *list,
226 __attribute__((__unused__)) const void *elem, 228 cx_attr_unused const void *elem,
227 __attribute__((__unused__)) bool remove 229 cx_attr_unused bool remove
228 ) { 230 ) {
229 return -1; 231 return -1;
230 } 232 }
231 233
232 static bool cx_emptyl_iter_valid(__attribute__((__unused__)) const void *iter) { 234 static bool cx_emptyl_iter_valid(cx_attr_unused const void *iter) {
233 return false; 235 return false;
234 } 236 }
235 237
236 static CxIterator cx_emptyl_iterator( 238 static CxIterator cx_emptyl_iterator(
237 const struct cx_list_s *list, 239 const struct cx_list_s *list,
238 size_t index, 240 size_t index,
239 __attribute__((__unused__)) bool backwards 241 cx_attr_unused bool backwards
240 ) { 242 ) {
241 CxIterator iter = {0}; 243 CxIterator iter = {0};
242 iter.src_handle.c = list; 244 iter.src_handle.c = list;
243 iter.index = index; 245 iter.index = index;
244 iter.base.valid = cx_emptyl_iter_valid; 246 iter.base.valid = cx_emptyl_iter_valid;
293 ) { 295 ) {
294 size_t elem_size = list->collection.elem_size; 296 size_t elem_size = list->collection.elem_size;
295 const char *src = data; 297 const char *src = data;
296 size_t i = 0; 298 size_t i = 0;
297 for (; i < n; i++) { 299 for (; i < n; i++) {
298 if (0 != invoke_list_func(insert_element, 300 if (0 != invoke_list_func(
299 list, index + i, src + (i * elem_size))) { 301 insert_element, list, index + i,
300 return i; 302 src + (i * elem_size))) return i;
301 }
302 } 303 }
303 return i; 304 return i;
304 } 305 }
305 306
306 size_t cx_list_default_insert_sorted( 307 size_t cx_list_default_insert_sorted(
341 ins++; 342 ins++;
342 } 343 }
343 344
344 // insert the elements at location si 345 // insert the elements at location si
345 if (ins == 1) { 346 if (ins == 1) {
346 if (0 != invoke_list_func(insert_element, 347 if (0 != invoke_list_func(
347 list, di, src)) 348 insert_element, list, di, src)) return inserted;
348 return inserted;
349 } else { 349 } else {
350 size_t r = invoke_list_func(insert_array, list, di, src, ins); 350 size_t r = invoke_list_func(insert_array, list, di, src, ins);
351 if (r < ins) return inserted + r; 351 if (r < ins) return inserted + r;
352 } 352 }
353 inserted += ins; 353 inserted += ins;
413 memcpy(jp, tmp, elem_size); 413 memcpy(jp, tmp, elem_size);
414 414
415 free(tmp); 415 free(tmp);
416 416
417 return 0; 417 return 0;
418 }
419
420 void cxListDestroy(CxList *list) {
421 list->cl->destructor(list);
422 } 418 }
423 419
424 int cxListCompare( 420 int cxListCompare(
425 const CxList *list, 421 const CxList *list,
426 const CxList *other 422 const CxList *other
483 ) { 479 ) {
484 CxIterator it = list->cl->iterator(list, index, true); 480 CxIterator it = list->cl->iterator(list, index, true);
485 it.base.mutating = true; 481 it.base.mutating = true;
486 return it; 482 return it;
487 } 483 }
484
485 void cxListFree(CxList *list) {
486 if (list == NULL) return;
487 list->cl->deallocate(list);
488 }

mercurial