aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic
diff options
context:
space:
mode:
authorskalsin <skalsin@yandex-team.ru>2022-02-10 16:46:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:39 +0300
commit5036b5f2122001f9aef8a0e4cd85440d73ea6b9f (patch)
tree49e222ea1c5804306084bb3ae065bb702625360f /util/generic
parent0ec5f3106fcb5e342ec13cdfad678bf4633580d5 (diff)
downloadydb-5036b5f2122001f9aef8a0e4cd85440d73ea6b9f.tar.gz
Restoring authorship annotation for <skalsin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r--util/generic/hash.h108
-rw-r--r--util/generic/hash_ut.cpp40
2 files changed, 74 insertions, 74 deletions
diff --git a/util/generic/hash.h b/util/generic/hash.h
index 8852e69488..e46db21fa9 100644
--- a/util/generic/hash.h
+++ b/util/generic/hash.h
@@ -676,24 +676,24 @@ public:
template <class OtherValue>
iterator insert_equal(const OtherValue& obj) {
reserve(num_elements + 1);
- return emplace_equal_noresize(obj);
+ return emplace_equal_noresize(obj);
}
- template <typename... Args>
+ template <typename... Args>
iterator emplace_equal(Args&&... args) {
reserve(num_elements + 1);
- return emplace_equal_noresize(std::forward<Args>(args)...);
- }
-
+ return emplace_equal_noresize(std::forward<Args>(args)...);
+ }
+
template <class OtherValue>
iterator insert_direct(const OtherValue& obj, insert_ctx ins) {
- return emplace_direct(ins, obj);
- }
-
- template <typename... Args>
+ return emplace_direct(ins, obj);
+ }
+
+ template <typename... Args>
iterator emplace_direct(insert_ctx ins, Args&&... args) {
bool resized = reserve(num_elements + 1);
- node* tmp = new_node(std::forward<Args>(args)...);
+ node* tmp = new_node(std::forward<Args>(args)...);
if (resized) {
find_i(get_key(tmp->val), ins);
}
@@ -703,19 +703,19 @@ public:
return iterator(tmp);
}
- template <typename... Args>
+ template <typename... Args>
std::pair<iterator, bool> emplace_unique(Args&&... args) {
reserve(num_elements + 1);
- return emplace_unique_noresize(std::forward<Args>(args)...);
- }
-
- template <typename... Args>
+ return emplace_unique_noresize(std::forward<Args>(args)...);
+ }
+
+ template <typename... Args>
std::pair<iterator, bool> emplace_unique_noresize(Args&&... args);
-
+
template <class OtherValue>
std::pair<iterator, bool> insert_unique_noresize(const OtherValue& obj);
- template <typename... Args>
+ template <typename... Args>
iterator emplace_equal_noresize(Args&&... args);
template <class InputIterator>
@@ -755,7 +755,7 @@ public:
reserve(num_elements + n);
for (; n > 0; --n, ++f)
- emplace_equal_noresize(*f);
+ emplace_equal_noresize(*f);
}
template <class OtherValue>
@@ -929,12 +929,12 @@ private:
return bkt_num_key(get_key(obj), n);
}
- template <typename... Args>
+ template <typename... Args>
node* new_node(Args&&... val) {
node* n = get_node();
n->next = (node*)1; /*y*/ // just for a case
try {
- new (static_cast<void*>(&n->val)) Value(std::forward<Args>(val)...);
+ new (static_cast<void*>(&n->val)) Value(std::forward<Args>(val)...);
} catch (...) {
put_node(n);
throw;
@@ -997,28 +997,28 @@ inline __yhashtable_const_iterator<V> __yhashtable_const_iterator<V>::operator++
}
template <class V, class K, class HF, class Ex, class Eq, class A>
-template <typename... Args>
+template <typename... Args>
std::pair<typename THashTable<V, K, HF, Ex, Eq, A>::iterator, bool> THashTable<V, K, HF, Ex, Eq, A>::emplace_unique_noresize(Args&&... args) {
auto deleter = [&](node* tmp) { delete_node(tmp); };
- node* tmp = new_node(std::forward<Args>(args)...);
- std::unique_ptr<node, decltype(deleter)> guard(tmp, deleter);
-
- const size_type n = bkt_num(tmp->val);
- node* first = buckets[n];
-
- if (first) /*y*/
- for (node* cur = first; !((uintptr_t)cur & 1); cur = cur->next) /*y*/
- if (equals(get_key(cur->val), get_key(tmp->val)))
- return std::pair<iterator, bool>(iterator(cur), false); /*y*/
-
- guard.release();
- tmp->next = first ? first : (node*)((uintptr_t)&buckets[n + 1] | 1); /*y*/
- buckets[n] = tmp;
- ++num_elements;
- return std::pair<iterator, bool>(iterator(tmp), true); /*y*/
-}
-
-template <class V, class K, class HF, class Ex, class Eq, class A>
+ node* tmp = new_node(std::forward<Args>(args)...);
+ std::unique_ptr<node, decltype(deleter)> guard(tmp, deleter);
+
+ const size_type n = bkt_num(tmp->val);
+ node* first = buckets[n];
+
+ if (first) /*y*/
+ for (node* cur = first; !((uintptr_t)cur & 1); cur = cur->next) /*y*/
+ if (equals(get_key(cur->val), get_key(tmp->val)))
+ return std::pair<iterator, bool>(iterator(cur), false); /*y*/
+
+ guard.release();
+ tmp->next = first ? first : (node*)((uintptr_t)&buckets[n + 1] | 1); /*y*/
+ buckets[n] = tmp;
+ ++num_elements;
+ return std::pair<iterator, bool>(iterator(tmp), true); /*y*/
+}
+
+template <class V, class K, class HF, class Ex, class Eq, class A>
template <class OtherValue>
std::pair<typename THashTable<V, K, HF, Ex, Eq, A>::iterator, bool> THashTable<V, K, HF, Ex, Eq, A>::insert_unique_noresize(const OtherValue& obj) {
const size_type n = bkt_num(obj);
@@ -1037,25 +1037,25 @@ std::pair<typename THashTable<V, K, HF, Ex, Eq, A>::iterator, bool> THashTable<V
}
template <class V, class K, class HF, class Ex, class Eq, class A>
-template <typename... Args>
+template <typename... Args>
__yhashtable_iterator<V> THashTable<V, K, HF, Ex, Eq, A>::emplace_equal_noresize(Args&&... args) {
auto deleter = [&](node* tmp) { delete_node(tmp); };
- node* tmp = new_node(std::forward<Args>(args)...);
- std::unique_ptr<node, decltype(deleter)> guard(tmp, deleter);
- const size_type n = bkt_num(tmp->val);
+ node* tmp = new_node(std::forward<Args>(args)...);
+ std::unique_ptr<node, decltype(deleter)> guard(tmp, deleter);
+ const size_type n = bkt_num(tmp->val);
node* first = buckets[n];
if (first) /*y*/
for (node* cur = first; !((uintptr_t)cur & 1); cur = cur->next) /*y*/
- if (equals(get_key(cur->val), get_key(tmp->val))) {
- guard.release();
+ if (equals(get_key(cur->val), get_key(tmp->val))) {
+ guard.release();
tmp->next = cur->next;
cur->next = tmp;
++num_elements;
return iterator(tmp); /*y*/
}
- guard.release();
+ guard.release();
tmp->next = first ? first : (node*)((uintptr_t)&buckets[n + 1] | 1); /*y*/
buckets[n] = tmp;
++num_elements;
@@ -1570,10 +1570,10 @@ public:
return rep.insert_unique(obj);
}
- template <typename... Args>
+ template <typename... Args>
std::pair<iterator, bool> emplace(Args&&... args) {
- return rep.emplace_unique(std::forward<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);
@@ -1644,7 +1644,7 @@ public:
return it->second;
}
- return rep.emplace_direct(ctx, std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple())->second;
+ return rep.emplace_direct(ctx, std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple())->second;
}
template <class TheKey>
@@ -1897,11 +1897,11 @@ public:
template <typename... Args>
iterator emplace(Args&&... args) {
- return rep.emplace_equal(std::forward<Args>(args)...);
- }
+ return rep.emplace_equal(std::forward<Args>(args)...);
+ }
iterator insert_noresize(const value_type& obj) {
- return rep.emplace_equal_noresize(obj);
+ return rep.emplace_equal_noresize(obj);
}
template <typename... Args>
diff --git a/util/generic/hash_ut.cpp b/util/generic/hash_ut.cpp
index 7028da5963..0551d58770 100644
--- a/util/generic/hash_ut.cpp
+++ b/util/generic/hash_ut.cpp
@@ -37,7 +37,7 @@ class THashTest: public TTestBase {
UNIT_TEST(TestInvariants);
UNIT_TEST(TestAllocation);
UNIT_TEST(TestInsertCopy);
- UNIT_TEST(TestEmplace);
+ UNIT_TEST(TestEmplace);
UNIT_TEST(TestEmplaceNoresize);
UNIT_TEST(TestEmplaceDirect);
UNIT_TEST(TestTryEmplace);
@@ -48,7 +48,7 @@ class THashTest: public TTestBase {
UNIT_TEST(TestHSetEmplace);
UNIT_TEST(TestHSetEmplaceNoresize);
UNIT_TEST(TestHSetEmplaceDirect);
- UNIT_TEST(TestNonCopyable);
+ UNIT_TEST(TestNonCopyable);
UNIT_TEST(TestValueInitialization);
UNIT_TEST(TestAssignmentClear);
UNIT_TEST(TestReleaseNodes);
@@ -88,7 +88,7 @@ protected:
void TestInvariants();
void TestAllocation();
void TestInsertCopy();
- void TestEmplace();
+ void TestEmplace();
void TestEmplaceNoresize();
void TestEmplaceDirect();
void TestTryEmplace();
@@ -99,7 +99,7 @@ protected:
void TestHMMapEmplace();
void TestHMMapEmplaceNoresize();
void TestHMMapEmplaceDirect();
- void TestNonCopyable();
+ void TestNonCopyable();
void TestValueInitialization();
void TestAssignmentClear();
void TestReleaseNodes();
@@ -887,14 +887,14 @@ void THashTest::TestInsertCopy() {
hash[TNonCopyableInt<0>(0)] = 0;
}
-void THashTest::TestEmplace() {
+void THashTest::TestEmplace() {
using hash_t = THashMap<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);
-}
-
+ 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() {
using hash_t = THashMap<int, TNonCopyableInt<0>>;
hash_t hash;
@@ -1037,9 +1037,9 @@ void THashTest::TestHSetEmplaceDirect() {
UNIT_ASSERT(!hash.contains(1));
}
-void THashTest::TestNonCopyable() {
- struct TValue: public TNonCopyable {
- int value;
+void THashTest::TestNonCopyable() {
+ struct TValue: public TNonCopyable {
+ int value;
TValue(int _value = 0)
: value(_value)
{
@@ -1047,16 +1047,16 @@ void THashTest::TestNonCopyable() {
operator int() {
return value;
}
- };
-
+ };
+
THashMap<int, TValue> hash;
- hash.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(5));
+ hash.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(5));
auto&& value = hash[1];
- UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(value), 5);
+ UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(value), 5);
auto&& not_inserted = hash[2];
- UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(not_inserted), 0);
-}
-
+ UNIT_ASSERT_VALUES_EQUAL(static_cast<int>(not_inserted), 0);
+}
+
void THashTest::TestValueInitialization() {
THashMap<int, int> hash;