Sun, 20 Nov 2022 16:28:03 +0100
#219 array list: implement compare member func
src/array_list.c | file | annotate | diff | comparison | revisions | |
test/test_list.cpp | file | annotate | diff | comparison | revisions |
--- a/src/array_list.c Sun Nov 20 16:22:50 2022 +0100 +++ b/src/array_list.c Sun Nov 20 16:28:03 2022 +0100 @@ -272,7 +272,21 @@ struct cx_list_s const *list, struct cx_list_s const *other ) { - + if (list->size == other->size) { + char const *left = ((cx_array_list const *) list)->data; + char const *right = ((cx_array_list const *) other)->data; + for (size_t i = 0; i < list->size; i++) { + int d = list->cmpfunc(left, right); + if (d != 0) { + return d; + } + left += list->itemsize; + right += other->itemsize; + } + return 0; + } else { + return list->size < other->size ? -1 : 1; + } } static void cx_arl_reverse(struct cx_list_s *list) {
--- a/test/test_list.cpp Sun Nov 20 16:22:50 2022 +0100 +++ b/test/test_list.cpp Sun Nov 20 16:28:03 2022 +0100 @@ -974,7 +974,6 @@ } TEST_F(ArrayList, cxListCompare) { - ASSERT_EQ(1,0); // TODO: remove when implemented auto left = arrayListFromTestData(); auto right = arrayListFromTestData(); verifyCompare(left, right);