diff options
author | pozhilov <pozhilov@yandex-team.ru> | 2022-02-10 16:49:27 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:27 +0300 |
commit | 23bf1d16dddf213a6aa8e8d5c8621e1242a1f118 (patch) | |
tree | ed030ff443eb83431f11e53b6460b1b73d035412 /util/generic | |
parent | 7156b3713e77ce36387436e5558320917698b7a2 (diff) | |
download | ydb-23bf1d16dddf213a6aa8e8d5c8621e1242a1f118.tar.gz |
Restoring authorship annotation for <pozhilov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r-- | util/generic/fwd.h | 14 | ||||
-rw-r--r-- | util/generic/hash.cpp | 16 | ||||
-rw-r--r-- | util/generic/hash.h | 26 | ||||
-rw-r--r-- | util/generic/hash_ut.cpp | 80 | ||||
-rw-r--r-- | util/generic/is_in.h | 4 | ||||
-rw-r--r-- | util/generic/is_in_ut.cpp | 14 | ||||
-rw-r--r-- | util/generic/maybe.h | 2 | ||||
-rw-r--r-- | util/generic/ptr_ut.cpp | 56 | ||||
-rw-r--r-- | util/generic/strbuf_ut.cpp | 6 | ||||
-rw-r--r-- | util/generic/typetraits_ut.cpp | 4 | ||||
-rw-r--r-- | util/generic/utility.h | 8 | ||||
-rw-r--r-- | util/generic/ylimits.h | 4 | ||||
-rw-r--r-- | util/generic/ymath.h | 2 |
13 files changed, 118 insertions, 118 deletions
diff --git a/util/generic/fwd.h b/util/generic/fwd.h index 5cc2da40e5..6bc808a8c2 100644 --- a/util/generic/fwd.h +++ b/util/generic/fwd.h @@ -132,7 +132,7 @@ class TSharedPtr; template <class T, class C = TCopyNew, class D = TDelete> class TCopyPtr; - + template <class TPtr, class TCopy = TCopyNew> class TCowPtr; @@ -151,13 +151,13 @@ using TArrayPtr = TAutoPtr<T, TDeleteArray>; template <typename T> using TMallocPtr = TAutoPtr<T, TFree>; -//maybe -namespace NMaybe { - struct TPolicyUndefinedExcept; -} +//maybe +namespace NMaybe { + struct TPolicyUndefinedExcept; +} -template <class T, class Policy = ::NMaybe::TPolicyUndefinedExcept> -class TMaybe; +template <class T, class Policy = ::NMaybe::TPolicyUndefinedExcept> +class TMaybe; struct TGUID; diff --git a/util/generic/hash.cpp b/util/generic/hash.cpp index a674ee4538..bbc922072e 100644 --- a/util/generic/hash.cpp +++ b/util/generic/hash.cpp @@ -1,18 +1,18 @@ #include "hash.h" -#include <util/string/escape.h> +#include <util/string/escape.h> #include <util/string/cast.h> const void* const _yhashtable_empty_data[] = {(void*)3, nullptr, (void*)1}; - + TString NPrivate::MapKeyToString(TStringBuf key) { - constexpr size_t HASH_KEY_MAX_LENGTH = 500; - try { - return EscapeC(key.substr(0, HASH_KEY_MAX_LENGTH)); - } catch (...) { + constexpr size_t HASH_KEY_MAX_LENGTH = 500; + try { + return EscapeC(key.substr(0, HASH_KEY_MAX_LENGTH)); + } catch (...) { return "TStringBuf"; - } -} + } +} TString NPrivate::MapKeyToString(unsigned short key) { return ToString(key); diff --git a/util/generic/hash.h b/util/generic/hash.h index e46db21fa9..30d00685e8 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -1390,12 +1390,12 @@ void THashTable<V, K, HF, Ex, Eq, A>::copy_from_dynamic(const THashTable& ht) { #endif /* __STL_USE_EXCEPTIONS */ } -namespace NPrivate { +namespace NPrivate { template <class Key> inline TString MapKeyToString(const Key&) { return TypeName<Key>(); - } - + } + TString MapKeyToString(TStringBuf key); TString MapKeyToString(unsigned short key); TString MapKeyToString(short key); @@ -1405,22 +1405,22 @@ namespace NPrivate { TString MapKeyToString(long key); TString MapKeyToString(unsigned long long key); TString MapKeyToString(long long key); - + inline TString MapKeyToString(const TString& key) { - return MapKeyToString(TStringBuf(key)); - } - + return MapKeyToString(TStringBuf(key)); + } + inline TString MapKeyToString(const char* key) { - return MapKeyToString(TStringBuf(key)); - } - + return MapKeyToString(TStringBuf(key)); + } + inline TString MapKeyToString(char* key) { - return MapKeyToString(TStringBuf(key)); - } + return MapKeyToString(TStringBuf(key)); + } [[noreturn]] void ThrowKeyNotFoundInHashTableException(const TStringBuf keyRepresentation); } - + template <class Key, class T, class HashFcn, class EqualKey, class Alloc> class THashMap: public TMapOps<THashMap<Key, T, HashFcn, EqualKey, Alloc>> { private: diff --git a/util/generic/hash_ut.cpp b/util/generic/hash_ut.cpp index 0551d58770..3df3371dbe 100644 --- a/util/generic/hash_ut.cpp +++ b/util/generic/hash_ut.cpp @@ -21,11 +21,11 @@ class THashTest: public TTestBase { UNIT_TEST(TestHMMap1); UNIT_TEST(TestHMMapHas); UNIT_TEST(TestHSetConstructorsAndAssignments); - UNIT_TEST(TestHSetSize); + UNIT_TEST(TestHSetSize); UNIT_TEST(TestHSet2); UNIT_TEST(TestHSetEqualityOperator); UNIT_TEST(TestHMSetConstructorsAndAssignments); - UNIT_TEST(TestHMSetSize); + UNIT_TEST(TestHMSetSize); UNIT_TEST(TestHMSet1); UNIT_TEST(TestHMSetEqualityOperator); UNIT_TEST(TestHMSetEmplace); @@ -52,7 +52,7 @@ class THashTest: public TTestBase { UNIT_TEST(TestValueInitialization); UNIT_TEST(TestAssignmentClear); UNIT_TEST(TestReleaseNodes); - UNIT_TEST(TestAt); + UNIT_TEST(TestAt); UNIT_TEST(TestHMapInitializerList); UNIT_TEST(TestHMMapInitializerList); UNIT_TEST(TestHSetInitializerList); @@ -72,11 +72,11 @@ protected: void TestHMMap1(); void TestHMMapHas(); void TestHSetConstructorsAndAssignments(); - void TestHSetSize(); + void TestHSetSize(); void TestHSet2(); void TestHSetEqualityOperator(); void TestHMSetConstructorsAndAssignments(); - void TestHMSetSize(); + void TestHMSetSize(); void TestHMSet1(); void TestHMSetEqualityOperator(); void TestHMSetEmplace(); @@ -103,7 +103,7 @@ protected: void TestValueInitialization(); void TestAssignmentClear(); void TestReleaseNodes(); - void TestAt(); + void TestAt(); void TestHMapInitializerList(); void TestHMMapInitializerList(); void TestHSetInitializerList(); @@ -407,20 +407,20 @@ void THashTest::TestHSetConstructorsAndAssignments() { UNIT_ASSERT(c4.contains(3)); } -void THashTest::TestHSetSize() { +void THashTest::TestHSetSize() { using container = THashSet<int>; - - container c; - c.insert(100); - c.insert(200); - - UNIT_ASSERT_VALUES_EQUAL(2, c.size()); - - c.insert(200); - - UNIT_ASSERT_VALUES_EQUAL(2, c.size()); -} - + + container c; + c.insert(100); + c.insert(200); + + UNIT_ASSERT_VALUES_EQUAL(2, c.size()); + + c.insert(200); + + UNIT_ASSERT_VALUES_EQUAL(2, c.size()); +} + void THashTest::TestHSet2() { THashSet<int, THash<int>, TEqualTo<int>> s; auto p = s.insert(42); @@ -492,20 +492,20 @@ void THashTest::TestHMSetConstructorsAndAssignments() { UNIT_ASSERT(c3.find(400) != c3.end()); } -void THashTest::TestHMSetSize() { +void THashTest::TestHMSetSize() { using container = THashMultiSet<int>; - - container c; - c.insert(100); - c.insert(200); - - UNIT_ASSERT_VALUES_EQUAL(2, c.size()); - - c.insert(200); - - UNIT_ASSERT_VALUES_EQUAL(3, c.size()); -} - + + container c; + c.insert(100); + c.insert(200); + + UNIT_ASSERT_VALUES_EQUAL(2, c.size()); + + c.insert(200); + + UNIT_ASSERT_VALUES_EQUAL(3, c.size()); +} + void THashTest::TestHMSet1() { hmset s; UNIT_ASSERT(s.count(star) == 0); @@ -1111,8 +1111,8 @@ void THashTest::TestReleaseNodes() { set2.insert(1); UNIT_ASSERT_VALUES_EQUAL(set2.size(), 1); } - -void THashTest::TestAt() { + +void THashTest::TestAt() { #define TEST_AT_THROWN_EXCEPTION(SRC_TYPE, DST_TYPE, KEY_TYPE, KEY, MESSAGE) \ { \ THashMap<SRC_TYPE, DST_TYPE> testMap; \ @@ -1125,8 +1125,8 @@ void THashTest::TestAt() { } catch (...) { \ UNIT_ASSERT_C(false, "THashMap::at(\"" << KEY << "\") should throw yexception"); \ } \ - } - + } + TEST_AT_THROWN_EXCEPTION(TString, TString, TString, "111", "111"); TEST_AT_THROWN_EXCEPTION(TString, TString, const TString, "111", "111"); TEST_AT_THROWN_EXCEPTION(TString, TString, TStringBuf, "111", "111"); @@ -1140,13 +1140,13 @@ void THashTest::TestAt() { TEST_AT_THROWN_EXCEPTION(int, int, unsigned int, 2, "2"); TEST_AT_THROWN_EXCEPTION(int, int, unsigned long, 131, "131"); TEST_AT_THROWN_EXCEPTION(int, int, unsigned long long, 1000000000000ll, "1000000000000"); - + char key[] = {11, 12, 0, 1, 2, 11, 0}; TEST_AT_THROWN_EXCEPTION(TString, TString, char*, key, "\\x0B\\x0C"); TEST_AT_THROWN_EXCEPTION(TString, TString, TStringBuf, TStringBuf(key, sizeof(key) - 1), "\\x0B\\x0C\\0\\1\\2\\x0B"); - -#undef TEST_AT_THROWN_EXCEPTION -} + +#undef TEST_AT_THROWN_EXCEPTION +} void THashTest::TestHMapInitializerList() { THashMap<TString, TString> h1 = {{"foo", "bar"}, {"bar", "baz"}, {"baz", "qux"}}; diff --git a/util/generic/is_in.h b/util/generic/is_in.h index 4f175ea5eb..a3277f173d 100644 --- a/util/generic/is_in.h +++ b/util/generic/is_in.h @@ -47,7 +47,7 @@ static inline bool IsIn(const C& c, const T& e) { return TIsInTraits<C, T, TIsAssocCont<C>::value>::IsIn(c, e); } -template <class T, class U> -static inline bool IsIn(std::initializer_list<T> l, const U& e) { +template <class T, class U> +static inline bool IsIn(std::initializer_list<T> l, const U& e) { return ::IsIn(l.begin(), l.end(), e); } diff --git a/util/generic/is_in_ut.cpp b/util/generic/is_in_ut.cpp index c668bce807..1306e427e7 100644 --- a/util/generic/is_in_ut.cpp +++ b/util/generic/is_in_ut.cpp @@ -70,7 +70,7 @@ Y_UNIT_TEST_SUITE(TIsIn) { UNIT_ASSERT(IsIn(b, 'f')); UNIT_ASSERT(!IsIn(b, 'z')); } - + Y_UNIT_TEST(IsInInitListTest) { const char* abc = "abc"; const char* def = "def"; @@ -88,22 +88,22 @@ Y_UNIT_TEST_SUITE(TIsIn) { UNIT_ASSERT(!IsIn({TStringBuf("abc"), TStringBuf("def")}, TStringBuf("ghi"))); UNIT_ASSERT(!IsIn({"abc", "def"}, TStringBuf("ghi"))); UNIT_ASSERT(!IsIn({"abc", "def"}, TString("ghi"))); - - const TStringBuf str = "abc////"; - + + const TStringBuf str = "abc////"; + UNIT_ASSERT(IsIn({"abc", "def"}, TStringBuf{str.data(), 3})); } Y_UNIT_TEST(ConfOfTest) { UNIT_ASSERT(IsIn({1, 2, 3}, 1)); UNIT_ASSERT(!IsIn({1, 2, 3}, 4)); - + const TString b = "b"; - + UNIT_ASSERT(!IsIn({"a", "b", "c"}, b.data())); // compares pointers by value. Whether it's good or not. UNIT_ASSERT(IsIn(TVector<TStringBuf>({"a", "b", "c"}), b.data())); UNIT_ASSERT(IsIn(TVector<TStringBuf>({"a", "b", "c"}), "b")); - } + } Y_UNIT_TEST(IsInArrayTest) { const TString array[] = {"a", "b", "d"}; diff --git a/util/generic/maybe.h b/util/generic/maybe.h index 34d21aebcd..f009fdb1e9 100644 --- a/util/generic/maybe.h +++ b/util/generic/maybe.h @@ -34,7 +34,7 @@ constexpr bool operator==(TNothing, TNothing) noexcept { return true; } -template <class T, class Policy /*= ::NMaybe::TPolicyUndefinedExcept*/> +template <class T, class Policy /*= ::NMaybe::TPolicyUndefinedExcept*/> class TMaybe: private TMaybeBase<T> { public: using TInPlace = NMaybe::TInPlace; diff --git a/util/generic/ptr_ut.cpp b/util/generic/ptr_ut.cpp index c2dcff23f6..b8429f7ca2 100644 --- a/util/generic/ptr_ut.cpp +++ b/util/generic/ptr_ut.cpp @@ -20,7 +20,7 @@ class TPointerTest: public TTestBase { UNIT_TEST(TestHolderPtrMoveAssignmentInheritance); UNIT_TEST(TestMakeHolder); UNIT_TEST(TestTrulePtr); - UNIT_TEST(TestAutoToHolder); + UNIT_TEST(TestAutoToHolder); UNIT_TEST(TestCopyPtr); UNIT_TEST(TestIntrPtr); UNIT_TEST(TestIntrusiveConvertion); @@ -72,7 +72,7 @@ private: void TestHolderPtrMoveAssignmentInheritance(); void TestMakeHolder(); void TestTrulePtr(); - void TestAutoToHolder(); + void TestAutoToHolder(); void TestCopyPtr(); void TestIntrPtr(); void TestIntrusiveConvertion(); @@ -136,7 +136,7 @@ void TPointerTest::TestSimpleIntrPtr() { a2 = a3; } - UNIT_ASSERT_VALUES_EQUAL(cnt, 0); + UNIT_ASSERT_VALUES_EQUAL(cnt, 0); } void TPointerTest::TestHolderPtr() { @@ -145,7 +145,7 @@ void TPointerTest::TestHolderPtr() { THolder<A> a2(a1.Release()); } - UNIT_ASSERT_VALUES_EQUAL(cnt, 0); + UNIT_ASSERT_VALUES_EQUAL(cnt, 0); } THolder<int> CreateInt(int value) { @@ -246,19 +246,19 @@ void TPointerTest::TestTrulePtr() { a1 = a2; } - UNIT_ASSERT_VALUES_EQUAL(cnt, 0); + UNIT_ASSERT_VALUES_EQUAL(cnt, 0); } void TPointerTest::TestAutoToHolder() { - { + { TAutoPtr<A> a1(MakeA()); - THolder<A> a2(a1); - - UNIT_ASSERT_EQUAL(a1.Get(), nullptr); - UNIT_ASSERT_VALUES_EQUAL(cnt, 1); - } - - UNIT_ASSERT_VALUES_EQUAL(cnt, 0); + THolder<A> a2(a1); + + UNIT_ASSERT_EQUAL(a1.Get(), nullptr); + UNIT_ASSERT_VALUES_EQUAL(cnt, 1); + } + + UNIT_ASSERT_VALUES_EQUAL(cnt, 0); { TAutoPtr<A> x(new A()); @@ -276,22 +276,22 @@ void TPointerTest::TestAutoToHolder() { } UNIT_ASSERT_VALUES_EQUAL(cnt, 0); -} - +} + void TPointerTest::TestCopyPtr() { TCopyPtr<A> a1(MakeA()); { TCopyPtr<A> a2(MakeA()); TCopyPtr<A> a3 = a2; - UNIT_ASSERT_VALUES_EQUAL(cnt, 3); + UNIT_ASSERT_VALUES_EQUAL(cnt, 3); a1 = a2; a2 = a3; } - UNIT_ASSERT_VALUES_EQUAL(cnt, 1); + UNIT_ASSERT_VALUES_EQUAL(cnt, 1); a1.Destroy(); - UNIT_ASSERT_VALUES_EQUAL(cnt, 0); + UNIT_ASSERT_VALUES_EQUAL(cnt, 0); } class TOp: public TSimpleRefCount<TOp>, public TNonCopyable { @@ -348,20 +348,20 @@ void TPointerTest::TestIntrPtr() { f2.push_back(p); Attach(&op3, &f2[1]); f1 = f2; - UNIT_ASSERT_VALUES_EQUAL(f1[0]->RefCount(), 2); - UNIT_ASSERT_VALUES_EQUAL(f1[1]->RefCount(), 3); + UNIT_ASSERT_VALUES_EQUAL(f1[0]->RefCount(), 2); + UNIT_ASSERT_VALUES_EQUAL(f1[1]->RefCount(), 3); UNIT_ASSERT_EQUAL(f1[1].Get(), op3.Op2.Get()); - UNIT_ASSERT_VALUES_EQUAL(op3.Op2->RefCount(), 3); - UNIT_ASSERT_VALUES_EQUAL(op3.Op2->Op->RefCount(), 2); - UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 4); + UNIT_ASSERT_VALUES_EQUAL(op3.Op2->RefCount(), 3); + UNIT_ASSERT_VALUES_EQUAL(op3.Op2->Op->RefCount(), 2); + UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 4); } p2 = p; } - UNIT_ASSERT_VALUES_EQUAL(op3.Op2->RefCount(), 1); - UNIT_ASSERT_VALUES_EQUAL(op3.Op2->Op->RefCount(), 3); - UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 3); + UNIT_ASSERT_VALUES_EQUAL(op3.Op2->RefCount(), 1); + UNIT_ASSERT_VALUES_EQUAL(op3.Op2->Op->RefCount(), 3); + UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 3); } - UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 0); + UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 0); } namespace NTestIntrusiveConvertion { @@ -424,7 +424,7 @@ void TPointerTest::TestMakeIntrusive() { UNIT_ASSERT_VALUES_EQUAL(1, p->RefCount()); UNIT_ASSERT_VALUES_EQUAL(1, TOp::Cnt); } - UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 0); + UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 0); } void TPointerTest::TestCopyOnWritePtr1() { diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp index 69cde785af..28f6951b5f 100644 --- a/util/generic/strbuf_ut.cpp +++ b/util/generic/strbuf_ut.cpp @@ -197,10 +197,10 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { UNIT_ASSERT_EQUAL(buf2.RNextTok("@@"), TStringBuf("b")); UNIT_ASSERT_EQUAL(buf2.RNextTok("@@"), TStringBuf("a")); UNIT_ASSERT_EQUAL(buf2, TStringBuf()); - - TStringBuf buf3("a@@b@@c"); + + TStringBuf buf3("a@@b@@c"); UNIT_ASSERT_EQUAL(buf3.RNextTok("@@@"), TStringBuf("a@@b@@c")); - UNIT_ASSERT_EQUAL(buf3, TStringBuf()); + UNIT_ASSERT_EQUAL(buf3, TStringBuf()); } Y_UNIT_TEST(TestReadLine) { diff --git a/util/generic/typetraits_ut.cpp b/util/generic/typetraits_ut.cpp index e7571c75ec..fe3c6059b4 100644 --- a/util/generic/typetraits_ut.cpp +++ b/util/generic/typetraits_ut.cpp @@ -227,9 +227,9 @@ Y_UNIT_TEST_SUITE(TTypeTraitsTest) { UNIT_ASSERT(!std::is_standard_layout<TNonStdLayoutClass4>::value); } - template <class T> + template <class T> using TTrySum = decltype(std::declval<T>() + std::declval<T>()); - + Y_UNIT_TEST(TestIsTriviallyCopyable) { struct TPod { int value; diff --git a/util/generic/utility.h b/util/generic/utility.h index 43b98eeafc..96061fe45c 100644 --- a/util/generic/utility.h +++ b/util/generic/utility.h @@ -5,22 +5,22 @@ #include <cstring> template <class T> -static constexpr const T& Min(const T& l, const T& r) { +static constexpr const T& Min(const T& l, const T& r) { return r < l ? r : l; } template <typename T, typename... Args> -static constexpr const T& Min(const T& a, const T& b, const Args&... args) { +static constexpr const T& Min(const T& a, const T& b, const Args&... args) { return Min(a, Min(b, args...)); } template <class T> -static constexpr const T& Max(const T& l, const T& r) { +static constexpr const T& Max(const T& l, const T& r) { return l < r ? r : l; } template <typename T, typename... Args> -static constexpr const T& Max(const T& a, const T& b, const Args&... args) { +static constexpr const T& Max(const T& a, const T& b, const Args&... args) { return Max(a, Max(b, args...)); } diff --git a/util/generic/ylimits.h b/util/generic/ylimits.h index fe42b4dfc0..46c6cd5ed5 100644 --- a/util/generic/ylimits.h +++ b/util/generic/ylimits.h @@ -19,14 +19,14 @@ static constexpr T Min() noexcept { namespace NPrivate { struct TMax { template <class T> - constexpr operator T() const { + constexpr operator T() const { return Max<T>(); } }; struct TMin { template <class T> - constexpr operator T() const { + constexpr operator T() const { return Min<T>(); } }; diff --git a/util/generic/ymath.h b/util/generic/ymath.h index 9ff9ae2abe..5998207f9f 100644 --- a/util/generic/ymath.h +++ b/util/generic/ymath.h @@ -18,7 +18,7 @@ constexpr double M_LN2_INV = M_LOG2E; // 1 / ln(2) == log2(e) * \returns Absolute value of the provided argument. */ template <class T> -constexpr T Abs(T value) { +constexpr T Abs(T value) { return std::abs(value); } |