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
     1.1 --- a/src/cx/list.h	Sun Feb 07 21:14:39 2021 +0100
     1.2 +++ b/src/cx/list.h	Sun Feb 07 21:26:48 2021 +0100
     1.3 @@ -51,11 +51,14 @@
     1.4  
     1.5  typedef size_t (*cx_list_find)(cx_list *list, void *elem);
     1.6  
     1.7 +typedef void *(*cx_list_last)(cx_list *list);
     1.8 +
     1.9  typedef struct {
    1.10      cx_list_add add;
    1.11      cx_list_insert insert;
    1.12      cx_list_remove remove;
    1.13      cx_list_find find;
    1.14 +    cx_list_last last;
    1.15  } cx_list_class;
    1.16  
    1.17  struct cx_list_s {
    1.18 @@ -73,4 +76,6 @@
    1.19  
    1.20  size_t cxListFind(CxList list, void *elem);
    1.21  
    1.22 +void *cxListLast(CxList list);
    1.23 +
    1.24  #endif /* UCX_LIST_H */
     2.1 --- a/src/linked_list.c	Sun Feb 07 21:14:39 2021 +0100
     2.2 +++ b/src/linked_list.c	Sun Feb 07 21:26:48 2021 +0100
     2.3 @@ -135,12 +135,19 @@
     2.4      return 0;
     2.5  }
     2.6  
     2.7 +void *cx_ll_last(cx_list *list) {
     2.8 +    cx_linked_list *ll = list->listdata;
     2.9 +    struct cx_linked_list_node *last = cx_linked_list_last(
    2.10 +            NULL, &ll->end, offsetof(struct cx_linked_list_node, next));
    2.11 +    return &last->payload;
    2.12 +}
    2.13  
    2.14  cx_list_class cx_linked_list_class = {
    2.15          cx_ll_add,
    2.16          cx_ll_insert,
    2.17          cx_ll_remove,
    2.18 -        cx_ll_find
    2.19 +        cx_ll_find,
    2.20 +        cx_ll_last
    2.21  };
    2.22  
    2.23  CxList cxLinkedListCreate(CxAllocator allocator, CxListComparator comparator, size_t itemsize) {
     3.1 --- a/src/list.c	Sun Feb 07 21:14:39 2021 +0100
     3.2 +++ b/src/list.c	Sun Feb 07 21:26:48 2021 +0100
     3.3 @@ -43,3 +43,7 @@
     3.4  size_t cxListFind(CxList list, void *elem) {
     3.5      return list->cl->find(&list->data, elem);
     3.6  }
     3.7 +
     3.8 +void *cxListLast(CxList list) {
     3.9 +    return list->cl->last(&list->data);
    3.10 +}

mercurial