diff -r 9d4971ea0625 -r cd3069757010 src/linked_list.c --- a/src/linked_list.c Mon Sep 27 17:49:23 2021 +0200 +++ b/src/linked_list.c Mon Sep 27 18:33:30 2021 +0200 @@ -34,6 +34,16 @@ #define CX_LL_PTR(cur, off) ((void**)(((char*)cur)+off)) +void *cx_linked_list_at(void *start, size_t start_index, ptrdiff_t loc_advance, size_t index) { + size_t i = start_index; + void* cur = start; + while (i != index && cur != NULL) { + cur = *CX_LL_PTR(cur, loc_advance); + i < index ? i++ : i--; + } + return cur; +} + void *cx_linked_list_last(void **begin, void **end, ptrdiff_t loc_next) { if (end != NULL) { return *end; @@ -97,7 +107,7 @@ ptrdiff_t loc_next; } cx_linked_list; -int cx_ll_add(cx_list_s *list, void *elem) { +static int cx_ll_add(cx_list_s *list, void *elem) { cx_linked_list *ll = (cx_linked_list *) list; struct cx_linked_list_node *node = cxMalloc(list->allocator, @@ -122,19 +132,22 @@ } } -int cx_ll_insert(cx_list_s *list, size_t index, void *elem) { +static int cx_ll_insert(cx_list_s *list, size_t index, void *elem) { cx_linked_list *ll = (cx_linked_list *) list; // TODO: implement using low level API return 1; } -void *cx_ll_remove(cx_list_s *list, size_t index) { +static int cx_ll_remove(cx_list_s *list, size_t index) { + if (index >= list->size) { + return 1; + } cx_linked_list *ll = (cx_linked_list *) list; // TODO: implement using low level API - return NULL; + return 0; } -size_t cx_ll_find(cx_list_s *list, void *elem) { +static size_t cx_ll_find(cx_list_s *list, void *elem) { CxListComparator cmp = list->cmpfunc; cx_linked_list *ll = (cx_linked_list *) list; @@ -150,7 +163,7 @@ return index; } -void *cx_ll_last(cx_list_s *list) { +static void *cx_ll_last(cx_list_s *list) { cx_linked_list *linkedList = (cx_linked_list *) list; struct cx_linked_list_node *last = cx_linked_list_last( NULL, &linkedList->end, offsetof(struct cx_linked_list_node, next));