adds cxListLast

Sun, 07 Feb 2021 21:26:48 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 07 Feb 2021 21:26:48 +0100
changeset 404
86ebc3745e62
parent 403
8fa43b732980
child 405
44efaa54d63d

adds cxListLast

src/cx/list.h file | annotate | diff | comparison | revisions
src/linked_list.c file | annotate | diff | comparison | revisions
src/list.c file | annotate | diff | comparison | revisions
--- 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 */
--- 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) {
--- 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);
+}

mercurial