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 | 173c6a0fa7f439b2c207c2f258e52ccb4ac181cf (patch) | |
tree | ccc1431399e20197a8533f3d4bd0eb9a4bb8db62 | |
parent | da16e7702d9b0a8a42761ad877f102ef6aa85ec0 (diff) | |
download | ydb-173c6a0fa7f439b2c207c2f258e52ccb4ac181cf.tar.gz |
Restoring authorship annotation for <pavelgur@yandex-team.ru>. Commit 1 of 2.
-rw-r--r-- | library/cpp/accurate_accumulate/accurate_accumulate.h | 50 | ||||
-rw-r--r-- | library/cpp/containers/top_keeper/top_keeper.h | 170 | ||||
-rw-r--r-- | library/cpp/containers/top_keeper/top_keeper/top_keeper.h | 170 | ||||
-rw-r--r-- | library/cpp/containers/top_keeper/top_keeper/ut/top_keeper_ut.cpp | 10 | ||||
-rw-r--r-- | library/cpp/containers/top_keeper/ut/top_keeper_ut.cpp | 10 | ||||
-rw-r--r-- | util/charset/wide.h | 10 | ||||
-rw-r--r-- | util/digest/multi.cpp | 2 | ||||
-rw-r--r-- | util/digest/multi.h | 18 | ||||
-rw-r--r-- | util/digest/multi_ut.cpp | 38 | ||||
-rw-r--r-- | util/generic/algorithm.h | 8 | ||||
-rw-r--r-- | util/generic/array_ref.h | 6 | ||||
-rw-r--r-- | util/generic/array_ref_ut.cpp | 18 | ||||
-rw-r--r-- | util/generic/hash.h | 24 | ||||
-rw-r--r-- | util/generic/hash_set.h | 2 | ||||
-rw-r--r-- | util/generic/hash_ut.cpp | 22 | ||||
-rw-r--r-- | util/generic/noncopyable.h | 4 | ||||
-rw-r--r-- | util/generic/queue_ut.cpp | 42 | ||||
-rw-r--r-- | util/generic/utility.h | 24 | ||||
-rw-r--r-- | util/generic/utility_ut.cpp | 4 |
19 files changed, 316 insertions, 316 deletions
diff --git a/library/cpp/accurate_accumulate/accurate_accumulate.h b/library/cpp/accurate_accumulate/accurate_accumulate.h index dacced17e9..53ff04ef09 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 2f282b5a9e..1188c95733 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(T&& value) { - CheckNotFinalized(); - return Internal.Push(std::move(value)); + bool Insert(const T& value) { + CheckNotFinalized(); + return Internal.Push(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 2f282b5a9e..1188c95733 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(T&& value) { - CheckNotFinalized(); - return Internal.Push(std::move(value)); + bool Insert(const T& value) { + CheckNotFinalized(); + return Internal.Push(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 a938279025..a26d2576e9 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 a938279025..a26d2576e9 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(); diff --git a/util/charset/wide.h b/util/charset/wide.h index 04e6928aab..950c6c44e6 100644 --- a/util/charset/wide.h +++ b/util/charset/wide.h @@ -406,12 +406,12 @@ inline void WideToUTF8(const TCharType* text, size_t len, char* dest, size_t& wr written = p - reinterpret_cast<unsigned char*>(dest); } -constexpr size_t WideToUTF8BufferSize(const size_t inputStringSize) noexcept { - return inputStringSize * 4; // * 4 because the conversion functions can convert unicode character into maximum 4 bytes of UTF8 -} - +constexpr size_t WideToUTF8BufferSize(const size_t inputStringSize) noexcept { + return inputStringSize * 4; // * 4 because the conversion functions can convert unicode character into maximum 4 bytes of UTF8 +} + inline TStringBuf WideToUTF8(const TWtringBuf src, TString& dst) { - dst.ReserveAndResize(WideToUTF8BufferSize(src.size())); + dst.ReserveAndResize(WideToUTF8BufferSize(src.size())); size_t written = 0; WideToUTF8(src.data(), src.size(), dst.begin(), written); Y_ASSERT(dst.size() >= written); diff --git a/util/digest/multi.cpp b/util/digest/multi.cpp index e4a59f0e67..74db0818b7 100644 --- a/util/digest/multi.cpp +++ b/util/digest/multi.cpp @@ -1 +1 @@ -#include "multi.h" +#include "multi.h" diff --git a/util/digest/multi.h b/util/digest/multi.h index 8e4597c9dc..9b2d5f2f88 100644 --- a/util/digest/multi.h +++ b/util/digest/multi.h @@ -1,14 +1,14 @@ -#pragma once - -#include <util/str_stl.h> - -#include "numeric.h" - +#pragma once + +#include <util/str_stl.h> + +#include "numeric.h" + template <typename TOne> constexpr size_t MultiHash(const TOne& one) noexcept { - return THash<TOne>()(one); -} + return THash<TOne>()(one); +} template <typename THead, typename... TTail> constexpr size_t MultiHash(const THead& head, const TTail&... tail) noexcept { return CombineHashes(MultiHash(tail...), THash<THead>()(head)); -} +} diff --git a/util/digest/multi_ut.cpp b/util/digest/multi_ut.cpp index dff64ff0cc..9d508c4ce8 100644 --- a/util/digest/multi_ut.cpp +++ b/util/digest/multi_ut.cpp @@ -1,25 +1,25 @@ -#include "multi.h" - +#include "multi.h" + #include <library/cpp/testing/unittest/registar.h> - + #include <util/stream/output.h> - -class TMultiHashTest: public TTestBase { - UNIT_TEST_SUITE(TMultiHashTest); - UNIT_TEST(TestStrInt) - UNIT_TEST(TestIntStr) + +class TMultiHashTest: public TTestBase { + UNIT_TEST_SUITE(TMultiHashTest); + UNIT_TEST(TestStrInt) + UNIT_TEST(TestIntStr) UNIT_TEST(TestSimpleCollision) UNIT_TEST(TestTypes) - UNIT_TEST_SUITE_END(); - -private: - inline void TestStrInt() { + UNIT_TEST_SUITE_END(); + +private: + inline void TestStrInt() { UNIT_ASSERT_EQUAL(MultiHash(TString("1234567"), static_cast<int>(123)), static_cast<size_t>(ULL(17038203285960021630))); - } - - inline void TestIntStr() { + } + + inline void TestIntStr() { UNIT_ASSERT_EQUAL(MultiHash(static_cast<int>(123), TString("1234567")), static_cast<size_t>(ULL(9973288649881090712))); - } + } inline void TestSimpleCollision() { UNIT_ASSERT_UNEQUAL(MultiHash(1, 1, 0), MultiHash(2, 2, 0)); @@ -33,6 +33,6 @@ private: UNIT_ASSERT_EQUAL(MultiHash("aaa", (i64)-123), MultiHash("aaa", -123)); UNIT_ASSERT_EQUAL(MultiHash("aaa", (i32)-123), MultiHash("aaa", -123)); } -}; - -UNIT_TEST_SUITE_REGISTRATION(TMultiHashTest); +}; + +UNIT_TEST_SUITE_REGISTRATION(TMultiHashTest); diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h index badfb88993..2d184ee7e0 100644 --- a/util/generic/algorithm.h +++ b/util/generic/algorithm.h @@ -439,10 +439,10 @@ static inline void Fill(I f, I l, const T& v) { } template <typename I, typename S, typename T> -static inline I FillN(I f, S n, const T& v) { - return std::fill_n(f, n, v); -} - +static inline I FillN(I f, S n, const T& v) { + return std::fill_n(f, n, v); +} + template <class T> static inline void Reverse(T f, T l) { std::reverse(f, l); diff --git a/util/generic/array_ref.h b/util/generic/array_ref.h index 1ac60ac7d3..ddaf6bdceb 100644 --- a/util/generic/array_ref.h +++ b/util/generic/array_ref.h @@ -2,10 +2,10 @@ #include <util/generic/yexception.h> -#include <algorithm> +#include <algorithm> #include <initializer_list> #include <iterator> - + /** * `TArrayRef` works pretty much like `std::span` with dynamic extent, presenting * an array-like interface into a contiguous sequence of objects. @@ -77,7 +77,7 @@ public: bool operator==(const TArrayRef<TT>& other) const noexcept { return (S_ == other.size()) && std::equal(begin(), end(), other.begin()); } - + constexpr inline T* data() const noexcept { return T_; } diff --git a/util/generic/array_ref_ut.cpp b/util/generic/array_ref_ut.cpp index 4c8eaf7135..89add6e8d1 100644 --- a/util/generic/array_ref_ut.cpp +++ b/util/generic/array_ref_ut.cpp @@ -139,27 +139,27 @@ Y_UNIT_TEST_SUITE(TestArrayRef) { UNIT_ASSERT_VALUES_EQUAL(autoSizeRef[0], '4'); UNIT_ASSERT_VALUES_EQUAL(autoSizeRef[3], '\0'); } - + Y_UNIT_TEST(TestEqualityOperator) { - static constexpr size_t size = 5; + static constexpr size_t size = 5; int a[size]{1, 2, 3, 4, 5}; int b[size]{5, 4, 3, 2, 1}; int c[size - 1]{5, 4, 3, 2}; float d[size]{1.f, 2.f, 3.f, 4.f, 5.f}; - + TArrayRef<int> aRef(a); TConstArrayRef<int> aConstRef(a, size); - + TArrayRef<int> bRef(b); - + TArrayRef<int> cRef(c, size - 1); - + TArrayRef<float> dRef(d, size); TConstArrayRef<float> dConstRef(d, size); - + UNIT_ASSERT_EQUAL(aRef, aConstRef); UNIT_ASSERT_EQUAL(dRef, dConstRef); - + UNIT_ASSERT_UNEQUAL(aRef, cRef); UNIT_ASSERT_UNEQUAL(aRef, bRef); @@ -167,7 +167,7 @@ Y_UNIT_TEST_SUITE(TestArrayRef) { //Testing if operator== compares values, not pointers UNIT_ASSERT_EQUAL(cRef, bSubRef); - } + } Y_UNIT_TEST(TestImplicitConstructionFromContainer) { /* Just test compilation. */ diff --git a/util/generic/hash.h b/util/generic/hash.h index e46db21fa9..cb6672cf62 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -1461,7 +1461,7 @@ public: } template <class TAllocParam> explicit THashMap(TAllocParam* allocParam, size_type n = 0) - : rep(n, hasher(), key_equal(), allocParam) + : rep(n, hasher(), key_equal(), allocParam) { } explicit THashMap(size_type n) @@ -1509,13 +1509,13 @@ public: } THashMap(const std::initializer_list<std::pair<Key, T>>& list) - : rep(list.size(), hasher(), key_equal()) - { - for (const auto& v : list) { - rep.insert_unique_noresize(v); - } - } - + : rep(list.size(), hasher(), key_equal()) + { + for (const auto& v : list) { + rep.insert_unique_noresize(v); + } + } + // THashMap has implicit copy/move constructors and copy-/move-assignment operators // because its implementation is backed by THashTable. // See hash_ut.cpp @@ -1579,10 +1579,10 @@ public: return rep.insert_unique_noresize(obj); } - template <typename... Args> - std::pair<iterator, bool> emplace_noresize(Args&&... args) { - return rep.emplace_unique_noresize(std::forward<Args>(args)...); - } + template <typename... Args> + std::pair<iterator, bool> emplace_noresize(Args&&... args) { + return rep.emplace_unique_noresize(std::forward<Args>(args)...); + } template <class TheObj> iterator insert_direct(const TheObj& obj, const insert_ctx& ins) { diff --git a/util/generic/hash_set.h b/util/generic/hash_set.h index e8088cf23b..309782304a 100644 --- a/util/generic/hash_set.h +++ b/util/generic/hash_set.h @@ -47,7 +47,7 @@ public: } template <class TT> explicit THashSet(TT* allocParam, size_type n = 0) - : rep(n, hasher(), key_equal(), allocParam) + : rep(n, hasher(), key_equal(), allocParam) { } explicit THashSet(size_type n) diff --git a/util/generic/hash_ut.cpp b/util/generic/hash_ut.cpp index 0551d58770..873a5ecebc 100644 --- a/util/generic/hash_ut.cpp +++ b/util/generic/hash_ut.cpp @@ -147,19 +147,19 @@ void THashTest::TestHMapConstructorsAndAssignments() { UNIT_ASSERT_VALUES_EQUAL(0, c2.size()); UNIT_ASSERT_VALUES_EQUAL(4, c3.size()); UNIT_ASSERT_VALUES_EQUAL(4, c3.at("four")); - + const container c4{ {"one", 1}, {"two", 2}, - {"three", 3}, + {"three", 3}, {"four", 4}, - }; - - UNIT_ASSERT_VALUES_EQUAL(4, c4.size()); - UNIT_ASSERT_VALUES_EQUAL(1, c4.at("one")); - UNIT_ASSERT_VALUES_EQUAL(2, c4.at("two")); - UNIT_ASSERT_VALUES_EQUAL(3, c4.at("three")); - UNIT_ASSERT_VALUES_EQUAL(4, c4.at("four")); + }; + + UNIT_ASSERT_VALUES_EQUAL(4, c4.size()); + UNIT_ASSERT_VALUES_EQUAL(1, c4.at("one")); + UNIT_ASSERT_VALUES_EQUAL(2, c4.at("two")); + UNIT_ASSERT_VALUES_EQUAL(3, c4.at("three")); + UNIT_ASSERT_VALUES_EQUAL(4, c4.at("four")); // non-existent values must be zero-initialized UNIT_ASSERT_VALUES_EQUAL(c1["nonexistent"], 0); @@ -1035,8 +1035,8 @@ void THashTest::TestHSetEmplaceDirect() { hash.emplace_direct(ins, 1); UNIT_ASSERT(hash.contains(0)); UNIT_ASSERT(!hash.contains(1)); -} - +} + void THashTest::TestNonCopyable() { struct TValue: public TNonCopyable { int value; diff --git a/util/generic/noncopyable.h b/util/generic/noncopyable.h index c007934133..c4a1143f8b 100644 --- a/util/generic/noncopyable.h +++ b/util/generic/noncopyable.h @@ -23,8 +23,8 @@ namespace NNonCopyable { // protection from unintended ADL }; struct TMoveOnly { - TMoveOnly(TMoveOnly&&) noexcept = default; - TMoveOnly& operator=(TMoveOnly&&) noexcept = default; + TMoveOnly(TMoveOnly&&) noexcept = default; + TMoveOnly& operator=(TMoveOnly&&) noexcept = default; TMoveOnly(const TMoveOnly&) = delete; TMoveOnly& operator=(const TMoveOnly&) = delete; diff --git a/util/generic/queue_ut.cpp b/util/generic/queue_ut.cpp index a33399e104..c747e33ac4 100644 --- a/util/generic/queue_ut.cpp +++ b/util/generic/queue_ut.cpp @@ -130,28 +130,28 @@ Y_UNIT_TEST_SUITE(TYQueueTest) { Y_UNIT_TEST(pqueue4) { TDeque<int> c; - c.push_back(42); - c.push_back(101); - c.push_back(69); - + c.push_back(42); + c.push_back(101); + c.push_back(69); + TPriorityQueue<int, TDeque<int>, TLess<int>> q(TLess<int>(), std::move(c)); - - UNIT_ASSERT(c.empty()); - - UNIT_ASSERT_EQUAL(q.size(), 3); - - UNIT_ASSERT(q.top() == 101); - - q.pop(); - UNIT_ASSERT(q.top() == 69); - - q.pop(); - UNIT_ASSERT(q.top() == 42); - - q.pop(); - UNIT_ASSERT(q.empty()); - } - + + UNIT_ASSERT(c.empty()); + + UNIT_ASSERT_EQUAL(q.size(), 3); + + UNIT_ASSERT(q.top() == 101); + + q.pop(); + UNIT_ASSERT(q.top() == 69); + + q.pop(); + UNIT_ASSERT(q.top() == 42); + + q.pop(); + UNIT_ASSERT(q.empty()); + } + Y_UNIT_TEST(queue1) { TQueue<int, TList<int>> q; diff --git a/util/generic/utility.h b/util/generic/utility.h index 43b98eeafc..36501499b7 100644 --- a/util/generic/utility.h +++ b/util/generic/utility.h @@ -30,18 +30,18 @@ constexpr const T& ClampVal(const T& val, const T& min, const T& max) { return val < min ? min : (max < val ? max : val); } -template <typename T = double, typename... Args> -static T Mean(const Args&... other) noexcept { - const auto numArgs = sizeof...(other); - - auto sum = T(); - for (const auto& v : {other...}) { - sum += v; - } - - return sum / numArgs; -} - +template <typename T = double, typename... Args> +static T Mean(const Args&... other) noexcept { + const auto numArgs = sizeof...(other); + + auto sum = T(); + for (const auto& v : {other...}) { + sum += v; + } + + return sum / numArgs; +} + template <class T> static inline void Zero(T& t) noexcept { memset((void*)&t, 0, sizeof(t)); diff --git a/util/generic/utility_ut.cpp b/util/generic/utility_ut.cpp index 8e9d5afff9..c2893dca03 100644 --- a/util/generic/utility_ut.cpp +++ b/util/generic/utility_ut.cpp @@ -1,5 +1,5 @@ #include "utility.h" -#include "ymath.h" +#include "ymath.h" #include <library/cpp/testing/unittest/registar.h> @@ -66,7 +66,7 @@ Y_UNIT_TEST_SUITE(TUtilityTest) { UNIT_ASSERT_VALUES_EQUAL(Min(TUnorderedTag{"first"}, TUnorderedTag{"second"}, TUnorderedTag{"third"}).Tag, "first"); UNIT_ASSERT_VALUES_EQUAL(Max(TUnorderedTag{"first"}, TUnorderedTag{"second"}, TUnorderedTag{"third"}).Tag, "first"); } - + Y_UNIT_TEST(TestMean) { UNIT_ASSERT_EQUAL(Mean(5), 5); UNIT_ASSERT_EQUAL(Mean(1, 2, 3), 2); |