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 | 6560e4993b14d193f8c879e33a3de5e5eba6e21d (patch) | |
tree | cfd2e2baa05c3196f2caacbb63c32e1df40bc3de /util | |
parent | 7489e4682331202b9c7d863c0898eb83d7b12c2b (diff) | |
download | ydb-6560e4993b14d193f8c879e33a3de5e5eba6e21d.tar.gz |
Restoring authorship annotation for <bulatman@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util')
32 files changed, 323 insertions, 323 deletions
diff --git a/util/charset/benchmark/to_lower/ya.make b/util/charset/benchmark/to_lower/ya.make index 74c47e6de5..3cfdb8affc 100644 --- a/util/charset/benchmark/to_lower/ya.make +++ b/util/charset/benchmark/to_lower/ya.make @@ -1,6 +1,6 @@ OWNER(yazevnul) -Y_BENCHMARK() +Y_BENCHMARK() ALLOCATOR(B) diff --git a/util/charset/benchmark/utf8_to_wide/ya.make b/util/charset/benchmark/utf8_to_wide/ya.make index 4631fd7c41..121bea0ac8 100644 --- a/util/charset/benchmark/utf8_to_wide/ya.make +++ b/util/charset/benchmark/utf8_to_wide/ya.make @@ -1,4 +1,4 @@ -Y_BENCHMARK() +Y_BENCHMARK() OWNER(agorodilov) diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h index badfb88993..0561a5cc15 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 8d732fcc0c..9dd7632f5c 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 976977014f..5088daa2f3 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 45d751909e..c5202ae100 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 976977014f..5088daa2f3 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 12d3d316c8..79e15aa8e4 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 7059abc3a4..ea15a55136 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 7059abc3a4..ea15a55136 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 42ce442819..c6f415cde0 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 9576467404..51f6fb20a4 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 437d7122ec..370fbedc75 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 e46db21fa9..207c9d3484 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 0551d58770..e1feefd2d3 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 d165bd1a06..d4156c709e 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 b0c604e8c4..17320e1762 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); diff --git a/util/memory/benchmark/pool/ya.make b/util/memory/benchmark/pool/ya.make index 5f4f7d3f15..f3f25bd15a 100644 --- a/util/memory/benchmark/pool/ya.make +++ b/util/memory/benchmark/pool/ya.make @@ -1,7 +1,7 @@ OWNER(g:util) SUBSCRIBER(g:util-subscribers) -Y_BENCHMARK() +Y_BENCHMARK() SRCS( main.cpp diff --git a/util/network/socket.cpp b/util/network/socket.cpp index 4f6e804346..47ae44c51f 100644 --- a/util/network/socket.cpp +++ b/util/network/socket.cpp @@ -44,7 +44,7 @@ #include <util/generic/hash_set.h> #include <stddef.h> -#include <sys/uio.h> +#include <sys/uio.h> using namespace NAddr; @@ -539,7 +539,7 @@ ESocketReadStatus HasSocketDataToRead(SOCKET s) { #if defined(_win_) static ssize_t DoSendMsg(SOCKET sock, const struct iovec* iov, int iovcnt) { - return writev(sock, iov, iovcnt); + return writev(sock, iov, iovcnt); } #else static ssize_t DoSendMsg(SOCKET sock, const struct iovec* iov, int iovcnt) { diff --git a/util/random/benchmark/prng/ya.make b/util/random/benchmark/prng/ya.make index 976977014f..5088daa2f3 100644 --- a/util/random/benchmark/prng/ya.make +++ b/util/random/benchmark/prng/ya.make @@ -4,7 +4,7 @@ OWNER( ) SUBSCRIBER(g:util-subscribers) -Y_BENCHMARK() +Y_BENCHMARK() SRCS( main.cpp diff --git a/util/string/benchmark/ascii/ya.make b/util/string/benchmark/ascii/ya.make index f95b9e0fa8..f57b10e7f8 100644 --- a/util/string/benchmark/ascii/ya.make +++ b/util/string/benchmark/ascii/ya.make @@ -1,4 +1,4 @@ -Y_BENCHMARK() +Y_BENCHMARK() OWNER(pg) diff --git a/util/string/benchmark/cast/ya.make b/util/string/benchmark/cast/ya.make index f95b9e0fa8..f57b10e7f8 100644 --- a/util/string/benchmark/cast/ya.make +++ b/util/string/benchmark/cast/ya.make @@ -1,4 +1,4 @@ -Y_BENCHMARK() +Y_BENCHMARK() OWNER(pg) diff --git a/util/string/benchmark/float_to_string/ya.make b/util/string/benchmark/float_to_string/ya.make index 8136ad34f0..397a4bf354 100644 --- a/util/string/benchmark/float_to_string/ya.make +++ b/util/string/benchmark/float_to_string/ya.make @@ -1,6 +1,6 @@ OWNER(yazevnul) -Y_BENCHMARK() +Y_BENCHMARK() # to minimize allocations overhead ALLOCATOR(B) diff --git a/util/string/benchmark/join/ya.make b/util/string/benchmark/join/ya.make index dfcc1d264e..5742af7831 100644 --- a/util/string/benchmark/join/ya.make +++ b/util/string/benchmark/join/ya.make @@ -1,4 +1,4 @@ -Y_BENCHMARK() +Y_BENCHMARK() OWNER( salmin diff --git a/util/string/benchmark/subst_global/ya.make b/util/string/benchmark/subst_global/ya.make index 8136ad34f0..397a4bf354 100644 --- a/util/string/benchmark/subst_global/ya.make +++ b/util/string/benchmark/subst_global/ya.make @@ -1,6 +1,6 @@ OWNER(yazevnul) -Y_BENCHMARK() +Y_BENCHMARK() # to minimize allocations overhead ALLOCATOR(B) diff --git a/util/system/benchmark/cpu_id/ya.make b/util/system/benchmark/cpu_id/ya.make index 976977014f..5088daa2f3 100644 --- a/util/system/benchmark/cpu_id/ya.make +++ b/util/system/benchmark/cpu_id/ya.make @@ -4,7 +4,7 @@ OWNER( ) SUBSCRIBER(g:util-subscribers) -Y_BENCHMARK() +Y_BENCHMARK() SRCS( main.cpp diff --git a/util/system/benchmark/create_destroy_thread/ya.make b/util/system/benchmark/create_destroy_thread/ya.make index 03eb0ec8e0..613643b456 100644 --- a/util/system/benchmark/create_destroy_thread/ya.make +++ b/util/system/benchmark/create_destroy_thread/ya.make @@ -1,6 +1,6 @@ OWNER(yazevnul) -Y_BENCHMARK() +Y_BENCHMARK() SRCS( main.cpp diff --git a/util/system/benchmark/rdtsc/ya.make b/util/system/benchmark/rdtsc/ya.make index 7059abc3a4..ea15a55136 100644 --- a/util/system/benchmark/rdtsc/ya.make +++ b/util/system/benchmark/rdtsc/ya.make @@ -1,4 +1,4 @@ -Y_BENCHMARK() +Y_BENCHMARK() OWNER(g:util) SUBSCRIBER(g:util-subscribers) diff --git a/util/thread/lfqueue.h b/util/thread/lfqueue.h index ab523631e4..fc606963d3 100644 --- a/util/thread/lfqueue.h +++ b/util/thread/lfqueue.h @@ -18,11 +18,11 @@ struct TDefaultLFCounter { } }; -// @brief lockfree queue -// @tparam T - the queue element, should be movable -// @tparam TCounter, a observer class to count number of items in queue -// be carifull, IncCount and DecCount can be called on a moved object and -// it is TCounter class responsibility to check validity of passed object +// @brief lockfree queue +// @tparam T - the queue element, should be movable +// @tparam TCounter, a observer class to count number of items in queue +// be carifull, IncCount and DecCount can be called on a moved object and +// it is TCounter class responsibility to check validity of passed object template <class T, class TCounter> class TLockFreeQueue: public TNonCopyable { struct TListNode { diff --git a/util/thread/lfstack.h b/util/thread/lfstack.h index ca3d95f3c3..168e2b1d24 100644 --- a/util/thread/lfstack.h +++ b/util/thread/lfstack.h @@ -12,10 +12,10 @@ class TLockFreeStack: TNonCopyable { TNode* Next; TNode() = default; - + template <class U> - explicit TNode(U&& val) - : Value(std::forward<U>(val)) + explicit TNode(U&& val) + : Value(std::forward<U>(val)) , Next(nullptr) { } @@ -49,11 +49,11 @@ class TLockFreeStack: TNonCopyable { break; } } - template <class U> - void EnqueueImpl(U&& u) { + template <class U> + void EnqueueImpl(U&& u) { TNode* volatile node = new TNode(std::forward<U>(u)); - EnqueueImpl(node, node); - } + EnqueueImpl(node, node); + } public: TLockFreeStack() @@ -66,15 +66,15 @@ public: EraseList(Head); EraseList(FreePtr); } - + void Enqueue(const T& t) { - EnqueueImpl(t); + EnqueueImpl(t); } - - void Enqueue(T&& t) { - EnqueueImpl(std::move(t)); - } - + + void Enqueue(T&& t) { + EnqueueImpl(std::move(t)); + } + template <typename TCollection> void EnqueueAll(const TCollection& data) { EnqueueAll(data.begin(), data.end()); @@ -99,7 +99,7 @@ public: AtomicAdd(DequeueCount, 1); for (TNode* current = AtomicGet(Head); current; current = AtomicGet(Head)) { if (AtomicCas(&Head, AtomicGet(current->Next), current)) { - *res = std::move(current->Value); + *res = std::move(current->Value); // delete current; // ABA problem // even more complex node deletion TryToFreeMemory(); @@ -129,7 +129,7 @@ public: for (TNode* current = AtomicGet(Head); current; current = AtomicGet(Head)) { if (AtomicCas(&Head, (TNode*)nullptr, current)) { for (TNode* x = current; x;) { - res->push_back(std::move(x->Value)); + res->push_back(std::move(x->Value)); x = x->Next; } // EraseList(current); // ABA problem @@ -159,7 +159,7 @@ public: bool DequeueSingleConsumer(T* res) { for (TNode* current = AtomicGet(Head); current; current = AtomicGet(Head)) { if (AtomicCas(&Head, current->Next, current)) { - *res = std::move(current->Value); + *res = std::move(current->Value); delete current; // with single consumer thread ABA does not happen return true; } @@ -173,7 +173,7 @@ public: for (TNode* current = AtomicGet(Head); current; current = AtomicGet(Head)) { if (AtomicCas(&Head, (TNode*)nullptr, current)) { for (TNode* x = current; x;) { - res->push_back(std::move(x->Value)); + res->push_back(std::move(x->Value)); x = x->Next; } EraseList(current); // with single consumer thread ABA does not happen diff --git a/util/thread/lfstack_ut.cpp b/util/thread/lfstack_ut.cpp index e20a838f95..00ae2864d7 100644 --- a/util/thread/lfstack_ut.cpp +++ b/util/thread/lfstack_ut.cpp @@ -190,55 +190,55 @@ Y_UNIT_TEST_SUITE(TLockFreeStackTests) { UNIT_ASSERT_VALUES_EQUAL(1, p.RefCount()); } - Y_UNIT_TEST(NoCopyTest) { - static unsigned copied = 0; - struct TCopyCount { + Y_UNIT_TEST(NoCopyTest) { + static unsigned copied = 0; + struct TCopyCount { TCopyCount(int) { } TCopyCount(const TCopyCount&) { ++copied; } - + TCopyCount(TCopyCount&&) { } - - TCopyCount& operator=(const TCopyCount&) { - ++copied; - return *this; - } - - TCopyCount& operator=(TCopyCount&&) { - return *this; - } - }; - - TLockFreeStack<TCopyCount> stack; - stack.Enqueue(TCopyCount(1)); - TCopyCount val(0); - stack.Dequeue(&val); - UNIT_ASSERT_VALUES_EQUAL(0, copied); - } - - Y_UNIT_TEST(MoveOnlyTest) { - TLockFreeStack<THolder<bool>> stack; - stack.Enqueue(MakeHolder<bool>(true)); - THolder<bool> val; - stack.Dequeue(&val); - UNIT_ASSERT(val); - UNIT_ASSERT_VALUES_EQUAL(true, *val); - } - - template <class TTest> - struct TMultiThreadTester { - using ThisType = TMultiThreadTester<TTest>; - + + TCopyCount& operator=(const TCopyCount&) { + ++copied; + return *this; + } + + TCopyCount& operator=(TCopyCount&&) { + return *this; + } + }; + + TLockFreeStack<TCopyCount> stack; + stack.Enqueue(TCopyCount(1)); + TCopyCount val(0); + stack.Dequeue(&val); + UNIT_ASSERT_VALUES_EQUAL(0, copied); + } + + Y_UNIT_TEST(MoveOnlyTest) { + TLockFreeStack<THolder<bool>> stack; + stack.Enqueue(MakeHolder<bool>(true)); + THolder<bool> val; + stack.Dequeue(&val); + UNIT_ASSERT(val); + UNIT_ASSERT_VALUES_EQUAL(true, *val); + } + + template <class TTest> + struct TMultiThreadTester { + using ThisType = TMultiThreadTester<TTest>; + size_t Threads; size_t OperationsPerThread; TCountDownLatch StartLatch; - TLockFreeStack<typename TTest::ValueType> Stack; + TLockFreeStack<typename TTest::ValueType> Stack; - TMultiThreadTester() + TMultiThreadTester() : Threads(10) , OperationsPerThread(100000) , StartLatch(Threads) @@ -249,23 +249,23 @@ Y_UNIT_TEST_SUITE(TLockFreeStackTests) { StartLatch.CountDown(); StartLatch.Await(); - TVector<typename TTest::ValueType> unused; + TVector<typename TTest::ValueType> unused; for (size_t i = 0; i < OperationsPerThread; ++i) { switch (GetCycleCount() % 4) { case 0: { - TTest::Enqueue(Stack, i); + TTest::Enqueue(Stack, i); break; } case 1: { - TTest::Dequeue(Stack); + TTest::Dequeue(Stack); break; } case 2: { - TTest::EnqueueAll(Stack); + TTest::EnqueueAll(Stack); break; } case 3: { - TTest::DequeueAll(Stack); + TTest::DequeueAll(Stack); break; } } @@ -276,71 +276,71 @@ Y_UNIT_TEST_SUITE(TLockFreeStackTests) { TDeque<NThreading::TLegacyFuture<>> futures; for (size_t i = 0; i < Threads; ++i) { - futures.emplace_back(std::bind(&ThisType::Worker, this)); + futures.emplace_back(std::bind(&ThisType::Worker, this)); } futures.clear(); - TTest::DequeueAll(Stack); - } - }; - - struct TFreeListTest { - using ValueType = int; - - static void Enqueue(TLockFreeStack<int>& stack, size_t i) { - stack.Enqueue(static_cast<int>(i)); - } - - static void Dequeue(TLockFreeStack<int>& stack) { - int value; - stack.Dequeue(&value); - } - - static void EnqueueAll(TLockFreeStack<int>& stack) { - TVector<int> values(5); - stack.EnqueueAll(values); - } - - static void DequeueAll(TLockFreeStack<int>& stack) { - TVector<int> value; - stack.DequeueAll(&value); + TTest::DequeueAll(Stack); + } + }; + + struct TFreeListTest { + using ValueType = int; + + static void Enqueue(TLockFreeStack<int>& stack, size_t i) { + stack.Enqueue(static_cast<int>(i)); } + + static void Dequeue(TLockFreeStack<int>& stack) { + int value; + stack.Dequeue(&value); + } + + static void EnqueueAll(TLockFreeStack<int>& stack) { + TVector<int> values(5); + stack.EnqueueAll(values); + } + + static void DequeueAll(TLockFreeStack<int>& stack) { + TVector<int> value; + stack.DequeueAll(&value); + } }; // Test for catching thread sanitizer problems Y_UNIT_TEST(TestFreeList) { - TMultiThreadTester<TFreeListTest>().Run(); - } - - struct TMoveTest { - using ValueType = THolder<int>; - - static void Enqueue(TLockFreeStack<ValueType>& stack, size_t i) { - stack.Enqueue(MakeHolder<int>(static_cast<int>(i))); - } - - static void Dequeue(TLockFreeStack<ValueType>& stack) { - ValueType value; - if (stack.Dequeue(&value)) { - UNIT_ASSERT(value); - } - } - - static void EnqueueAll(TLockFreeStack<ValueType>& stack) { - // there is no enqueAll with moving signature in LockFreeStack - Enqueue(stack, 0); - } - - static void DequeueAll(TLockFreeStack<ValueType>& stack) { - TVector<ValueType> values; - stack.DequeueAll(&values); - for (auto& v : values) { - UNIT_ASSERT(v); - } - } - }; - - // Test for catching thread sanitizer problems - Y_UNIT_TEST(TesMultiThreadMove) { - TMultiThreadTester<TMoveTest>().Run(); + TMultiThreadTester<TFreeListTest>().Run(); } + + struct TMoveTest { + using ValueType = THolder<int>; + + static void Enqueue(TLockFreeStack<ValueType>& stack, size_t i) { + stack.Enqueue(MakeHolder<int>(static_cast<int>(i))); + } + + static void Dequeue(TLockFreeStack<ValueType>& stack) { + ValueType value; + if (stack.Dequeue(&value)) { + UNIT_ASSERT(value); + } + } + + static void EnqueueAll(TLockFreeStack<ValueType>& stack) { + // there is no enqueAll with moving signature in LockFreeStack + Enqueue(stack, 0); + } + + static void DequeueAll(TLockFreeStack<ValueType>& stack) { + TVector<ValueType> values; + stack.DequeueAll(&values); + for (auto& v : values) { + UNIT_ASSERT(v); + } + } + }; + + // Test for catching thread sanitizer problems + Y_UNIT_TEST(TesMultiThreadMove) { + TMultiThreadTester<TMoveTest>().Run(); + } } diff --git a/util/ya.make b/util/ya.make index 6ebe7e40cf..91cd1a2e26 100644 --- a/util/ya.make +++ b/util/ya.make @@ -15,10 +15,10 @@ PEERDIR( contrib/libs/double-conversion ) -PEERDIR( - contrib/libs/libc_compat -) - +PEERDIR( + contrib/libs/libc_compat +) + # datetime JOIN_SRCS( all_datetime.cpp |