diff options
author | krivokon <krivokon@yandex-team.ru> | 2022-02-10 16:52:05 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:52:05 +0300 |
commit | 57cd0ba1b8c1fb6b71ccd886caab0c1f28fe54f5 (patch) | |
tree | ab7fbbf3253d4c0e2793218f09378908beb025fb /util/generic | |
parent | 0a4db2a8ab37872843d41855c2af41be46523ae5 (diff) | |
download | ydb-57cd0ba1b8c1fb6b71ccd886caab0c1f28fe54f5.tar.gz |
Restoring authorship annotation for <krivokon@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r-- | util/generic/algorithm.h | 16 | ||||
-rw-r--r-- | util/generic/algorithm_ut.cpp | 52 |
2 files changed, 34 insertions, 34 deletions
diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h index cfb8b450ae..badfb88993 100644 --- a/util/generic/algorithm.h +++ b/util/generic/algorithm.h @@ -665,16 +665,16 @@ static inline std::pair<I1, I2> Mismatch(I1 b1, I1 e1, I2 b2, P p) { return std::mismatch(b1, e1, b2, p); } -template <class RandomIterator> -static inline void NthElement(RandomIterator begin, RandomIterator nth, RandomIterator end) { +template <class RandomIterator> +static inline void NthElement(RandomIterator begin, RandomIterator nth, RandomIterator end) { std::nth_element(begin, nth, end); -} - -template <class RandomIterator, class Compare> -static inline void NthElement(RandomIterator begin, RandomIterator nth, RandomIterator end, Compare compare) { +} + +template <class RandomIterator, class Compare> +static inline void NthElement(RandomIterator begin, RandomIterator nth, RandomIterator end, Compare compare) { std::nth_element(begin, nth, end, compare); -} - +} + // no standard implementation until C++14 template <class I1, class I2> static inline std::pair<I1, I2> Mismatch(I1 b1, I1 e1, I2 b2, I2 e2) { diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp index abea879ea7..8d732fcc0c 100644 --- a/util/generic/algorithm_ut.cpp +++ b/util/generic/algorithm_ut.cpp @@ -265,7 +265,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT_EQUAL(v, suV); } } - + Y_UNIT_TEST(EraseTest) { TVector<int> data = {5, 4, 3, 2, 1, 0}; TVector<int> expected = {5, 4, 2, 1, 0}; @@ -313,40 +313,40 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } Y_UNIT_TEST(NthElementTest) { - { + { TVector<TString> v; - NthElement(v.begin(), v.begin(), v.end()); + NthElement(v.begin(), v.begin(), v.end()); UNIT_ASSERT_EQUAL(v, TVector<TString>()); - } - - { - int data[] = {3, 2, 1, 4, 6, 5, 7, 9, 8}; + } + + { + int data[] = {3, 2, 1, 4, 6, 5, 7, 9, 8}; TVector<int> testVector(data, data + Y_ARRAY_SIZE(data)); - + size_t medianInd = testVector.size() / 2; - - NthElement(testVector.begin(), testVector.begin() + medianInd, testVector.end()); - UNIT_ASSERT_EQUAL(testVector[medianInd], 5); - + + NthElement(testVector.begin(), testVector.begin() + medianInd, testVector.end()); + UNIT_ASSERT_EQUAL(testVector[medianInd], 5); + NthElement(testVector.begin(), testVector.begin() + medianInd, testVector.end(), [](int lhs, int rhs) { return lhs > rhs; }); - UNIT_ASSERT_EQUAL(testVector[medianInd], 5); - } - - { - const char* data[] = {"3", "234", "1231", "333", "545345", "11", "111", "55", "66"}; + UNIT_ASSERT_EQUAL(testVector[medianInd], 5); + } + + { + const char* data[] = {"3", "234", "1231", "333", "545345", "11", "111", "55", "66"}; TVector<TString> testVector(data, data + Y_ARRAY_SIZE(data)); - + size_t medianInd = testVector.size() / 2; - NthElement(testVector.begin(), testVector.begin() + medianInd, testVector.end()); - - auto median = testVector.begin() + medianInd; + NthElement(testVector.begin(), testVector.begin() + medianInd, testVector.end()); + + auto median = testVector.begin() + medianInd; for (auto it0 = testVector.begin(); it0 != median; ++it0) { for (auto it1 = median; it1 != testVector.end(); ++it1) { - UNIT_ASSERT(*it0 <= *it1); - } - } - } - } + UNIT_ASSERT(*it0 <= *it1); + } + } + } + } Y_UNIT_TEST(BinarySearchTest) { { |