Skip to content

Commit

Permalink
AK: Fix the signature of binary_search.
Browse files Browse the repository at this point in the history
  • Loading branch information
asynts authored and awesomekling committed Aug 26, 2020
1 parent 18b3de7 commit 8e08d9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions AK/BinarySearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
namespace AK {

template<typename T>
int integral_compare(const T& a, const T& b)
int integral_compare(const typename RemoveConst<T>::Type& a, const typename RemoveConst<T>::Type& b)
{
return a - b;
}

template<typename T, typename Compare>
T* binary_search(Span<T> haystack, const T& needle, Compare compare = integral_compare, size_t* nearby_index = nullptr)
T* binary_search(Span<T> haystack, const typename RemoveConst<T>::Type& needle, Compare compare = integral_compare, size_t* nearby_index = nullptr)
{
if (haystack.size() == 0) {
if (nearby_index)
Expand Down
8 changes: 4 additions & 4 deletions AK/Tests/TestBinarySearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ TEST_CASE(array_doubles)
{
double doubles[] = { 1.1, 9.9, 33.33 };

auto test1 = *binary_search({ doubles, 3 }, 1.1, AK::integral_compare<double>);
auto test2 = *binary_search({ doubles, 3 }, 9.9, AK::integral_compare<double>);
auto test3 = *binary_search({ doubles, 3 }, 33.33, AK::integral_compare<double>);
auto test1 = *binary_search(Span<double> { doubles, 3 }, 1.1, AK::integral_compare<double>);
auto test2 = *binary_search(Span<double> { doubles, 3 }, 9.9, AK::integral_compare<double>);
auto test3 = *binary_search(Span<double> { doubles, 3 }, 33.33, AK::integral_compare<double>);
EXPECT_EQ(test1, 1.1);
EXPECT_EQ(test2, 9.9);
EXPECT_EQ(test3, 33.33);
Expand Down Expand Up @@ -110,7 +110,7 @@ TEST_CASE(no_elements)

TEST_CASE(huge_char_array)
{
const size_t N = 2147483680;
const size_t N = 2147483680;
Bytes span { new (std::nothrow) u8[N], N };
EXPECT(span.data() != nullptr);

Expand Down

0 comments on commit 8e08d9f

Please sign in to comment.