# HG changeset patch # User Mike Becker # Date 1612729608 -3600 # Node ID 86ebc3745e620843895ec6ada07ada74d69478f0 # Parent 8fa43b732980d0d2eded3241d807363ac254df45 adds cxListLast diff -r 8fa43b732980 -r 86ebc3745e62 src/cx/list.h --- a/src/cx/list.h Sun Feb 07 21:14:39 2021 +0100 +++ b/src/cx/list.h Sun Feb 07 21:26:48 2021 +0100 @@ -51,11 +51,14 @@ typedef size_t (*cx_list_find)(cx_list *list, void *elem); +typedef void *(*cx_list_last)(cx_list *list); + typedef struct { cx_list_add add; cx_list_insert insert; cx_list_remove remove; cx_list_find find; + cx_list_last last; } cx_list_class; struct cx_list_s { @@ -73,4 +76,6 @@ size_t cxListFind(CxList list, void *elem); +void *cxListLast(CxList list); + #endif /* UCX_LIST_H */ diff -r 8fa43b732980 -r 86ebc3745e62 src/linked_list.c --- a/src/linked_list.c Sun Feb 07 21:14:39 2021 +0100 +++ b/src/linked_list.c Sun Feb 07 21:26:48 2021 +0100 @@ -135,12 +135,19 @@ return 0; } +void *cx_ll_last(cx_list *list) { + cx_linked_list *ll = list->listdata; + struct cx_linked_list_node *last = cx_linked_list_last( + NULL, &ll->end, offsetof(struct cx_linked_list_node, next)); + return &last->payload; +} cx_list_class cx_linked_list_class = { cx_ll_add, cx_ll_insert, cx_ll_remove, - cx_ll_find + cx_ll_find, + cx_ll_last }; CxList cxLinkedListCreate(CxAllocator allocator, CxListComparator comparator, size_t itemsize) { diff -r 8fa43b732980 -r 86ebc3745e62 src/list.c --- a/src/list.c Sun Feb 07 21:14:39 2021 +0100 +++ b/src/list.c Sun Feb 07 21:26:48 2021 +0100 @@ -43,3 +43,7 @@ size_t cxListFind(CxList list, void *elem) { return list->cl->find(&list->data, elem); } + +void *cxListLast(CxList list) { + return list->cl->last(&list->data); +}