diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0c11715..6c6e0ec 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,19 +1,20 @@ -add_subdirectory(./Scratchpad) -add_subdirectory(./allocator-interface) add_subdirectory(./FixedBuffer) -add_subdirectory(./dynamicbuffer) -add_subdirectory(./FreeList) -add_subdirectory(./BinaryTree) -add_subdirectory(./hashmap) -add_subdirectory(./QuadTree) -add_subdirectory(./threading) -add_subdirectory(./ThreadPool) -add_subdirectory(./regex) -add_subdirectory(./utf8) -add_subdirectory(./StringView) +add_subdirectory(./allocator-interface) add_subdirectory(./arraylist) -add_subdirectory(./argumentc) -add_subdirectory(./rand) add_subdirectory(./siphash) -add_subdirectory(./pointers) add_subdirectory(./dynamicarray) +add_subdirectory(./dynamicbuffer) +add_subdirectory(./hashmap) +add_subdirectory(./rand) +add_subdirectory(./utf8) +add_subdirectory(./pointers) +add_subdirectory(./StringView) +add_subdirectory(./ThreadPool) +add_subdirectory(./threading) +add_subdirectory(./FreeList) +add_subdirectory(./argumentc) +add_subdirectory(./Scratchpad) +add_subdirectory(./regex) +add_subdirectory(./QuadTree) +add_subdirectory(./BinaryTree) +add_subdirectory(./Subprocess) diff --git a/src/dynamicarray/dynamicarray.c b/src/dynamicarray/dynamicarray.c index 6a4255a..61f9075 100644 --- a/src/dynamicarray/dynamicarray.c +++ b/src/dynamicarray/dynamicarray.c @@ -257,17 +257,25 @@ size_t DynamicArray_FindFunctionLinear(DynamicArray* array, DynamicArrayLinearFi size_t mid = bot + (top - bot) / 2; int eval = -1; - while (bot != top) { + while (eval != 0 && mid != top && mid < array->reserved) { void* current = DynamicArray_GetPointer(array, mid); eval = function(current, xarg); - if (eval > 0) { - bot = mid + 1; + if (eval == 0) { + bot = top = mid; } else if (eval < 0) { top = mid - 1; } else { - bot = top; + bot = mid + 1; } + // TODO: Is there a bug with overlapping top and bot here? + + mid = bot + (top - bot) / 2; + } + + if (mid == top && mid < array->reserved) { + void* current = DynamicArray_GetPointer(array, mid); + eval = function(current, xarg); } if (eval != 0) {