# HG changeset patch # User Mike Becker # Date 1668706379 -3600 # Node ID 85c08391a0906c3e979e847209db58fb9103609e # Parent 820ee59121b4849b55ede237f91f45c5e1e1ab6c #219 array list: implement remove diff -r 820ee59121b4 -r 85c08391a090 src/array_list.c --- a/src/array_list.c Thu Nov 17 18:29:59 2022 +0100 +++ b/src/array_list.c Thu Nov 17 18:32:59 2022 +0100 @@ -190,7 +190,29 @@ struct cx_list_s *list, size_t index ) { - return 1; + /* out-of-bounds check */ + if (index >= list->size) { + return 1; + } + + cx_array_list *arl = (cx_array_list *) list; + + /* just move the elements starting at index to the left */ + int result = cx_array_copy( + &arl->data, + &list->size, + &list->capacity, + index, + ((char *) arl->data) + (index + 1) * list->itemsize, + list->itemsize, + list->size - index, + &arl->reallocator + ); + if (result == 0) { + /* decrease the size */ + list->size--; + } + return result; } static void *cx_arl_at( diff -r 820ee59121b4 -r 85c08391a090 test/test_list.cpp --- a/test/test_list.cpp Thu Nov 17 18:29:59 2022 +0100 +++ b/test/test_list.cpp Thu Nov 17 18:32:59 2022 +0100 @@ -852,7 +852,6 @@ } TEST_F(ArrayList, cxListRemove) { - ASSERT_EQ(1,0); // TODO: remove when implemented verifyRemove(arrayListFromTestData()); }