mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 17:17:45 +00:00
Refactor: Change the AK::binary_search signature to use AK::Span.
This commit is contained in:
parent
ac9c2bc492
commit
707d92db61
5 changed files with 20 additions and 19 deletions
|
@ -26,6 +26,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Span.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
|
@ -38,10 +39,10 @@ int integral_compare(const T& a, const T& b)
|
|||
}
|
||||
|
||||
template<typename T, typename Compare>
|
||||
T* binary_search(T* haystack, size_t haystack_size, const T& needle, Compare compare = integral_compare, int* nearby_index = nullptr)
|
||||
T* binary_search(Span<T> haystack, const T& needle, Compare compare = integral_compare, int* nearby_index = nullptr)
|
||||
{
|
||||
int low = 0;
|
||||
int high = haystack_size - 1;
|
||||
int high = haystack.size() - 1;
|
||||
while (low <= high) {
|
||||
int middle = (low + high) / 2;
|
||||
int comparison = compare(needle, haystack[middle]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue