diff options
author | bulatman <bulatman@yandex-team.ru> | 2022-02-10 16:45:50 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:50 +0300 |
commit | 2f6ca198245aeffd5e2d82b65927c2465b68b4f5 (patch) | |
tree | 9142afc54d335ea52910662635b898e79e192e49 /util/generic | |
parent | 6560e4993b14d193f8c879e33a3de5e5eba6e21d (diff) | |
download | ydb-2f6ca198245aeffd5e2d82b65927c2465b68b4f5.tar.gz |
Restoring authorship annotation for <bulatman@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r-- | util/generic/algorithm.h | 88 | ||||
-rw-r--r-- | util/generic/algorithm_ut.cpp | 62 | ||||
-rw-r--r-- | util/generic/benchmark/fastclp2/ya.make | 2 | ||||
-rw-r--r-- | util/generic/benchmark/log2/ya.make | 2 | ||||
-rw-r--r-- | util/generic/benchmark/rotate_bits/ya.make | 2 | ||||
-rw-r--r-- | util/generic/benchmark/singleton/ya.make | 2 | ||||
-rw-r--r-- | util/generic/benchmark/smart_pointers/ya.make | 2 | ||||
-rw-r--r-- | util/generic/benchmark/sort/ya.make | 2 | ||||
-rw-r--r-- | util/generic/benchmark/vector_count_ctor/ya.make | 2 | ||||
-rw-r--r-- | util/generic/buffer.h | 22 | ||||
-rw-r--r-- | util/generic/buffer_ut.cpp | 24 | ||||
-rw-r--r-- | util/generic/hash.h | 22 | ||||
-rw-r--r-- | util/generic/hash_ut.cpp | 112 | ||||
-rw-r--r-- | util/generic/typetraits.h | 14 | ||||
-rw-r--r-- | util/generic/yexception.h | 4 |
15 files changed, 181 insertions, 181 deletions
diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h index 0561a5cc15..badfb88993 100644 --- a/util/generic/algorithm.h +++ b/util/generic/algorithm.h @@ -562,61 +562,61 @@ inline void ForEach(TI f, TI l, TOp op) { namespace NPrivate { template <class T, class TOp, size_t... Is> - constexpr bool AllOfImpl(T&& t, TOp&& op, std::index_sequence<Is...>) { -#if _LIBCPP_STD_VER >= 17 - return (true && ... && op(std::get<Is>(std::forward<T>(t)))); -#else - bool result = true; - auto wrapper = [&result, &op](auto&& x) { result = result && op(std::forward<decltype(x)>(x)); }; - int dummy[] = {(wrapper(std::get<Is>(std::forward<T>(t))), 0)...}; - Y_UNUSED(dummy); - return result; -#endif - } - - template <class T, class TOp, size_t... Is> - constexpr bool AnyOfImpl(T&& t, TOp&& op, std::index_sequence<Is...>) { -#if _LIBCPP_STD_VER >= 17 - return (false || ... || op(std::get<Is>(std::forward<T>(t)))); -#else - bool result = false; - auto wrapper = [&result, &op](auto&& x) { result = result || op(std::forward<decltype(x)>(x)); }; - int dummy[] = {(wrapper(std::get<Is>(std::forward<T>(t))), 0)...}; - Y_UNUSED(dummy); - return result; -#endif - } - - template <class T, class TOp, size_t... Is> - constexpr void ForEachImpl(T&& t, TOp&& op, std::index_sequence<Is...>) { -#if _LIBCPP_STD_VER >= 17 - (..., op(std::get<Is>(std::forward<T>(t)))); -#else + constexpr bool AllOfImpl(T&& t, TOp&& op, std::index_sequence<Is...>) { +#if _LIBCPP_STD_VER >= 17 + return (true && ... && op(std::get<Is>(std::forward<T>(t)))); +#else + bool result = true; + auto wrapper = [&result, &op](auto&& x) { result = result && op(std::forward<decltype(x)>(x)); }; + int dummy[] = {(wrapper(std::get<Is>(std::forward<T>(t))), 0)...}; + Y_UNUSED(dummy); + return result; +#endif + } + + template <class T, class TOp, size_t... Is> + constexpr bool AnyOfImpl(T&& t, TOp&& op, std::index_sequence<Is...>) { +#if _LIBCPP_STD_VER >= 17 + return (false || ... || op(std::get<Is>(std::forward<T>(t)))); +#else + bool result = false; + auto wrapper = [&result, &op](auto&& x) { result = result || op(std::forward<decltype(x)>(x)); }; + int dummy[] = {(wrapper(std::get<Is>(std::forward<T>(t))), 0)...}; + Y_UNUSED(dummy); + return result; +#endif + } + + template <class T, class TOp, size_t... Is> + constexpr void ForEachImpl(T&& t, TOp&& op, std::index_sequence<Is...>) { +#if _LIBCPP_STD_VER >= 17 + (..., op(std::get<Is>(std::forward<T>(t)))); +#else ::ApplyToMany(std::forward<TOp>(op), std::get<Is>(std::forward<T>(t))...); -#endif +#endif } } -// check that TOp return true for all of element from tuple T +// check that TOp return true for all of element from tuple T template <class T, class TOp> -constexpr ::TEnableIfTuple<T, bool> AllOf(T&& t, TOp&& op) { - return ::NPrivate::AllOfImpl( +constexpr ::TEnableIfTuple<T, bool> AllOf(T&& t, TOp&& op) { + return ::NPrivate::AllOfImpl( std::forward<T>(t), std::forward<TOp>(op), std::make_index_sequence<std::tuple_size<std::decay_t<T>>::value>{}); -} - -// check that TOp return true for at least one element from tuple T -template <class T, class TOp> -constexpr ::TEnableIfTuple<T, bool> AnyOf(T&& t, TOp&& op) { - return ::NPrivate::AnyOfImpl( +} + +// check that TOp return true for at least one element from tuple T +template <class T, class TOp> +constexpr ::TEnableIfTuple<T, bool> AnyOf(T&& t, TOp&& op) { + return ::NPrivate::AnyOfImpl( std::forward<T>(t), std::forward<TOp>(op), std::make_index_sequence<std::tuple_size<std::decay_t<T>>::value>{}); -} - -template <class T, class TOp> -constexpr ::TEnableIfTuple<T> ForEach(T&& t, TOp&& op) { +} + +template <class T, class TOp> +constexpr ::TEnableIfTuple<T> ForEach(T&& t, TOp&& op) { ::NPrivate::ForEachImpl( std::forward<T>(t), std::forward<TOp>(op), diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp index 9dd7632f5c..8d732fcc0c 100644 --- a/util/generic/algorithm_ut.cpp +++ b/util/generic/algorithm_ut.cpp @@ -720,42 +720,42 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } Y_UNIT_TEST(TestTupleForEach) { - ForEach(std::tuple<>{}, [&](auto) { UNIT_ASSERT(false); }); + ForEach(std::tuple<>{}, [&](auto) { UNIT_ASSERT(false); }); auto t = std::make_tuple(5, 6, 2, 3, 6); ForEach(t, [](auto& v) { v *= -1; }); UNIT_ASSERT_EQUAL(t, std::make_tuple(-5, -6, -2, -3, -6)); } - Y_UNIT_TEST(TestTupleAllOf) { - UNIT_ASSERT(AllOf(std::tuple<>{}, [](auto) { return false; })); - UNIT_ASSERT(!AllOf(std::make_tuple(1, 2, 0, 4, 5), [&](auto v) { UNIT_ASSERT_LT(v, 3); return 0 != v; })); - UNIT_ASSERT(AllOf(std::make_tuple(1, 2, 3, 4, 5), [](auto v) { return 0 != v; })); - { - auto pred = std::function<bool(int)>([x = TVector<int>(1, 0)](auto v) { return x.front() != v; }); - UNIT_ASSERT(AllOf(std::make_tuple(1, 2), pred)); - UNIT_ASSERT(AllOf(std::make_tuple(1, 2), pred)); - } - { - auto ts = std::make_tuple(TString{"foo"}, TString{"bar"}); - auto pred = [](auto s) { return s.size() == 3; }; - UNIT_ASSERT_VALUES_EQUAL(AllOf(ts, pred), AllOf(ts, pred)); - } - } - - Y_UNIT_TEST(TestTupleAnyOf) { - UNIT_ASSERT(!AnyOf(std::tuple<>{}, [](auto) { return true; })); - UNIT_ASSERT(AnyOf(std::make_tuple(0, 1, 2, 3, 4), [&](auto v) { UNIT_ASSERT_LT(v, 2); return 1 == v; })); - UNIT_ASSERT(AnyOf(std::make_tuple(1, 2, 3, 4, 5), [](auto v) { return 5 == v; })); - auto pred = std::function<bool(int)>([x = TVector<int>(1, 0)](auto v) { return x.front() == v; }); - UNIT_ASSERT(!AnyOf(std::make_tuple(1, 2), pred)); - UNIT_ASSERT(!AnyOf(std::make_tuple(1, 2), pred)); - { - auto ts = std::make_tuple(TString{"f"}, TString{"bar"}); - auto pred = [](auto s) { return s.size() == 3; }; - UNIT_ASSERT_VALUES_EQUAL(AnyOf(ts, pred), AnyOf(ts, pred)); - } - } - + Y_UNIT_TEST(TestTupleAllOf) { + UNIT_ASSERT(AllOf(std::tuple<>{}, [](auto) { return false; })); + UNIT_ASSERT(!AllOf(std::make_tuple(1, 2, 0, 4, 5), [&](auto v) { UNIT_ASSERT_LT(v, 3); return 0 != v; })); + UNIT_ASSERT(AllOf(std::make_tuple(1, 2, 3, 4, 5), [](auto v) { return 0 != v; })); + { + auto pred = std::function<bool(int)>([x = TVector<int>(1, 0)](auto v) { return x.front() != v; }); + UNIT_ASSERT(AllOf(std::make_tuple(1, 2), pred)); + UNIT_ASSERT(AllOf(std::make_tuple(1, 2), pred)); + } + { + auto ts = std::make_tuple(TString{"foo"}, TString{"bar"}); + auto pred = [](auto s) { return s.size() == 3; }; + UNIT_ASSERT_VALUES_EQUAL(AllOf(ts, pred), AllOf(ts, pred)); + } + } + + Y_UNIT_TEST(TestTupleAnyOf) { + UNIT_ASSERT(!AnyOf(std::tuple<>{}, [](auto) { return true; })); + UNIT_ASSERT(AnyOf(std::make_tuple(0, 1, 2, 3, 4), [&](auto v) { UNIT_ASSERT_LT(v, 2); return 1 == v; })); + UNIT_ASSERT(AnyOf(std::make_tuple(1, 2, 3, 4, 5), [](auto v) { return 5 == v; })); + auto pred = std::function<bool(int)>([x = TVector<int>(1, 0)](auto v) { return x.front() == v; }); + UNIT_ASSERT(!AnyOf(std::make_tuple(1, 2), pred)); + UNIT_ASSERT(!AnyOf(std::make_tuple(1, 2), pred)); + { + auto ts = std::make_tuple(TString{"f"}, TString{"bar"}); + auto pred = [](auto s) { return s.size() == 3; }; + UNIT_ASSERT_VALUES_EQUAL(AnyOf(ts, pred), AnyOf(ts, pred)); + } + } + Y_UNIT_TEST(FindIfForContainer) { using std::begin; using std::end; diff --git a/util/generic/benchmark/fastclp2/ya.make b/util/generic/benchmark/fastclp2/ya.make index 5088daa2f3..976977014f 100644 --- a/util/generic/benchmark/fastclp2/ya.make +++ b/util/generic/benchmark/fastclp2/ya.make @@ -4,7 +4,7 @@ OWNER( ) SUBSCRIBER(g:util-subscribers) -Y_BENCHMARK() +Y_BENCHMARK() SRCS( main.cpp diff --git a/util/generic/benchmark/log2/ya.make b/util/generic/benchmark/log2/ya.make index c5202ae100..45d751909e 100644 --- a/util/generic/benchmark/log2/ya.make +++ b/util/generic/benchmark/log2/ya.make @@ -4,7 +4,7 @@ OWNER( ) SUBSCRIBER(g:util-subscribers) -Y_BENCHMARK() +Y_BENCHMARK() SRCS( main.cpp diff --git a/util/generic/benchmark/rotate_bits/ya.make b/util/generic/benchmark/rotate_bits/ya.make index 5088daa2f3..976977014f 100644 --- a/util/generic/benchmark/rotate_bits/ya.make +++ b/util/generic/benchmark/rotate_bits/ya.make @@ -4,7 +4,7 @@ OWNER( ) SUBSCRIBER(g:util-subscribers) -Y_BENCHMARK() +Y_BENCHMARK() SRCS( main.cpp diff --git a/util/generic/benchmark/singleton/ya.make b/util/generic/benchmark/singleton/ya.make index 79e15aa8e4..12d3d316c8 100644 --- a/util/generic/benchmark/singleton/ya.make +++ b/util/generic/benchmark/singleton/ya.make @@ -1,4 +1,4 @@ -Y_BENCHMARK() +Y_BENCHMARK() OWNER(g:util) SUBSCRIBER(g:util-subscribers) diff --git a/util/generic/benchmark/smart_pointers/ya.make b/util/generic/benchmark/smart_pointers/ya.make index ea15a55136..7059abc3a4 100644 --- a/util/generic/benchmark/smart_pointers/ya.make +++ b/util/generic/benchmark/smart_pointers/ya.make @@ -1,4 +1,4 @@ -Y_BENCHMARK() +Y_BENCHMARK() OWNER(g:util) SUBSCRIBER(g:util-subscribers) diff --git a/util/generic/benchmark/sort/ya.make b/util/generic/benchmark/sort/ya.make index ea15a55136..7059abc3a4 100644 --- a/util/generic/benchmark/sort/ya.make +++ b/util/generic/benchmark/sort/ya.make @@ -1,4 +1,4 @@ -Y_BENCHMARK() +Y_BENCHMARK() OWNER(g:util) SUBSCRIBER(g:util-subscribers) diff --git a/util/generic/benchmark/vector_count_ctor/ya.make b/util/generic/benchmark/vector_count_ctor/ya.make index c6f415cde0..42ce442819 100644 --- a/util/generic/benchmark/vector_count_ctor/ya.make +++ b/util/generic/benchmark/vector_count_ctor/ya.make @@ -4,7 +4,7 @@ OWNER( ) SUBSCRIBER(g:util-subscribers) -Y_BENCHMARK() +Y_BENCHMARK() ALLOCATOR(B) diff --git a/util/generic/buffer.h b/util/generic/buffer.h index 51f6fb20a4..9576467404 100644 --- a/util/generic/buffer.h +++ b/util/generic/buffer.h @@ -223,17 +223,17 @@ public: return Begin() + Size(); } - bool operator==(const TBuffer& other) const noexcept { - if (Empty()) { - return other.Empty(); - } - return Size() == other.Size() && 0 == std::memcmp(Data(), other.Data(), Size()); - } - - bool operator!=(const TBuffer& other) const noexcept { - return !(*this == other); - } - + bool operator==(const TBuffer& other) const noexcept { + if (Empty()) { + return other.Empty(); + } + return Size() == other.Size() && 0 == std::memcmp(Data(), other.Data(), Size()); + } + + bool operator!=(const TBuffer& other) const noexcept { + return !(*this == other); + } + private: void DoReserve(size_t len); void Realloc(size_t len); diff --git a/util/generic/buffer_ut.cpp b/util/generic/buffer_ut.cpp index 370fbedc75..437d7122ec 100644 --- a/util/generic/buffer_ut.cpp +++ b/util/generic/buffer_ut.cpp @@ -190,16 +190,16 @@ Y_UNIT_TEST(TestSpeed) { UNIT_ASSERT_VALUES_EQUAL(TString(buf.data(), buf.size()), "Some text."); } - Y_UNIT_TEST(TestComparison) { - TBuffer buf1("abcd", 4); - TBuffer buf2("abcde", 5); - TBuffer empty; - UNIT_ASSERT(empty == empty); - UNIT_ASSERT(!(empty != empty)); - UNIT_ASSERT(buf1 != buf2); - UNIT_ASSERT(buf1 == buf1); - buf2.EraseBack(1); - UNIT_ASSERT(buf2 == buf1); - } - + Y_UNIT_TEST(TestComparison) { + TBuffer buf1("abcd", 4); + TBuffer buf2("abcde", 5); + TBuffer empty; + UNIT_ASSERT(empty == empty); + UNIT_ASSERT(!(empty != empty)); + UNIT_ASSERT(buf1 != buf2); + UNIT_ASSERT(buf1 == buf1); + buf2.EraseBack(1); + UNIT_ASSERT(buf2 == buf1); + } + } diff --git a/util/generic/hash.h b/util/generic/hash.h index 207c9d3484..e46db21fa9 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -1594,19 +1594,19 @@ public: return rep.emplace_direct(ins, std::forward<Args>(args)...); } - template <typename TKey, typename... Args> - std::pair<iterator, bool> try_emplace(TKey&& key, Args&&... args) { - insert_ctx ctx = nullptr; - iterator it = find(key, ctx); - if (it == end()) { - it = rep.emplace_direct(ctx, std::piecewise_construct, + template <typename TKey, typename... Args> + std::pair<iterator, bool> try_emplace(TKey&& key, Args&&... args) { + insert_ctx ctx = nullptr; + iterator it = find(key, ctx); + if (it == end()) { + it = rep.emplace_direct(ctx, std::piecewise_construct, std::forward_as_tuple(std::forward<TKey>(key)), std::forward_as_tuple(std::forward<Args>(args)...)); - return {it, true}; - } - return {it, false}; - } - + return {it, true}; + } + return {it, false}; + } + template <class TheKey> iterator find(const TheKey& key) { return rep.find(key); diff --git a/util/generic/hash_ut.cpp b/util/generic/hash_ut.cpp index e1feefd2d3..0551d58770 100644 --- a/util/generic/hash_ut.cpp +++ b/util/generic/hash_ut.cpp @@ -40,8 +40,8 @@ class THashTest: public TTestBase { UNIT_TEST(TestEmplace); UNIT_TEST(TestEmplaceNoresize); UNIT_TEST(TestEmplaceDirect); - UNIT_TEST(TestTryEmplace); - UNIT_TEST(TestTryEmplaceCopyKey); + UNIT_TEST(TestTryEmplace); + UNIT_TEST(TestTryEmplaceCopyKey); UNIT_TEST(TestHMMapEmplace); UNIT_TEST(TestHMMapEmplaceNoresize); UNIT_TEST(TestHMMapEmplaceDirect); @@ -91,8 +91,8 @@ protected: void TestEmplace(); void TestEmplaceNoresize(); void TestEmplaceDirect(); - void TestTryEmplace(); - void TestTryEmplaceCopyKey(); + void TestTryEmplace(); + void TestTryEmplaceCopyKey(); void TestHSetEmplace(); void TestHSetEmplaceNoresize(); void TestHSetEmplaceDirect(); @@ -914,39 +914,39 @@ void THashTest::TestEmplaceDirect() { UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); } -void THashTest::TestTryEmplace() { - static unsigned counter = 0u; - - struct TCountConstruct { +void THashTest::TestTryEmplace() { + static unsigned counter = 0u; + + struct TCountConstruct { explicit TCountConstruct(int v) : value(v) { ++counter; } - TCountConstruct(const TCountConstruct&) = delete; - int value; - }; - - THashMap<int, TCountConstruct> hash; - { - // try_emplace does not copy key if key is rvalue - auto r = hash.try_emplace(TNonCopyableInt<0>(0), 1); - UNIT_ASSERT(r.second); - UNIT_ASSERT_VALUES_EQUAL(1, counter); - UNIT_ASSERT_VALUES_EQUAL(1, r.first->second.value); - } - { - auto r = hash.try_emplace(0, 2); - UNIT_ASSERT(!r.second); - UNIT_ASSERT_VALUES_EQUAL(1, counter); - UNIT_ASSERT_VALUES_EQUAL(1, r.first->second.value); - } -} - -void THashTest::TestTryEmplaceCopyKey() { - static unsigned counter = 0u; - - struct TCountCopy { + TCountConstruct(const TCountConstruct&) = delete; + int value; + }; + + THashMap<int, TCountConstruct> hash; + { + // try_emplace does not copy key if key is rvalue + auto r = hash.try_emplace(TNonCopyableInt<0>(0), 1); + UNIT_ASSERT(r.second); + UNIT_ASSERT_VALUES_EQUAL(1, counter); + UNIT_ASSERT_VALUES_EQUAL(1, r.first->second.value); + } + { + auto r = hash.try_emplace(0, 2); + UNIT_ASSERT(!r.second); + UNIT_ASSERT_VALUES_EQUAL(1, counter); + UNIT_ASSERT_VALUES_EQUAL(1, r.first->second.value); + } +} + +void THashTest::TestTryEmplaceCopyKey() { + static unsigned counter = 0u; + + struct TCountCopy { explicit TCountCopy(int i) : Value(i) { @@ -956,30 +956,30 @@ void THashTest::TestTryEmplaceCopyKey() { { ++counter; } - - operator int() const { - return Value; - } - - int Value; - }; - - THashMap<TCountCopy, TNonCopyableInt<0>> hash; - TCountCopy key(1); - { - // try_emplace copy key if key is lvalue - auto r = hash.try_emplace(key, 1); - UNIT_ASSERT(r.second); - UNIT_ASSERT_VALUES_EQUAL(1, counter); - } - { - // no insert - no copy - auto r = hash.try_emplace(key, 2); - UNIT_ASSERT(!r.second); - UNIT_ASSERT_VALUES_EQUAL(1, counter); - } -} - + + operator int() const { + return Value; + } + + int Value; + }; + + THashMap<TCountCopy, TNonCopyableInt<0>> hash; + TCountCopy key(1); + { + // try_emplace copy key if key is lvalue + auto r = hash.try_emplace(key, 1); + UNIT_ASSERT(r.second); + UNIT_ASSERT_VALUES_EQUAL(1, counter); + } + { + // no insert - no copy + auto r = hash.try_emplace(key, 2); + UNIT_ASSERT(!r.second); + UNIT_ASSERT_VALUES_EQUAL(1, counter); + } +} + void THashTest::TestHMMapEmplace() { using hash_t = THashMultiMap<int, TNonCopyableInt<0>>; hash_t hash; diff --git a/util/generic/typetraits.h b/util/generic/typetraits.h index d4156c709e..d165bd1a06 100644 --- a/util/generic/typetraits.h +++ b/util/generic/typetraits.h @@ -282,7 +282,7 @@ struct TIsSpecializationOf<T, T<Ts...>>: std::true_type {}; */ template <typename... T> constexpr bool TDependentFalse = false; - + // FIXME: neither nvcc10 nor nvcc11 support using auto in this context #if defined(__NVCC__) template <size_t Value> @@ -292,14 +292,14 @@ template <auto... Values> constexpr bool TValueDependentFalse = false; #endif -/* - * shortcut for std::enable_if_t<...> which checks that T is std::tuple or std::pair - */ -template <class T, class R = void> -using TEnableIfTuple = std::enable_if_t<::TDisjunction<::TIsSpecializationOf<std::tuple, std::decay_t<T>>, +/* + * shortcut for std::enable_if_t<...> which checks that T is std::tuple or std::pair + */ +template <class T, class R = void> +using TEnableIfTuple = std::enable_if_t<::TDisjunction<::TIsSpecializationOf<std::tuple, std::decay_t<T>>, ::TIsSpecializationOf<std::pair, std::decay_t<T>>>::value, R>; - + namespace NPrivate { // To allow ADL with custom begin/end using std::begin; diff --git a/util/generic/yexception.h b/util/generic/yexception.h index 17320e1762..b0c604e8c4 100644 --- a/util/generic/yexception.h +++ b/util/generic/yexception.h @@ -66,8 +66,8 @@ namespace NPrivateException { }; template <class E, class T> - static inline std::enable_if_t<std::is_base_of<yexception, std::decay_t<E>>::value, E&&> - operator<<(E&& e, const T& t) { + static inline std::enable_if_t<std::is_base_of<yexception, std::decay_t<E>>::value, E&&> + operator<<(E&& e, const T& t) { e.Append(t); return std::forward<E>(e); |