Skip to content

Commit 91362aa

Browse files
wjakobTessil
authored andcommitted
Rename functions to *_with_hash
1 parent 17364b0 commit 91362aa

5 files changed

Lines changed: 59 additions & 59 deletions

File tree

include/tsl/robin_hash.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,10 @@ class robin_hash : private Hash, private KeyEqual, private GrowthPolicy {
692692
* otherwise the behaviour is undefined.
693693
*/
694694
template <typename P>
695-
std::pair<iterator, bool> insert_hash(std::size_t precalculated_hash,
696-
P&& value) {
697-
return insert_impl_hash(precalculated_hash, KeySelect()(value),
698-
std::forward<P>(value));
695+
std::pair<iterator, bool> insert_with_hash(std::size_t precalculated_hash,
696+
P&& value) {
697+
return insert_impl_with_hash(precalculated_hash, KeySelect()(value),
698+
std::forward<P>(value));
699699
}
700700

701701
template <typename P>
@@ -744,10 +744,10 @@ class robin_hash : private Hash, private KeyEqual, private GrowthPolicy {
744744
* behaviour is undefined.
745745
*/
746746
template <class K, class M>
747-
std::pair<iterator, bool> insert_or_assign_hash(
747+
std::pair<iterator, bool> insert_or_assign_with_hash(
748748
std::size_t precalculated_hash, K&& key, M&& obj) {
749-
auto it = try_emplace_hash(precalculated_hash, std::forward<K>(key),
750-
std::forward<M>(obj));
749+
auto it = try_emplace_with_hash(precalculated_hash, std::forward<K>(key),
750+
std::forward<M>(obj));
751751
if (!it.second) {
752752
it.first.value() = std::forward<M>(obj);
753753
}
@@ -790,11 +790,12 @@ class robin_hash : private Hash, private KeyEqual, private GrowthPolicy {
790790
* behaviour is undefined.
791791
*/
792792
template <class K, class... Args>
793-
std::pair<iterator, bool> try_emplace_hash(std::size_t precalculated_hash,
794-
K&& key, Args&&... args) {
795-
return insert_impl_hash(precalculated_hash, key, std::piecewise_construct,
796-
std::forward_as_tuple(std::forward<K>(key)),
797-
std::forward_as_tuple(std::forward<Args>(args)...));
793+
std::pair<iterator, bool> try_emplace_with_hash(
794+
std::size_t precalculated_hash, K&& key, Args&&... args) {
795+
return insert_impl_with_hash(
796+
precalculated_hash, key, std::piecewise_construct,
797+
std::forward_as_tuple(std::forward<K>(key)),
798+
std::forward_as_tuple(std::forward<Args>(args)...));
798799
}
799800

800801
template <class K, class... Args>
@@ -1203,13 +1204,13 @@ class robin_hash : private Hash, private KeyEqual, private GrowthPolicy {
12031204
template <class K, class... Args>
12041205
std::pair<iterator, bool> insert_impl(const K& key,
12051206
Args&&... value_type_args) {
1206-
return insert_impl_hash(hash_key(key), key,
1207-
std::forward<Args>(value_type_args)...);
1207+
return insert_impl_with_hash(hash_key(key), key,
1208+
std::forward<Args>(value_type_args)...);
12081209
}
12091210

12101211
template <class K, class... Args>
1211-
std::pair<iterator, bool> insert_impl_hash(std::size_t hash, const K& key,
1212-
Args&&... value_type_args) {
1212+
std::pair<iterator, bool> insert_impl_with_hash(
1213+
std::size_t hash, const K& key, Args&&... value_type_args) {
12131214
tsl_rh_assert(hash == hash_key(key));
12141215

12151216
std::size_t ibucket = bucket_for_hash(hash);

include/tsl/robin_map.h

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,17 @@ class robin_map {
249249
* hash value should be the same as hash_function()(value.first). Useful to
250250
* speed-up the insertion if you already have the hash.
251251
*/
252-
std::pair<iterator, bool> insert_hash(std::size_t precalculated_hash,
253-
const value_type& value) {
254-
return m_ht.insert_hash(precalculated_hash, value);
252+
std::pair<iterator, bool> insert_with_hash(std::size_t precalculated_hash,
253+
const value_type& value) {
254+
return m_ht.insert_with_hash(precalculated_hash, value);
255255
}
256256

257257
/**
258-
* @copydoc insert_hash(std::size_t precalculated_hash, const value_type& value)
258+
* @copydoc insert_with_hash(std::size_t precalculated_hash, const value_type& value)
259259
*/
260-
std::pair<iterator, bool> insert_hash(std::size_t precalculated_hash,
261-
value_type&& value) {
262-
return m_ht.insert_hash(precalculated_hash, std::move(value));
260+
std::pair<iterator, bool> insert_with_hash(std::size_t precalculated_hash,
261+
value_type&& value) {
262+
return m_ht.insert_with_hash(precalculated_hash, std::move(value));
263263
}
264264

265265
iterator insert(const_iterator hint, const value_type& value) {
@@ -311,20 +311,20 @@ class robin_map {
311311
* the insertion if you already have the hash.
312312
*/
313313
template <class M>
314-
std::pair<iterator, bool> insert_or_assign_hash(
314+
std::pair<iterator, bool> insert_or_assign_with_hash(
315315
std::size_t precalculated_hash, const key_type& k, M&& obj) {
316-
return m_ht.insert_or_assign_hash(precalculated_hash, k,
317-
std::forward<M>(obj));
316+
return m_ht.insert_or_assign_with_hash(precalculated_hash, k,
317+
std::forward<M>(obj));
318318
}
319319

320320
/**
321-
* @copydoc insert_or_assign_hash(std::size_t precalculated_hash, const key_type& k, M&& obj)
321+
* @copydoc insert_or_assign_with_hash(std::size_t precalculated_hash, const key_type& k, M&& obj)
322322
*/
323323
template <class M>
324-
std::pair<iterator, bool> insert_or_assign_hash(
324+
std::pair<iterator, bool> insert_or_assign_with_hash(
325325
std::size_t precalculated_hash, key_type&& k, M&& obj) {
326-
return m_ht.insert_or_assign_hash(precalculated_hash, std::move(k),
327-
std::forward<M>(obj));
326+
return m_ht.insert_or_assign_with_hash(precalculated_hash, std::move(k),
327+
std::forward<M>(obj));
328328
}
329329

330330
/**
@@ -378,21 +378,20 @@ class robin_map {
378378
* the insertion if you already have the hash.
379379
*/
380380
template <class... Args>
381-
std::pair<iterator, bool> try_emplace_hash(std::size_t precalculated_hash,
382-
const key_type& k,
383-
Args&&... args) {
384-
return m_ht.try_emplace_hash(precalculated_hash, k,
385-
std::forward<Args>(args)...);
381+
std::pair<iterator, bool> try_emplace_with_hash(
382+
std::size_t precalculated_hash, const key_type& k, Args&&... args) {
383+
return m_ht.try_emplace_with_hash(precalculated_hash, k,
384+
std::forward<Args>(args)...);
386385
}
387386

388387
/**
389-
* @copydoc try_emplace_hash(std::size_t precalculated_hash, const key_type& k, Args&&... args)
388+
* @copydoc try_emplace_with_hash(std::size_t precalculated_hash, const key_type& k, Args&&... args)
390389
*/
391390
template <class... Args>
392-
std::pair<iterator, bool> try_emplace_hash(std::size_t precalculated_hash,
393-
key_type&& k, Args&&... args) {
394-
return m_ht.try_emplace_hash(precalculated_hash, std::move(k),
395-
std::forward<Args>(args)...);
391+
std::pair<iterator, bool> try_emplace_with_hash(
392+
std::size_t precalculated_hash, key_type&& k, Args&&... args) {
393+
return m_ht.try_emplace_with_hash(precalculated_hash, std::move(k),
394+
std::forward<Args>(args)...);
396395
}
397396

398397
iterator erase(iterator pos) { return m_ht.erase(pos); }

include/tsl/robin_set.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,17 @@ class robin_set {
220220
* hash value should be the same as hash_function()(value). Useful to speed-up
221221
* the insertion if you already have the hash.
222222
*/
223-
std::pair<iterator, bool> insert_hash(std::size_t precalculated_hash,
224-
const value_type& value) {
225-
return m_ht.insert_hash(precalculated_hash, value);
223+
std::pair<iterator, bool> insert_with_hash(std::size_t precalculated_hash,
224+
const value_type& value) {
225+
return m_ht.insert_with_hash(precalculated_hash, value);
226226
}
227227

228228
/**
229-
* @copydoc insert_hash(std::size_t precalculated_hash, const value_type& value)
229+
* @copydoc insert_with_hash(std::size_t precalculated_hash, const value_type& value)
230230
*/
231-
std::pair<iterator, bool> insert_hash(std::size_t precalculated_hash,
232-
value_type&& value) {
233-
return m_ht.insert_hash(precalculated_hash, std::move(value));
231+
std::pair<iterator, bool> insert_with_hash(std::size_t precalculated_hash,
232+
value_type&& value) {
233+
return m_ht.insert_with_hash(precalculated_hash, std::move(value));
234234
}
235235

236236
iterator insert(const_iterator hint, const value_type& value) {

tests/robin_map_tests.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,41 +1440,41 @@ BOOST_AUTO_TEST_CASE(test_precalculated_hash) {
14401440
BOOST_CHECK_EQUAL(std::distance(it_range.first, it_range.second), 0);
14411441

14421442
/**
1443-
* try_emplace_hash
1443+
* try_emplace_with_hash
14441444
*/
1445-
auto it_te = map.try_emplace_hash(map.hash_function()(7), 7, -7);
1445+
auto it_te = map.try_emplace_with_hash(map.hash_function()(7), 7, -7);
14461446
BOOST_CHECK(it_te.second);
14471447
BOOST_CHECK_EQUAL(it_te.first->first, 7);
14481448
BOOST_CHECK_EQUAL(it_te.first->second, -7);
14491449

14501450
// Key already present: no insert, value left untouched.
1451-
it_te = map.try_emplace_hash(map.hash_function()(7), 7, -70);
1451+
it_te = map.try_emplace_with_hash(map.hash_function()(7), 7, -70);
14521452
BOOST_CHECK(!it_te.second);
14531453
BOOST_CHECK_EQUAL(it_te.first->second, -7);
14541454

14551455
/**
1456-
* insert_or_assign_hash
1456+
* insert_or_assign_with_hash
14571457
*/
1458-
auto it_ioa = map.insert_or_assign_hash(map.hash_function()(8), 8, -8);
1458+
auto it_ioa = map.insert_or_assign_with_hash(map.hash_function()(8), 8, -8);
14591459
BOOST_CHECK(it_ioa.second);
14601460
BOOST_CHECK_EQUAL(it_ioa.first->first, 8);
14611461
BOOST_CHECK_EQUAL(it_ioa.first->second, -8);
14621462

14631463
// Key already present: no insert, but value is overwritten.
1464-
it_ioa = map.insert_or_assign_hash(map.hash_function()(8), 8, -80);
1464+
it_ioa = map.insert_or_assign_with_hash(map.hash_function()(8), 8, -80);
14651465
BOOST_CHECK(!it_ioa.second);
14661466
BOOST_CHECK_EQUAL(it_ioa.first->second, -80);
14671467

14681468
/**
1469-
* insert_hash
1469+
* insert_with_hash
14701470
*/
1471-
auto it_ins = map.insert_hash(map.hash_function()(9), {9, -9});
1471+
auto it_ins = map.insert_with_hash(map.hash_function()(9), {9, -9});
14721472
BOOST_CHECK(it_ins.second);
14731473
BOOST_CHECK_EQUAL(it_ins.first->first, 9);
14741474
BOOST_CHECK_EQUAL(it_ins.first->second, -9);
14751475

14761476
// Key already present: no insert, value left untouched.
1477-
it_ins = map.insert_hash(map.hash_function()(9), {9, -90});
1477+
it_ins = map.insert_with_hash(map.hash_function()(9), {9, -90});
14781478
BOOST_CHECK(!it_ins.second);
14791479
BOOST_CHECK_EQUAL(it_ins.first->second, -9);
14801480

tests/robin_set_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,14 @@ BOOST_AUTO_TEST_CASE(test_precalculated_hash) {
200200
BOOST_CHECK_EQUAL(set.count(3, set.hash_function()(2)), 0);
201201

202202
/**
203-
* insert_hash
203+
* insert_with_hash
204204
*/
205-
auto it_ins = set.insert_hash(set.hash_function()(7), 7);
205+
auto it_ins = set.insert_with_hash(set.hash_function()(7), 7);
206206
BOOST_CHECK(it_ins.second);
207207
BOOST_CHECK_EQUAL(*it_ins.first, 7);
208208

209209
// Value already present: no insert.
210-
it_ins = set.insert_hash(set.hash_function()(7), 7);
210+
it_ins = set.insert_with_hash(set.hash_function()(7), 7);
211211
BOOST_CHECK(!it_ins.second);
212212
BOOST_CHECK_EQUAL(*it_ins.first, 7);
213213

0 commit comments

Comments
 (0)