remove cxListLast (can be realized via cxListAt and index=size-1)

Sat, 09 Oct 2021 11:12:48 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 09 Oct 2021 11:12:48 +0200
changeset 474
9c1fccda16bc
parent 473
1bd4b8c28722
child 475
31bf97fdbf71

remove cxListLast (can be realized via cxListAt and index=size-1)

src/cx/list.h file | annotate | diff | comparison | revisions
src/linked_list.c file | annotate | diff | comparison | revisions
test/test_list.c file | annotate | diff | comparison | revisions
--- a/src/cx/list.h	Fri Oct 08 19:47:31 2021 +0200
+++ b/src/cx/list.h	Sat Oct 09 11:12:48 2021 +0200
@@ -84,11 +84,6 @@
     size_t (*find)(cx_list_s *list, void *elem);
 
     /**
-     * Member function for retrieving the last element.
-     */
-    void *(*last)(cx_list_s *list);
-
-    /**
      * Member function for sorting the list in place.
      */
     void (*sort)(cx_list_s *list);
@@ -200,20 +195,6 @@
 }
 
 /**
- * Returns a pointer to the last element of the list.
- *
- * This is effectively the same as cxListAt() with \c index=size-1, but
- * this implementation may be more efficient depending on the list structure
- * and the conrecte implementation of cxListAt().
- *
- * @param list the list
- * @return a pointer to the last element or \c NULL if the list is empty
- */
-static inline void *cxListLast(CxList list) {
-    return list->cl->last(list);
-}
-
-/**
  * Sorts the list in place.
  *
  * \remark The underlying sort algorithm is implementation defined.
--- a/src/linked_list.c	Fri Oct 08 19:47:31 2021 +0200
+++ b/src/linked_list.c	Sat Oct 09 11:12:48 2021 +0200
@@ -456,18 +456,6 @@
     return index;
 }
 
-static void *cx_ll_last(cx_list_s *list) {
-    cx_linked_list *ll = (cx_linked_list *) list;
-    cx_linked_list_node *last = ll->end;
-    return last == NULL ? NULL : last->payload;
-}
-
-static void *cx_pll_last(cx_list_s *list) {
-    cx_linked_list *ll = (cx_linked_list *) list;
-    cx_linked_list_node *last = ll->end;
-    return last == NULL ? NULL : *(void **) last->payload;
-}
-
 static void cx_ll_sort(cx_list_s *list) {
     cx_linked_list *ll = (cx_linked_list *) list;
     cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end,
@@ -488,7 +476,6 @@
         cx_ll_remove,
         cx_ll_at,
         cx_ll_find,
-        cx_ll_last,
         cx_ll_sort
 };
 
@@ -498,7 +485,6 @@
         cx_ll_remove,
         cx_pll_at,
         cx_pll_find,
-        cx_pll_last,
         cx_pll_sort
 };
 
--- a/test/test_list.c	Fri Oct 08 19:47:31 2021 +0200
+++ b/test/test_list.c	Sat Oct 09 11:12:48 2021 +0200
@@ -397,26 +397,6 @@
     CU_ASSERT_TRUE(cxTestingAllocatorVerify())
 }
 
-void test_hl_linked_list_last(void) {
-    cxTestingAllocatorReset();
-
-    int data;
-    CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int));
-
-    CU_ASSERT_PTR_NULL(cxListLast(list))
-
-    data = 5;
-    CU_ASSERT_EQUAL(cxListAdd(list, &data), 0)
-    CU_ASSERT_EQUAL(*(int *) cxListLast(list), 5)
-
-    data = 47;
-    CU_ASSERT_EQUAL(cxListAdd(list, &data), 0)
-    CU_ASSERT_EQUAL(*(int *) cxListLast(list), 47)
-
-    cxLinkedListDestroy(list);
-    CU_ASSERT_TRUE(cxTestingAllocatorVerify())
-}
-
 void test_hl_linked_list_insert(void) {
     cxTestingAllocatorReset();
 
@@ -609,23 +589,6 @@
     CU_ASSERT_TRUE(cxTestingAllocatorVerify())
 }
 
-void test_hl_ptr_linked_list_last(void) {
-    cxTestingAllocatorReset();
-
-    CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int);
-    CU_ASSERT_PTR_NULL(cxListLast(list))
-
-    int a = 5, b = 47;
-
-    CU_ASSERT_EQUAL(cxListAdd(list, &a), 0)
-    CU_ASSERT_EQUAL(*(int *) cxListLast(list), 5)
-    CU_ASSERT_EQUAL(cxListAdd(list, &b), 0)
-    CU_ASSERT_EQUAL(*(int *) cxListLast(list), 47)
-
-    cxLinkedListDestroy(list);
-    CU_ASSERT_TRUE(cxTestingAllocatorVerify())
-}
-
 void test_hl_ptr_linked_list_insert(void) {
     cxTestingAllocatorReset();
 
@@ -787,7 +750,6 @@
 
     cu_add_test(suite, test_hl_linked_list_create);
     cu_add_test(suite, test_hl_linked_list_add);
-    cu_add_test(suite, test_hl_linked_list_last);
     cu_add_test(suite, test_hl_linked_list_insert);
     cu_add_test(suite, test_hl_linked_list_remove);
     cu_add_test(suite, test_hl_linked_list_find);
@@ -797,7 +759,6 @@
 
     cu_add_test(suite, test_hl_ptr_linked_list_create);
     cu_add_test(suite, test_hl_ptr_linked_list_add);
-    cu_add_test(suite, test_hl_ptr_linked_list_last);
     cu_add_test(suite, test_hl_ptr_linked_list_insert);
     cu_add_test(suite, test_hl_ptr_linked_list_remove);
     cu_add_test(suite, test_hl_ptr_linked_list_find);

mercurial