diff options
author | avatar <avatar@yandex-team.ru> | 2022-02-10 16:50:10 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:10 +0300 |
commit | e21d5670f181bded7a3222fe235c79bea9d9f378 (patch) | |
tree | e7d9da854fe0f8f38dad6be2866c4bc8a7f99847 /library/cpp/containers | |
parent | aed1c1c7782eb0a0536e5b25bbed950b397e0ac8 (diff) | |
download | ydb-e21d5670f181bded7a3222fe235c79bea9d9f378.tar.gz |
Restoring authorship annotation for <avatar@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/containers')
4 files changed, 94 insertions, 94 deletions
diff --git a/library/cpp/containers/top_keeper/top_keeper.h b/library/cpp/containers/top_keeper/top_keeper.h index 2f282b5a9e..a07b567ea3 100644 --- a/library/cpp/containers/top_keeper/top_keeper.h +++ b/library/cpp/containers/top_keeper/top_keeper.h @@ -13,7 +13,7 @@ private: TVector<T, Alloc> Internal; size_t HalfMaxSize; TComparator Comparer; - size_t MinElementIndex; + size_t MinElementIndex; private: void Reserve() { @@ -27,12 +27,12 @@ private: } if (Internal.size() < HalfMaxSize) { - if (Internal.empty() || Comparer(Internal[MinElementIndex], value)) { - MinElementIndex = Internal.size(); + if (Internal.empty() || Comparer(Internal[MinElementIndex], value)) { + MinElementIndex = Internal.size(); Internal.push_back(std::forward<UT>(value)); return true; } - } else if (!Comparer(value, Internal[MinElementIndex])) { + } else if (!Comparer(value, Internal[MinElementIndex])) { return false; } @@ -75,9 +75,9 @@ private: if (Y_LIKELY(Internal.size() >= HalfMaxSize)) { NthElement(Internal.begin(), Internal.begin() + HalfMaxSize - 1, Internal.end(), Comparer); Internal.erase(Internal.begin() + HalfMaxSize, Internal.end()); - - //we should update MinElementIndex cause we just altered Internal - MinElementIndex = HalfMaxSize - 1; + + //we should update MinElementIndex cause we just altered Internal + MinElementIndex = HalfMaxSize - 1; } } @@ -127,7 +127,7 @@ private: void Reset() { Internal.clear(); - //MinElementIndex will reset itself when we start adding new values + //MinElementIndex will reset itself when we start adding new values } }; diff --git a/library/cpp/containers/top_keeper/top_keeper/top_keeper.h b/library/cpp/containers/top_keeper/top_keeper/top_keeper.h index 2f282b5a9e..a07b567ea3 100644 --- a/library/cpp/containers/top_keeper/top_keeper/top_keeper.h +++ b/library/cpp/containers/top_keeper/top_keeper/top_keeper.h @@ -13,7 +13,7 @@ private: TVector<T, Alloc> Internal; size_t HalfMaxSize; TComparator Comparer; - size_t MinElementIndex; + size_t MinElementIndex; private: void Reserve() { @@ -27,12 +27,12 @@ private: } if (Internal.size() < HalfMaxSize) { - if (Internal.empty() || Comparer(Internal[MinElementIndex], value)) { - MinElementIndex = Internal.size(); + if (Internal.empty() || Comparer(Internal[MinElementIndex], value)) { + MinElementIndex = Internal.size(); Internal.push_back(std::forward<UT>(value)); return true; } - } else if (!Comparer(value, Internal[MinElementIndex])) { + } else if (!Comparer(value, Internal[MinElementIndex])) { return false; } @@ -75,9 +75,9 @@ private: if (Y_LIKELY(Internal.size() >= HalfMaxSize)) { NthElement(Internal.begin(), Internal.begin() + HalfMaxSize - 1, Internal.end(), Comparer); Internal.erase(Internal.begin() + HalfMaxSize, Internal.end()); - - //we should update MinElementIndex cause we just altered Internal - MinElementIndex = HalfMaxSize - 1; + + //we should update MinElementIndex cause we just altered Internal + MinElementIndex = HalfMaxSize - 1; } } @@ -127,7 +127,7 @@ private: void Reset() { Internal.clear(); - //MinElementIndex will reset itself when we start adding new values + //MinElementIndex will reset itself when we start adding new values } }; diff --git a/library/cpp/containers/top_keeper/top_keeper/ut/top_keeper_ut.cpp b/library/cpp/containers/top_keeper/top_keeper/ut/top_keeper_ut.cpp index a938279025..666d0a8297 100644 --- a/library/cpp/containers/top_keeper/top_keeper/ut/top_keeper_ut.cpp +++ b/library/cpp/containers/top_keeper/top_keeper/ut/top_keeper_ut.cpp @@ -1,7 +1,7 @@ #include <library/cpp/containers/limited_heap/limited_heap.h> #include <library/cpp/containers/top_keeper/top_keeper.h> #include <library/cpp/testing/unittest/registar.h> -#include <util/random/random.h> +#include <util/random/random.h> static ui32 seed = 3; ui32 Rnd() { @@ -158,50 +158,50 @@ Y_UNIT_TEST_SUITE(TTopKeeperTest) { h2.Pop(); } } - + Y_UNIT_TEST(PreRegressionTest) { - typedef std::pair<float, unsigned int> TElementType; - - const size_t randomTriesCount = 128; + typedef std::pair<float, unsigned int> TElementType; + + const size_t randomTriesCount = 128; for (size_t i1 = 0; i1 < randomTriesCount; ++i1) { - const size_t desiredElementsCount = RandomNumber<size_t>(5) + 1; - TLimitedHeap<TElementType> h1(desiredElementsCount); - TTopKeeper<TElementType> h2(desiredElementsCount); - - const size_t elementsToInsert = RandomNumber<size_t>(10) + desiredElementsCount; - UNIT_ASSERT_C(desiredElementsCount <= elementsToInsert, "Test internal invariant is broken"); + const size_t desiredElementsCount = RandomNumber<size_t>(5) + 1; + TLimitedHeap<TElementType> h1(desiredElementsCount); + TTopKeeper<TElementType> h2(desiredElementsCount); + + const size_t elementsToInsert = RandomNumber<size_t>(10) + desiredElementsCount; + UNIT_ASSERT_C(desiredElementsCount <= elementsToInsert, "Test internal invariant is broken"); for (size_t i2 = 0; i2 < elementsToInsert; ++i2) { - const auto f = RandomNumber<float>(); - const auto id = RandomNumber<unsigned int>(); - - h1.Insert(TElementType(f, id)); - h2.Insert(TElementType(f, id)); - } - - h2.Finalize(); - - //we inserted enough elements to guarantee this outcome - UNIT_ASSERT_EQUAL(h1.GetSize(), desiredElementsCount); - UNIT_ASSERT_EQUAL(h2.GetSize(), desiredElementsCount); - - const auto n = h2.GetSize(); + const auto f = RandomNumber<float>(); + const auto id = RandomNumber<unsigned int>(); + + h1.Insert(TElementType(f, id)); + h2.Insert(TElementType(f, id)); + } + + h2.Finalize(); + + //we inserted enough elements to guarantee this outcome + UNIT_ASSERT_EQUAL(h1.GetSize(), desiredElementsCount); + UNIT_ASSERT_EQUAL(h2.GetSize(), desiredElementsCount); + + const auto n = h2.GetSize(); for (size_t i3 = 0; i3 < n; ++i3) { - UNIT_ASSERT_EQUAL(h1.GetMin(), h2.GetNext()); - h1.PopMin(); - h2.Pop(); - } - } - } - + UNIT_ASSERT_EQUAL(h1.GetMin(), h2.GetNext()); + h1.PopMin(); + h2.Pop(); + } + } + } + Y_UNIT_TEST(CopyKeeperRegressionCase) { - using TKeeper = TTopKeeper<float>; + using TKeeper = TTopKeeper<float>; TVector<TKeeper> v(2, TKeeper(200)); - auto& k = v[1]; - for (size_t i = 0; i < 100; ++i) { - k.Insert(RandomNumber<float>()); - } - k.Finalize(); - } + auto& k = v[1]; + for (size_t i = 0; i < 100; ++i) { + k.Insert(RandomNumber<float>()); + } + k.Finalize(); + } Y_UNIT_TEST(ExtractTest) { TTopKeeper<size_t> keeper(100); diff --git a/library/cpp/containers/top_keeper/ut/top_keeper_ut.cpp b/library/cpp/containers/top_keeper/ut/top_keeper_ut.cpp index a938279025..666d0a8297 100644 --- a/library/cpp/containers/top_keeper/ut/top_keeper_ut.cpp +++ b/library/cpp/containers/top_keeper/ut/top_keeper_ut.cpp @@ -1,7 +1,7 @@ #include <library/cpp/containers/limited_heap/limited_heap.h> #include <library/cpp/containers/top_keeper/top_keeper.h> #include <library/cpp/testing/unittest/registar.h> -#include <util/random/random.h> +#include <util/random/random.h> static ui32 seed = 3; ui32 Rnd() { @@ -158,50 +158,50 @@ Y_UNIT_TEST_SUITE(TTopKeeperTest) { h2.Pop(); } } - + Y_UNIT_TEST(PreRegressionTest) { - typedef std::pair<float, unsigned int> TElementType; - - const size_t randomTriesCount = 128; + typedef std::pair<float, unsigned int> TElementType; + + const size_t randomTriesCount = 128; for (size_t i1 = 0; i1 < randomTriesCount; ++i1) { - const size_t desiredElementsCount = RandomNumber<size_t>(5) + 1; - TLimitedHeap<TElementType> h1(desiredElementsCount); - TTopKeeper<TElementType> h2(desiredElementsCount); - - const size_t elementsToInsert = RandomNumber<size_t>(10) + desiredElementsCount; - UNIT_ASSERT_C(desiredElementsCount <= elementsToInsert, "Test internal invariant is broken"); + const size_t desiredElementsCount = RandomNumber<size_t>(5) + 1; + TLimitedHeap<TElementType> h1(desiredElementsCount); + TTopKeeper<TElementType> h2(desiredElementsCount); + + const size_t elementsToInsert = RandomNumber<size_t>(10) + desiredElementsCount; + UNIT_ASSERT_C(desiredElementsCount <= elementsToInsert, "Test internal invariant is broken"); for (size_t i2 = 0; i2 < elementsToInsert; ++i2) { - const auto f = RandomNumber<float>(); - const auto id = RandomNumber<unsigned int>(); - - h1.Insert(TElementType(f, id)); - h2.Insert(TElementType(f, id)); - } - - h2.Finalize(); - - //we inserted enough elements to guarantee this outcome - UNIT_ASSERT_EQUAL(h1.GetSize(), desiredElementsCount); - UNIT_ASSERT_EQUAL(h2.GetSize(), desiredElementsCount); - - const auto n = h2.GetSize(); + const auto f = RandomNumber<float>(); + const auto id = RandomNumber<unsigned int>(); + + h1.Insert(TElementType(f, id)); + h2.Insert(TElementType(f, id)); + } + + h2.Finalize(); + + //we inserted enough elements to guarantee this outcome + UNIT_ASSERT_EQUAL(h1.GetSize(), desiredElementsCount); + UNIT_ASSERT_EQUAL(h2.GetSize(), desiredElementsCount); + + const auto n = h2.GetSize(); for (size_t i3 = 0; i3 < n; ++i3) { - UNIT_ASSERT_EQUAL(h1.GetMin(), h2.GetNext()); - h1.PopMin(); - h2.Pop(); - } - } - } - + UNIT_ASSERT_EQUAL(h1.GetMin(), h2.GetNext()); + h1.PopMin(); + h2.Pop(); + } + } + } + Y_UNIT_TEST(CopyKeeperRegressionCase) { - using TKeeper = TTopKeeper<float>; + using TKeeper = TTopKeeper<float>; TVector<TKeeper> v(2, TKeeper(200)); - auto& k = v[1]; - for (size_t i = 0; i < 100; ++i) { - k.Insert(RandomNumber<float>()); - } - k.Finalize(); - } + auto& k = v[1]; + for (size_t i = 0; i < 100; ++i) { + k.Insert(RandomNumber<float>()); + } + k.Finalize(); + } Y_UNIT_TEST(ExtractTest) { TTopKeeper<size_t> keeper(100); |