diff options
author | pavelgur <pavelgur@yandex-team.ru> | 2022-02-10 16:50:19 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:19 +0300 |
commit | db222959b3748242024c781f563f31a342492476 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp | |
parent | 173c6a0fa7f439b2c207c2f258e52ccb4ac181cf (diff) | |
download | ydb-db222959b3748242024c781f563f31a342492476.tar.gz |
Restoring authorship annotation for <pavelgur@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp')
5 files changed, 205 insertions, 205 deletions
diff --git a/library/cpp/accurate_accumulate/accurate_accumulate.h b/library/cpp/accurate_accumulate/accurate_accumulate.h index 53ff04ef09..dacced17e9 100644 --- a/library/cpp/accurate_accumulate/accurate_accumulate.h +++ b/library/cpp/accurate_accumulate/accurate_accumulate.h @@ -143,41 +143,41 @@ static inline TAccumulatorType TypedFastAccumulate(It begin, It end) { return accumulator; } -template <class TOperation, typename TAccumulatorType, typename It1, typename It2> -static inline TAccumulatorType TypedFastInnerOperation(It1 begin1, It1 end1, It2 begin2) { +template <class TOperation, typename TAccumulatorType, typename It1, typename It2> +static inline TAccumulatorType TypedFastInnerOperation(It1 begin1, It1 end1, It2 begin2) { TAccumulatorType accumulator = TAccumulatorType(); - const TOperation op; + const TOperation op; for (; begin1 + 15 < end1; begin1 += 16, begin2 += 16) { - accumulator += op(*(begin1 + 0), *(begin2 + 0)) + - op(*(begin1 + 1), *(begin2 + 1)) + - op(*(begin1 + 2), *(begin2 + 2)) + - op(*(begin1 + 3), *(begin2 + 3)) + - op(*(begin1 + 4), *(begin2 + 4)) + - op(*(begin1 + 5), *(begin2 + 5)) + - op(*(begin1 + 6), *(begin2 + 6)) + - op(*(begin1 + 7), *(begin2 + 7)) + - op(*(begin1 + 8), *(begin2 + 8)) + - op(*(begin1 + 9), *(begin2 + 9)) + - op(*(begin1 + 10), *(begin2 + 10)) + - op(*(begin1 + 11), *(begin2 + 11)) + - op(*(begin1 + 12), *(begin2 + 12)) + - op(*(begin1 + 13), *(begin2 + 13)) + - op(*(begin1 + 14), *(begin2 + 14)) + - op(*(begin1 + 15), *(begin2 + 15)); + accumulator += op(*(begin1 + 0), *(begin2 + 0)) + + op(*(begin1 + 1), *(begin2 + 1)) + + op(*(begin1 + 2), *(begin2 + 2)) + + op(*(begin1 + 3), *(begin2 + 3)) + + op(*(begin1 + 4), *(begin2 + 4)) + + op(*(begin1 + 5), *(begin2 + 5)) + + op(*(begin1 + 6), *(begin2 + 6)) + + op(*(begin1 + 7), *(begin2 + 7)) + + op(*(begin1 + 8), *(begin2 + 8)) + + op(*(begin1 + 9), *(begin2 + 9)) + + op(*(begin1 + 10), *(begin2 + 10)) + + op(*(begin1 + 11), *(begin2 + 11)) + + op(*(begin1 + 12), *(begin2 + 12)) + + op(*(begin1 + 13), *(begin2 + 13)) + + op(*(begin1 + 14), *(begin2 + 14)) + + op(*(begin1 + 15), *(begin2 + 15)); } for (; begin1 != end1; ++begin1, ++begin2) { - accumulator += op(*begin1, *begin2); + accumulator += op(*begin1, *begin2); } return accumulator; } -template <typename TAccumulatorType, typename It1, typename It2> -static inline TAccumulatorType TypedFastInnerProduct(It1 begin1, It1 end1, It2 begin2) { - return TypedFastInnerOperation<std::multiplies<>, TAccumulatorType>(begin1, end1, begin2); -} - +template <typename TAccumulatorType, typename It1, typename It2> +static inline TAccumulatorType TypedFastInnerProduct(It1 begin1, It1 end1, It2 begin2) { + return TypedFastInnerOperation<std::multiplies<>, TAccumulatorType>(begin1, end1, begin2); +} + template <typename It> static inline double FastAccumulate(It begin, It end) { return TypedFastAccumulate<double>(begin, end); diff --git a/library/cpp/containers/top_keeper/top_keeper.h b/library/cpp/containers/top_keeper/top_keeper.h index 1188c95733..2f282b5a9e 100644 --- a/library/cpp/containers/top_keeper/top_keeper.h +++ b/library/cpp/containers/top_keeper/top_keeper.h @@ -5,7 +5,7 @@ #include <util/generic/maybe.h> #include <util/str_stl.h> -template <class T, class TComparator = TGreater<T>, bool sort = true, class Alloc = std::allocator<T>> +template <class T, class TComparator = TGreater<T>, bool sort = true, class Alloc = std::allocator<T>> class TTopKeeper { private: class TVectorWithMin { @@ -16,16 +16,16 @@ private: size_t MinElementIndex; private: - void Reserve() { - Internal.reserve(2 * HalfMaxSize); - } + void Reserve() { + Internal.reserve(2 * HalfMaxSize); + } template <class UT> - bool Insert(UT&& value) noexcept { + bool Insert(UT&& value) noexcept { if (Y_UNLIKELY(0 == HalfMaxSize)) { - return false; - } - + return false; + } + if (Internal.size() < HalfMaxSize) { if (Internal.empty() || Comparer(Internal[MinElementIndex], value)) { MinElementIndex = Internal.size(); @@ -33,37 +33,37 @@ private: return true; } } else if (!Comparer(value, Internal[MinElementIndex])) { - return false; - } - - Internal.push_back(std::forward<UT>(value)); - - if (Internal.size() == (HalfMaxSize << 1)) { - Partition(); - } - - return true; - } - + return false; + } + + Internal.push_back(std::forward<UT>(value)); + + if (Internal.size() == (HalfMaxSize << 1)) { + Partition(); + } + + return true; + } + public: - using value_type = T; - + using value_type = T; + TVectorWithMin(const size_t halfMaxSize, const TComparator& comp) : HalfMaxSize(halfMaxSize) , Comparer(comp) { - Reserve(); + Reserve(); } template <class TAllocParam> - TVectorWithMin(const size_t halfMaxSize, const TComparator& comp, TAllocParam&& param) - : Internal(std::forward<TAllocParam>(param)) - , HalfMaxSize(halfMaxSize) - , Comparer(comp) - { - Reserve(); - } - + TVectorWithMin(const size_t halfMaxSize, const TComparator& comp, TAllocParam&& param) + : Internal(std::forward<TAllocParam>(param)) + , HalfMaxSize(halfMaxSize) + , Comparer(comp) + { + Reserve(); + } + void SortAccending() { Sort(Internal.begin(), Internal.end(), Comparer); } @@ -81,17 +81,17 @@ private: } } - bool Push(const T& value) { - return Insert(value); - } + bool Push(const T& value) { + return Insert(value); + } - bool Push(T&& value) { - return Insert(std::move(value)); - } + bool Push(T&& value) { + return Insert(std::move(value)); + } template <class... TArgs> - bool Emplace(TArgs&&... args) { - return Insert(T(std::forward<TArgs>(args)...)); // TODO: make it "real" emplace, not that fake one + bool Emplace(TArgs&&... args) { + return Insert(T(std::forward<TArgs>(args)...)); // TODO: make it "real" emplace, not that fake one } void SetMaxSize(size_t newHalfMaxSize) { @@ -104,10 +104,10 @@ private: return Internal.size(); } - const auto& GetInternal() const { - return Internal; - } - + const auto& GetInternal() const { + return Internal; + } + auto Extract() { using std::swap; @@ -131,13 +131,13 @@ private: } }; - void CheckNotFinalized() { - Y_ENSURE(!Finalized, "Cannot insert after finalizing (Pop() / GetNext() / Finalize())! " + void CheckNotFinalized() { + Y_ENSURE(!Finalized, "Cannot insert after finalizing (Pop() / GetNext() / Finalize())! " "Use TLimitedHeap for this scenario"); - } - + } + size_t MaxSize; - const TComparator Comparer; + const TComparator Comparer; TVectorWithMin Internal; bool Finalized; @@ -159,16 +159,16 @@ public: } template <class TAllocParam> - TTopKeeper(size_t maxSize, const TComparator& comp, TAllocParam&& param) - : MaxSize(maxSize) - , Comparer(comp) - , Internal(maxSize, comp, std::forward<TAllocParam>(param)) - , Finalized(false) - { - } - + TTopKeeper(size_t maxSize, const TComparator& comp, TAllocParam&& param) + : MaxSize(maxSize) + , Comparer(comp) + , Internal(maxSize, comp, std::forward<TAllocParam>(param)) + , Finalized(false) + { + } + void Finalize() { - if (Y_LIKELY(Finalized)) { + if (Y_LIKELY(Finalized)) { return; } Internal.Partition(); @@ -193,43 +193,43 @@ public: } } - T ExtractOne() { + T ExtractOne() { Y_ENSURE(!IsEmpty(), "Trying ExtractOne from empty heap!"); - Finalize(); - auto value = std::move(Internal.Back()); - Internal.Pop(); - if (IsEmpty()) { - Reset(); - } - return value; - } - + Finalize(); + auto value = std::move(Internal.Back()); + Internal.Pop(); + if (IsEmpty()) { + Reset(); + } + return value; + } + auto Extract() { Finalize(); return Internal.Extract(); } - bool Insert(const T& value) { - CheckNotFinalized(); - return Internal.Push(value); + bool Insert(const T& value) { + CheckNotFinalized(); + return Internal.Push(value); + } + + bool Insert(T&& value) { + CheckNotFinalized(); + return Internal.Push(std::move(value)); } - bool Insert(T&& value) { - CheckNotFinalized(); - return Internal.Push(std::move(value)); - } - template <class... TArgs> - bool Emplace(TArgs&&... args) { - CheckNotFinalized(); - return Internal.Emplace(std::forward<TArgs>(args)...); - } - - const auto& GetInternal() { - Finalize(); - return Internal.GetInternal(); - } - + bool Emplace(TArgs&&... args) { + CheckNotFinalized(); + return Internal.Emplace(std::forward<TArgs>(args)...); + } + + const auto& GetInternal() { + Finalize(); + return Internal.GetInternal(); + } + bool IsEmpty() const { return Internal.GetSize() == 0; } 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 1188c95733..2f282b5a9e 100644 --- a/library/cpp/containers/top_keeper/top_keeper/top_keeper.h +++ b/library/cpp/containers/top_keeper/top_keeper/top_keeper.h @@ -5,7 +5,7 @@ #include <util/generic/maybe.h> #include <util/str_stl.h> -template <class T, class TComparator = TGreater<T>, bool sort = true, class Alloc = std::allocator<T>> +template <class T, class TComparator = TGreater<T>, bool sort = true, class Alloc = std::allocator<T>> class TTopKeeper { private: class TVectorWithMin { @@ -16,16 +16,16 @@ private: size_t MinElementIndex; private: - void Reserve() { - Internal.reserve(2 * HalfMaxSize); - } + void Reserve() { + Internal.reserve(2 * HalfMaxSize); + } template <class UT> - bool Insert(UT&& value) noexcept { + bool Insert(UT&& value) noexcept { if (Y_UNLIKELY(0 == HalfMaxSize)) { - return false; - } - + return false; + } + if (Internal.size() < HalfMaxSize) { if (Internal.empty() || Comparer(Internal[MinElementIndex], value)) { MinElementIndex = Internal.size(); @@ -33,37 +33,37 @@ private: return true; } } else if (!Comparer(value, Internal[MinElementIndex])) { - return false; - } - - Internal.push_back(std::forward<UT>(value)); - - if (Internal.size() == (HalfMaxSize << 1)) { - Partition(); - } - - return true; - } - + return false; + } + + Internal.push_back(std::forward<UT>(value)); + + if (Internal.size() == (HalfMaxSize << 1)) { + Partition(); + } + + return true; + } + public: - using value_type = T; - + using value_type = T; + TVectorWithMin(const size_t halfMaxSize, const TComparator& comp) : HalfMaxSize(halfMaxSize) , Comparer(comp) { - Reserve(); + Reserve(); } template <class TAllocParam> - TVectorWithMin(const size_t halfMaxSize, const TComparator& comp, TAllocParam&& param) - : Internal(std::forward<TAllocParam>(param)) - , HalfMaxSize(halfMaxSize) - , Comparer(comp) - { - Reserve(); - } - + TVectorWithMin(const size_t halfMaxSize, const TComparator& comp, TAllocParam&& param) + : Internal(std::forward<TAllocParam>(param)) + , HalfMaxSize(halfMaxSize) + , Comparer(comp) + { + Reserve(); + } + void SortAccending() { Sort(Internal.begin(), Internal.end(), Comparer); } @@ -81,17 +81,17 @@ private: } } - bool Push(const T& value) { - return Insert(value); - } + bool Push(const T& value) { + return Insert(value); + } - bool Push(T&& value) { - return Insert(std::move(value)); - } + bool Push(T&& value) { + return Insert(std::move(value)); + } template <class... TArgs> - bool Emplace(TArgs&&... args) { - return Insert(T(std::forward<TArgs>(args)...)); // TODO: make it "real" emplace, not that fake one + bool Emplace(TArgs&&... args) { + return Insert(T(std::forward<TArgs>(args)...)); // TODO: make it "real" emplace, not that fake one } void SetMaxSize(size_t newHalfMaxSize) { @@ -104,10 +104,10 @@ private: return Internal.size(); } - const auto& GetInternal() const { - return Internal; - } - + const auto& GetInternal() const { + return Internal; + } + auto Extract() { using std::swap; @@ -131,13 +131,13 @@ private: } }; - void CheckNotFinalized() { - Y_ENSURE(!Finalized, "Cannot insert after finalizing (Pop() / GetNext() / Finalize())! " + void CheckNotFinalized() { + Y_ENSURE(!Finalized, "Cannot insert after finalizing (Pop() / GetNext() / Finalize())! " "Use TLimitedHeap for this scenario"); - } - + } + size_t MaxSize; - const TComparator Comparer; + const TComparator Comparer; TVectorWithMin Internal; bool Finalized; @@ -159,16 +159,16 @@ public: } template <class TAllocParam> - TTopKeeper(size_t maxSize, const TComparator& comp, TAllocParam&& param) - : MaxSize(maxSize) - , Comparer(comp) - , Internal(maxSize, comp, std::forward<TAllocParam>(param)) - , Finalized(false) - { - } - + TTopKeeper(size_t maxSize, const TComparator& comp, TAllocParam&& param) + : MaxSize(maxSize) + , Comparer(comp) + , Internal(maxSize, comp, std::forward<TAllocParam>(param)) + , Finalized(false) + { + } + void Finalize() { - if (Y_LIKELY(Finalized)) { + if (Y_LIKELY(Finalized)) { return; } Internal.Partition(); @@ -193,43 +193,43 @@ public: } } - T ExtractOne() { + T ExtractOne() { Y_ENSURE(!IsEmpty(), "Trying ExtractOne from empty heap!"); - Finalize(); - auto value = std::move(Internal.Back()); - Internal.Pop(); - if (IsEmpty()) { - Reset(); - } - return value; - } - + Finalize(); + auto value = std::move(Internal.Back()); + Internal.Pop(); + if (IsEmpty()) { + Reset(); + } + return value; + } + auto Extract() { Finalize(); return Internal.Extract(); } - bool Insert(const T& value) { - CheckNotFinalized(); - return Internal.Push(value); + bool Insert(const T& value) { + CheckNotFinalized(); + return Internal.Push(value); + } + + bool Insert(T&& value) { + CheckNotFinalized(); + return Internal.Push(std::move(value)); } - bool Insert(T&& value) { - CheckNotFinalized(); - return Internal.Push(std::move(value)); - } - template <class... TArgs> - bool Emplace(TArgs&&... args) { - CheckNotFinalized(); - return Internal.Emplace(std::forward<TArgs>(args)...); - } - - const auto& GetInternal() { - Finalize(); - return Internal.GetInternal(); - } - + bool Emplace(TArgs&&... args) { + CheckNotFinalized(); + return Internal.Emplace(std::forward<TArgs>(args)...); + } + + const auto& GetInternal() { + Finalize(); + return Internal.GetInternal(); + } + bool IsEmpty() const { return Internal.GetSize() == 0; } 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 a26d2576e9..a938279025 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 @@ -17,15 +17,15 @@ Y_UNIT_TEST_SUITE(TTopKeeperTest) { Y_UNIT_TEST(CorrectnessTest) { int m = 20000; - TLimitedHeap<std::pair<int, int>> h1(m); - TTopKeeper<std::pair<int, int>> h2(m); - + TLimitedHeap<std::pair<int, int>> h1(m); + TTopKeeper<std::pair<int, int>> h2(m); + int n = 20000000; while (n--) { int r = int(Rnd()); - h1.Insert({r, -r}); - h2.Emplace(r, -r); + h1.Insert({r, -r}); + h2.Emplace(r, -r); } h2.Finalize(); 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 a26d2576e9..a938279025 100644 --- a/library/cpp/containers/top_keeper/ut/top_keeper_ut.cpp +++ b/library/cpp/containers/top_keeper/ut/top_keeper_ut.cpp @@ -17,15 +17,15 @@ Y_UNIT_TEST_SUITE(TTopKeeperTest) { Y_UNIT_TEST(CorrectnessTest) { int m = 20000; - TLimitedHeap<std::pair<int, int>> h1(m); - TTopKeeper<std::pair<int, int>> h2(m); - + TLimitedHeap<std::pair<int, int>> h1(m); + TTopKeeper<std::pair<int, int>> h2(m); + int n = 20000000; while (n--) { int r = int(Rnd()); - h1.Insert({r, -r}); - h2.Emplace(r, -r); + h1.Insert({r, -r}); + h2.Emplace(r, -r); } h2.Finalize(); |