#219 array list: implement find

Thu, 17 Nov 2022 18:46:55 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 17 Nov 2022 18:46:55 +0100
changeset 614
7aaec630cf15
parent 613
85c08391a090
child 615
b52b66dcd44b

#219 array list: implement find

src/array_list.c file | annotate | diff | comparison | revisions
test/test_list.cpp file | annotate | diff | comparison | revisions
--- a/src/array_list.c	Thu Nov 17 18:32:59 2022 +0100
+++ b/src/array_list.c	Thu Nov 17 18:46:55 2022 +0100
@@ -232,7 +232,16 @@
         struct cx_list_s const *list,
         void const *elem
 ) {
-    return 0;
+    char *cur = ((cx_array_list const *) list)->data;
+
+    for (size_t i = 0; i < list->size; i++) {
+        if (0 == list->cmpfunc(elem, cur)) {
+            return i;
+        }
+        cur += list->itemsize;
+    }
+
+    return list->size;
 }
 
 static void cx_arl_sort(struct cx_list_s *list) {
--- a/test/test_list.cpp	Thu Nov 17 18:32:59 2022 +0100
+++ b/test/test_list.cpp	Thu Nov 17 18:46:55 2022 +0100
@@ -876,7 +876,6 @@
 }
 
 TEST_F(ArrayList, cxListFind) {
-    ASSERT_EQ(1,0); // TODO: remove when implemented
     verifyFind(arrayListFromTestData());
 }
 

mercurial