Fixed linearsearch (agai)
This commit is contained in:
parent
fe63781996
commit
840a29a59d
2 changed files with 28 additions and 19 deletions
|
@ -1,19 +1,20 @@
|
||||||
add_subdirectory(./Scratchpad)
|
|
||||||
add_subdirectory(./allocator-interface)
|
|
||||||
add_subdirectory(./FixedBuffer)
|
add_subdirectory(./FixedBuffer)
|
||||||
add_subdirectory(./dynamicbuffer)
|
add_subdirectory(./allocator-interface)
|
||||||
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(./arraylist)
|
add_subdirectory(./arraylist)
|
||||||
add_subdirectory(./argumentc)
|
|
||||||
add_subdirectory(./rand)
|
|
||||||
add_subdirectory(./siphash)
|
add_subdirectory(./siphash)
|
||||||
add_subdirectory(./pointers)
|
|
||||||
add_subdirectory(./dynamicarray)
|
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)
|
||||||
|
|
|
@ -257,17 +257,25 @@ size_t DynamicArray_FindFunctionLinear(DynamicArray* array, DynamicArrayLinearFi
|
||||||
size_t mid = bot + (top - bot) / 2;
|
size_t mid = bot + (top - bot) / 2;
|
||||||
int eval = -1;
|
int eval = -1;
|
||||||
|
|
||||||
while (bot != top) {
|
while (eval != 0 && mid != top && mid < array->reserved) {
|
||||||
void* current = DynamicArray_GetPointer(array, mid);
|
void* current = DynamicArray_GetPointer(array, mid);
|
||||||
eval = function(current, xarg);
|
eval = function(current, xarg);
|
||||||
|
|
||||||
if (eval > 0) {
|
if (eval == 0) {
|
||||||
bot = mid + 1;
|
bot = top = mid;
|
||||||
} else if (eval < 0) {
|
} else if (eval < 0) {
|
||||||
top = mid - 1;
|
top = mid - 1;
|
||||||
} else {
|
} 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) {
|
if (eval != 0) {
|
||||||
|
|
Loading…
Reference in a new issue