diff options
author | vskipin <vskipin@yandex-team.ru> | 2022-02-10 16:46:00 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:00 +0300 |
commit | 4d8b546b89b5afc08cf3667e176271c7ba935f33 (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/generic | |
parent | 4e4b78bd7b67e2533da4dbb9696374a6d6068e32 (diff) | |
download | ydb-4d8b546b89b5afc08cf3667e176271c7ba935f33.tar.gz |
Restoring authorship annotation for <vskipin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r-- | util/generic/deque.h | 2 | ||||
-rw-r--r-- | util/generic/flags.h | 4 | ||||
-rw-r--r-- | util/generic/flags_ut.cpp | 12 | ||||
-rw-r--r-- | util/generic/hash.h | 96 | ||||
-rw-r--r-- | util/generic/hash_set.h | 36 | ||||
-rw-r--r-- | util/generic/hash_ut.cpp | 216 | ||||
-rw-r--r-- | util/generic/object_counter.h | 2 | ||||
-rw-r--r-- | util/generic/singleton.h | 2 |
8 files changed, 185 insertions, 185 deletions
diff --git a/util/generic/deque.h b/util/generic/deque.h index b96f0ea2ba..2dabaf3177 100644 --- a/util/generic/deque.h +++ b/util/generic/deque.h @@ -12,7 +12,7 @@ template <class T, class A> class TDeque: public std::deque<T, TReboundAllocator<A, T>> { using TBase = std::deque<T, TReboundAllocator<A, T>>; -public: +public: using TBase::TBase; inline yssize_t ysize() const noexcept { diff --git a/util/generic/flags.h b/util/generic/flags.h index b47f7d02c0..a1f5921d42 100644 --- a/util/generic/flags.h +++ b/util/generic/flags.h @@ -234,11 +234,11 @@ struct THash<TFlags<Enum>> { * @param FLAGS Flags type to declare operator for. */ #define Y_DECLARE_OPERATORS_FOR_FLAGS(FLAGS) \ - Y_DECLARE_UNUSED \ + Y_DECLARE_UNUSED \ constexpr inline FLAGS operator|(FLAGS::TEnum l, FLAGS::TEnum r) { \ return FLAGS(l) | r; \ } \ - Y_DECLARE_UNUSED \ + Y_DECLARE_UNUSED \ constexpr inline FLAGS operator~(FLAGS::TEnum value) { \ return ~FLAGS(value); \ } diff --git a/util/generic/flags_ut.cpp b/util/generic/flags_ut.cpp index 23ab5a99f8..5377c6a058 100644 --- a/util/generic/flags_ut.cpp +++ b/util/generic/flags_ut.cpp @@ -22,15 +22,15 @@ enum class ETestFlag2 { Y_DECLARE_FLAGS(ETest2, ETestFlag2) Y_DECLARE_OPERATORS_FOR_FLAGS(ETest2) -namespace { - // won't compile without Y_DECLARE_UNUSED +namespace { + // won't compile without Y_DECLARE_UNUSED enum class ETestFlag3 { One = 1, Two = 2, Three = 3 }; - Y_DECLARE_FLAGS(ETestFlags3, ETestFlag3) - Y_DECLARE_OPERATORS_FOR_FLAGS(ETestFlags3) -} - + Y_DECLARE_FLAGS(ETestFlags3, ETestFlag3) + Y_DECLARE_OPERATORS_FOR_FLAGS(ETestFlags3) +} + Y_UNIT_TEST_SUITE(TFlagsTest) { template <class Enum> void TestEnum() { diff --git a/util/generic/hash.h b/util/generic/hash.h index 0fea17b3a5..e46db21fa9 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -1561,39 +1561,39 @@ public: } public: - template <class InputIterator> - void insert(InputIterator f, InputIterator l) { - rep.insert_unique(f, l); - } - + template <class InputIterator> + void insert(InputIterator f, InputIterator l) { + rep.insert_unique(f, l); + } + std::pair<iterator, bool> insert(const value_type& obj) { return rep.insert_unique(obj); } - + template <typename... Args> std::pair<iterator, bool> emplace(Args&&... args) { return rep.emplace_unique(std::forward<Args>(args)...); } - - std::pair<iterator, bool> insert_noresize(const value_type& obj) { - return rep.insert_unique_noresize(obj); - } - + + std::pair<iterator, bool> insert_noresize(const value_type& obj) { + 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 <class TheObj> iterator insert_direct(const TheObj& obj, const insert_ctx& ins) { return rep.insert_direct(obj, ins); } - template <typename... Args> - iterator emplace_direct(const insert_ctx& ins, Args&&... args) { - return rep.emplace_direct(ins, std::forward<Args>(args)...); - } - + template <typename... Args> + iterator emplace_direct(const insert_ctx& ins, Args&&... args) { + 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; @@ -1776,7 +1776,7 @@ public: using iterator = typename ht::iterator; using const_iterator = typename ht::const_iterator; - using insert_ctx = typename ht::insert_ctx; + using insert_ctx = typename ht::insert_ctx; hasher hash_function() const { return rep.hash_function(); @@ -1886,55 +1886,55 @@ public: } public: - template <class InputIterator> - void insert(InputIterator f, InputIterator l) { - rep.insert_equal(f, l); - } - + template <class InputIterator> + void insert(InputIterator f, InputIterator l) { + rep.insert_equal(f, l); + } + iterator insert(const value_type& obj) { return rep.insert_equal(obj); } - - template <typename... Args> + + template <typename... Args> iterator emplace(Args&&... args) { return rep.emplace_equal(std::forward<Args>(args)...); } - + iterator insert_noresize(const value_type& obj) { return rep.emplace_equal_noresize(obj); } - template <typename... Args> - iterator emplace_noresize(Args&&... args) { - return rep.emplace_equal_noresize(std::forward<Args>(args)...); - } - - template <class TheObj> - iterator insert_direct(const TheObj& obj, const insert_ctx& ins) { - return rep.insert_direct(obj, ins); - } - - template <typename... Args> - iterator emplace_direct(const insert_ctx& ins, Args&&... args) { - return rep.emplace_direct(ins, std::forward<Args>(args)...); - } - + template <typename... Args> + iterator emplace_noresize(Args&&... args) { + return rep.emplace_equal_noresize(std::forward<Args>(args)...); + } + + template <class TheObj> + iterator insert_direct(const TheObj& obj, const insert_ctx& ins) { + return rep.insert_direct(obj, ins); + } + + template <typename... Args> + iterator emplace_direct(const insert_ctx& ins, Args&&... args) { + return rep.emplace_direct(ins, std::forward<Args>(args)...); + } + template <class TKey> - const_iterator find(const TKey& key) const { + const_iterator find(const TKey& key) const { return rep.find(key); } template <class TKey> - iterator find(const TKey& key) { + iterator find(const TKey& key) { return rep.find(key); } template <class TheKey> - iterator find(const TheKey& key, insert_ctx& ins) { - return rep.find_i(key, ins); - } - - template <class TheKey> + iterator find(const TheKey& key, insert_ctx& ins) { + return rep.find_i(key, ins); + } + + template <class TheKey> bool contains(const TheKey& key) const { return rep.find(key) != rep.end(); } diff --git a/util/generic/hash_set.h b/util/generic/hash_set.h index ac1ff92bbb..e8088cf23b 100644 --- a/util/generic/hash_set.h +++ b/util/generic/hash_set.h @@ -147,15 +147,15 @@ public: } public: - void insert(std::initializer_list<value_type> ilist) { - insert(ilist.begin(), ilist.end()); - } - - template <class InputIterator> - void insert(InputIterator f, InputIterator l) { - rep.insert_unique(f, l); - } - + void insert(std::initializer_list<value_type> ilist) { + insert(ilist.begin(), ilist.end()); + } + + template <class InputIterator> + void insert(InputIterator f, InputIterator l) { + rep.insert_unique(f, l); + } + std::pair<iterator, bool> insert(const value_type& obj) { std::pair<mutable_iterator, bool> p = rep.insert_unique(obj); return std::pair<iterator, bool>(p.first, p.second); @@ -165,8 +165,8 @@ public: std::pair<mutable_iterator, bool> p = rep.emplace_unique(std::forward<Args>(args)...); return std::pair<iterator, bool>(p.first, p.second); } - - iterator insert(const_iterator, const value_type& obj) { // insert_hint + + iterator insert(const_iterator, const value_type& obj) { // insert_hint std::pair<mutable_iterator, bool> p = rep.insert_unique(obj); return p.first; } @@ -180,25 +180,25 @@ public: std::pair<mutable_iterator, bool> p = rep.emplace_unique_noresize(std::forward<Args>(args)...); return std::pair<iterator, bool>(p.first, p.second); } - + template <class TheObj> iterator insert_direct(const TheObj& obj, const insert_ctx& ins) { return rep.insert_direct(obj, ins); } - template <typename... Args> - iterator emplace_direct(const insert_ctx& ins, Args&&... args) { - return rep.emplace_direct(ins, std::forward<Args>(args)...); - } + template <typename... Args> + iterator emplace_direct(const insert_ctx& ins, Args&&... args) { + return rep.emplace_direct(ins, std::forward<Args>(args)...); + } template <class TheKey> - const_iterator find(const TheKey& key) const { + const_iterator find(const TheKey& key) const { return rep.find(key); } template <class TheKey> iterator find(const TheKey& key, insert_ctx& ins) { return rep.find_i(key, ins); } - + template <class TheKey> bool contains(const TheKey& key) const { return rep.find(key) != rep.end(); diff --git a/util/generic/hash_ut.cpp b/util/generic/hash_ut.cpp index 53396409f3..0551d58770 100644 --- a/util/generic/hash_ut.cpp +++ b/util/generic/hash_ut.cpp @@ -38,16 +38,16 @@ class THashTest: public TTestBase { UNIT_TEST(TestAllocation); UNIT_TEST(TestInsertCopy); UNIT_TEST(TestEmplace); - UNIT_TEST(TestEmplaceNoresize); - UNIT_TEST(TestEmplaceDirect); + UNIT_TEST(TestEmplaceNoresize); + UNIT_TEST(TestEmplaceDirect); UNIT_TEST(TestTryEmplace); UNIT_TEST(TestTryEmplaceCopyKey); - UNIT_TEST(TestHMMapEmplace); - UNIT_TEST(TestHMMapEmplaceNoresize); - UNIT_TEST(TestHMMapEmplaceDirect); + UNIT_TEST(TestHMMapEmplace); + UNIT_TEST(TestHMMapEmplaceNoresize); + UNIT_TEST(TestHMMapEmplaceDirect); UNIT_TEST(TestHSetEmplace); - UNIT_TEST(TestHSetEmplaceNoresize); - UNIT_TEST(TestHSetEmplaceDirect); + UNIT_TEST(TestHSetEmplaceNoresize); + UNIT_TEST(TestHSetEmplaceDirect); UNIT_TEST(TestNonCopyable); UNIT_TEST(TestValueInitialization); UNIT_TEST(TestAssignmentClear); @@ -89,16 +89,16 @@ protected: void TestAllocation(); void TestInsertCopy(); void TestEmplace(); - void TestEmplaceNoresize(); - void TestEmplaceDirect(); + void TestEmplaceNoresize(); + void TestEmplaceDirect(); void TestTryEmplace(); void TestTryEmplaceCopyKey(); void TestHSetEmplace(); - void TestHSetEmplaceNoresize(); - void TestHSetEmplaceDirect(); - void TestHMMapEmplace(); - void TestHMMapEmplaceNoresize(); - void TestHMMapEmplaceDirect(); + void TestHSetEmplaceNoresize(); + void TestHSetEmplaceDirect(); + void TestHMMapEmplace(); + void TestHMMapEmplaceNoresize(); + void TestHMMapEmplaceDirect(); void TestNonCopyable(); void TestValueInitialization(); void TestAssignmentClear(); @@ -632,65 +632,65 @@ void THashTest::TestInsertErase() { UNIT_ASSERT(values.erase("foo") == 1); } } - -namespace { + +namespace { struct TItem: public TSimpleRefCount<TItem> { const TString Key; const TString Value; - + TItem(const TString& key, const TString& value) - : Key(key) - , Value(value) + : Key(key) + , Value(value) { } - }; - + }; + using TItemPtr = TIntrusivePtr<TItem>; - - struct TSelectKey { + + struct TSelectKey { const TString& operator()(const TItemPtr& item) const { - return item->Key; - } - }; - + return item->Key; + } + }; + using TItemMapBase = THashTable< - TItemPtr, + TItemPtr, TString, THash<TString>, - TSelectKey, + TSelectKey, TEqualTo<TString>, std::allocator<TItemPtr>>; - - struct TItemMap: public TItemMapBase { - TItemMap() + + struct TItemMap: public TItemMapBase { + TItemMap() : TItemMapBase(1, THash<TString>(), TEqualTo<TString>()) { } - + TItem& Add(const TString& key, const TString& value) { - insert_ctx ins; - iterator it = find_i(key, ins); - if (it == end()) { - it = insert_direct(new TItem(key, value), ins); - } - return **it; - } - }; + insert_ctx ins; + iterator it = find_i(key, ins); + if (it == end()) { + it = insert_direct(new TItem(key, value), ins); + } + return **it; + } + }; +} + +void THashTest::TestResizeOnInsertSmartPtrBug() { + TItemMap map; + map.Add("key1", "value1"); + map.Add("key2", "value2"); + map.Add("key3", "value3"); + map.Add("key4", "value4"); + map.Add("key5", "value5"); + map.Add("key6", "value6"); + map.Add("key7", "value7"); + TItem& item = map.Add("key8", "value8"); + UNIT_ASSERT_EQUAL(item.Key, "key8"); + UNIT_ASSERT_EQUAL(item.Value, "value8"); } - -void THashTest::TestResizeOnInsertSmartPtrBug() { - TItemMap map; - map.Add("key1", "value1"); - map.Add("key2", "value2"); - map.Add("key3", "value3"); - map.Add("key4", "value4"); - map.Add("key5", "value5"); - map.Add("key6", "value6"); - map.Add("key7", "value7"); - TItem& item = map.Add("key8", "value8"); - UNIT_ASSERT_EQUAL(item.Key, "key8"); - UNIT_ASSERT_EQUAL(item.Value, "value8"); -} template <typename T> static void EmptyAndInsertTest(typename T::value_type v) { @@ -889,31 +889,31 @@ void THashTest::TestInsertCopy() { void THashTest::TestEmplace() { using hash_t = THashMap<int, TNonCopyableInt<0>>; - hash_t hash; + hash_t hash; hash.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); auto it = hash.find(1); UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); } -void THashTest::TestEmplaceNoresize() { +void THashTest::TestEmplaceNoresize() { using hash_t = THashMap<int, TNonCopyableInt<0>>; - hash_t hash; - hash.reserve(1); - hash.emplace_noresize(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); - auto it = hash.find(1); - UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); -} - -void THashTest::TestEmplaceDirect() { + hash_t hash; + hash.reserve(1); + hash.emplace_noresize(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); + auto it = hash.find(1); + UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); +} + +void THashTest::TestEmplaceDirect() { using hash_t = THashMap<int, TNonCopyableInt<0>>; - hash_t hash; - hash_t::insert_ctx ins; - hash.find(1, ins); - hash.emplace_direct(ins, std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); - auto it = hash.find(1); - UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); -} - + hash_t hash; + hash_t::insert_ctx ins; + hash.find(1, ins); + hash.emplace_direct(ins, std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); + auto it = hash.find(1); + UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); +} + void THashTest::TestTryEmplace() { static unsigned counter = 0u; @@ -980,59 +980,59 @@ void THashTest::TestTryEmplaceCopyKey() { } } -void THashTest::TestHMMapEmplace() { +void THashTest::TestHMMapEmplace() { using hash_t = THashMultiMap<int, TNonCopyableInt<0>>; - hash_t hash; - hash.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); - auto it = hash.find(1); - UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); -} - -void THashTest::TestHMMapEmplaceNoresize() { + hash_t hash; + hash.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); + auto it = hash.find(1); + UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); +} + +void THashTest::TestHMMapEmplaceNoresize() { using hash_t = THashMultiMap<int, TNonCopyableInt<0>>; - hash_t hash; - hash.reserve(1); - hash.emplace_noresize(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); - auto it = hash.find(1); - UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); -} - -void THashTest::TestHMMapEmplaceDirect() { + hash_t hash; + hash.reserve(1); + hash.emplace_noresize(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); + auto it = hash.find(1); + UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); +} + +void THashTest::TestHMMapEmplaceDirect() { using hash_t = THashMultiMap<int, TNonCopyableInt<0>>; - hash_t hash; - hash_t::insert_ctx ins; - hash.find(1, ins); - hash.emplace_direct(ins, std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); - auto it = hash.find(1); - UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); -} - + hash_t hash; + hash_t::insert_ctx ins; + hash.find(1, ins); + hash.emplace_direct(ins, std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(0)); + auto it = hash.find(1); + UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(it->second), 0); +} + void THashTest::TestHSetEmplace() { using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; - hash_t hash; + hash_t hash; UNIT_ASSERT(!hash.contains(0)); hash.emplace(0); UNIT_ASSERT(hash.contains(0)); UNIT_ASSERT(!hash.contains(1)); -} - -void THashTest::TestHSetEmplaceNoresize() { +} + +void THashTest::TestHSetEmplaceNoresize() { using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; - hash_t hash; - hash.reserve(1); + hash_t hash; + hash.reserve(1); UNIT_ASSERT(!hash.contains(0)); hash.emplace_noresize(0); UNIT_ASSERT(hash.contains(0)); UNIT_ASSERT(!hash.contains(1)); } -void THashTest::TestHSetEmplaceDirect() { +void THashTest::TestHSetEmplaceDirect() { using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; - hash_t hash; + hash_t hash; UNIT_ASSERT(!hash.contains(0)); - hash_t::insert_ctx ins; - hash.find(0, ins); - hash.emplace_direct(ins, 1); + hash_t::insert_ctx ins; + hash.find(0, ins); + hash.emplace_direct(ins, 1); UNIT_ASSERT(hash.contains(0)); UNIT_ASSERT(!hash.contains(1)); } diff --git a/util/generic/object_counter.h b/util/generic/object_counter.h index fa0575225e..5257afa2e6 100644 --- a/util/generic/object_counter.h +++ b/util/generic/object_counter.h @@ -42,7 +42,7 @@ public: * \returns Current object count. */ static inline long ResetObjectCount() noexcept { - return AtomicSwap(&Count_, 0); + return AtomicSwap(&Count_, 0); } private: diff --git a/util/generic/singleton.h b/util/generic/singleton.h index cf4795ead4..f5fa047f5c 100644 --- a/util/generic/singleton.h +++ b/util/generic/singleton.h @@ -54,7 +54,7 @@ namespace NPrivate { UnlockRecursive(lock); - return ret; + return ret; } template <class T, size_t P, class... TArgs> |