diff options
author | asynts <asynts@gmail.com> | 2020-08-26 14:14:32 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-26 21:07:53 +0200 |
commit | 8e08d9f70ac13ffdeecbb46b8e50db4fada974b6 (patch) | |
tree | 43dbc2587e863478a7f865336cb4ab863cda0bfe | |
parent | 18b3de755556bfcfa0fd5d00e54b9f14ea36b6f9 (diff) | |
download | serenity-8e08d9f70ac13ffdeecbb46b8e50db4fada974b6.zip |
AK: Fix the signature of binary_search.
-rw-r--r-- | AK/BinarySearch.h | 4 | ||||
-rw-r--r-- | AK/Tests/TestBinarySearch.cpp | 8 |
2 files changed, 6 insertions, 6 deletions
diff --git a/AK/BinarySearch.h b/AK/BinarySearch.h index be16f57f7e..6994b94600 100644 --- a/AK/BinarySearch.h +++ b/AK/BinarySearch.h @@ -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) diff --git a/AK/Tests/TestBinarySearch.cpp b/AK/Tests/TestBinarySearch.cpp index a0800b4f61..6e27fd1c60 100644 --- a/AK/Tests/TestBinarySearch.cpp +++ b/AK/Tests/TestBinarySearch.cpp @@ -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); @@ -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); |