538 void const *elem |
538 void const *elem |
539 ) { |
539 ) { |
540 return cx_ll_insert(list, list->size, elem); |
540 return cx_ll_insert(list, list->size, elem); |
541 } |
541 } |
542 |
542 |
|
543 static size_t cx_ll_add_array( |
|
544 struct cx_list_s *list, |
|
545 void const *array, |
|
546 size_t n |
|
547 ) { |
|
548 // TODO: redirect to cx_ll_insert_array |
|
549 cx_for_n (i, n) { |
|
550 if (cx_ll_add(list, ((char const *) array) + i * list->itemsize)) { |
|
551 return i; |
|
552 } |
|
553 } |
|
554 return n; |
|
555 } |
|
556 |
543 static int cx_pll_insert( |
557 static int cx_pll_insert( |
544 struct cx_list_s *list, |
558 struct cx_list_s *list, |
545 size_t index, |
559 size_t index, |
546 void const *elem |
560 void const *elem |
547 ) { |
561 ) { |
784 list->base.itemsize = sizeof(void *); |
800 list->base.itemsize = sizeof(void *); |
785 list->base.capacity = SIZE_MAX; |
801 list->base.capacity = SIZE_MAX; |
786 |
802 |
787 return (CxList *) list; |
803 return (CxList *) list; |
788 } |
804 } |
789 |
|
790 CxList *cxLinkedListFromArray( |
|
791 CxAllocator const *allocator, |
|
792 CxListComparator comparator, |
|
793 size_t item_size, |
|
794 size_t num_items, |
|
795 void const *array |
|
796 ) { |
|
797 CxList *list = cxLinkedListCreate(allocator, comparator, item_size); |
|
798 if (list == NULL) return NULL; |
|
799 cx_for_n (i, num_items) { |
|
800 if (0 != cxListAdd(list, ((const unsigned char *) array) + i * item_size)) { |
|
801 cx_ll_destructor(list); |
|
802 cxFree(allocator, list); |
|
803 return NULL; |
|
804 } |
|
805 } |
|
806 return list; |
|
807 } |
|