mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-30 00:50:38 +08:00
Reduce verbosity with using directives.
This commit is contained in:
Vendored
+43
-39
@@ -2579,7 +2579,10 @@ public:
|
||||
using key_arg = typename KeyArgImpl::template type<K, key_type>;
|
||||
|
||||
protected:
|
||||
using Lockable = phmap::LockableImpl<Mtx_>;
|
||||
using Lockable = phmap::LockableImpl<Mtx_>;
|
||||
using UniqueLock = typename Lockable::UniqueLock;
|
||||
using SharedLock = typename Lockable::SharedLock;
|
||||
using ReadWriteLock = typename Lockable::ReadWriteLock;
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
@@ -2631,9 +2634,7 @@ private:
|
||||
// --------------------------------------------------------------------
|
||||
template <class T>
|
||||
using RequiresInsertable = typename std::enable_if<
|
||||
phmap::disjunction<std::is_convertible<T, init_type>,
|
||||
SameAsElementReference<T>>::value,
|
||||
int>::type;
|
||||
phmap::disjunction<std::is_convertible<T, init_type>, SameAsElementReference<T>>::value, int>::type;
|
||||
|
||||
// RequiresNotInit is a workaround for gcc prior to 7.1.
|
||||
// See https://godbolt.org/g/Y4xsUh.
|
||||
@@ -2960,7 +2961,7 @@ public:
|
||||
PHMAP_ATTRIBUTE_REINITIALIZES void clear() {
|
||||
for (auto& inner : sets_)
|
||||
{
|
||||
typename Lockable::UniqueLock m(inner);
|
||||
UniqueLock m(inner);
|
||||
inner.set_.clear();
|
||||
}
|
||||
}
|
||||
@@ -2969,7 +2970,7 @@ public:
|
||||
// ----------------------------------------
|
||||
void clear(std::size_t submap_index) {
|
||||
Inner& inner = sets_[submap_index];
|
||||
typename Lockable::UniqueLock m(inner);
|
||||
UniqueLock m(inner);
|
||||
inner.set_.clear();
|
||||
}
|
||||
|
||||
@@ -3062,7 +3063,7 @@ public:
|
||||
Inner& inner = sets_[subidx(hashval)];
|
||||
auto& set = inner.set_;
|
||||
|
||||
typename Lockable::UniqueLock m(inner);
|
||||
UniqueLock m(inner);
|
||||
auto res = set.insert(std::move(node), hashval);
|
||||
return { make_iterator(&inner, res.position),
|
||||
res.inserted,
|
||||
@@ -3125,7 +3126,7 @@ public:
|
||||
const auto& elem = PolicyTraits::element(slot);
|
||||
Inner& inner = sets_[subidx(hashval)];
|
||||
auto& set = inner.set_;
|
||||
typename Lockable::UniqueLock m(inner);
|
||||
UniqueLock m(inner);
|
||||
typename EmbeddedSet::template InsertSlotWithHash<true> f { inner, std::move(*slot), hashval };
|
||||
return make_rv(PolicyTraits::apply(f, elem));
|
||||
}
|
||||
@@ -3144,7 +3145,7 @@ public:
|
||||
{
|
||||
Inner& inner = sets_[subidx(hashval)];
|
||||
auto& set = inner.set_;
|
||||
typename Lockable::ReadWriteLock m(inner);
|
||||
ReadWriteLock m(inner);
|
||||
|
||||
size_t offset = set._find_key(key, hashval);
|
||||
if (offset == (size_t)-1 && m.switch_to_unique()) {
|
||||
@@ -3205,7 +3206,7 @@ public:
|
||||
const auto& elem = PolicyTraits::element(slot);
|
||||
Inner& inner = sets_[subidx(hashval)];
|
||||
auto& set = inner.set_;
|
||||
typename Lockable::UniqueLock m(inner);
|
||||
UniqueLock m(inner);
|
||||
typename EmbeddedSet::template InsertSlotWithHash<true> f { inner, std::move(*slot), hashval };
|
||||
return make_rv(PolicyTraits::apply(f, elem));
|
||||
}
|
||||
@@ -3234,7 +3235,7 @@ public:
|
||||
iterator lazy_emplace_with_hash(const key_arg<K>& key, size_t hashval, F&& f) {
|
||||
Inner& inner = sets_[subidx(hashval)];
|
||||
auto& set = inner.set_;
|
||||
typename Lockable::ReadWriteLock m(inner);
|
||||
ReadWriteLock m(inner);
|
||||
size_t offset = set._find_key(key, hashval);
|
||||
if (offset == (size_t)-1 && m.switch_to_unique()) {
|
||||
// we did an unlock/lock, and another thread could have inserted the same key, so we need to
|
||||
@@ -3260,7 +3261,7 @@ public:
|
||||
void emplace_single_with_hash(const key_arg<K>& key, size_t hashval, F&& f) {
|
||||
Inner& inner = sets_[subidx(hashval)];
|
||||
auto& set = inner.set_;
|
||||
typename Lockable::UniqueLock m(inner);
|
||||
UniqueLock m(inner);
|
||||
set.emplace_single_with_hash(key, hashval, std::forward<F>(f));
|
||||
}
|
||||
|
||||
@@ -3275,7 +3276,7 @@ public:
|
||||
template <class K = key_type, class F>
|
||||
bool if_contains(const key_arg<K>& key, F&& f) const {
|
||||
return const_cast<parallel_hash_set*>(this)->template
|
||||
modify_if_impl<K, F, typename Lockable::SharedLock>(key, std::forward<F>(f));
|
||||
modify_if_impl<K, F, SharedLock>(key, std::forward<F>(f));
|
||||
}
|
||||
|
||||
// if set contains key, lambda is called with the value_type without read lock protection,
|
||||
@@ -3293,7 +3294,7 @@ public:
|
||||
// ----------------------------------------------------------------------------------------------------
|
||||
template <class K = key_type, class F>
|
||||
bool modify_if(const key_arg<K>& key, F&& f) {
|
||||
return modify_if_impl<K, F, typename Lockable::UniqueLock>(key, std::forward<F>(f));
|
||||
return modify_if_impl<K, F, UniqueLock>(key, std::forward<F>(f));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
@@ -3317,7 +3318,7 @@ public:
|
||||
// ----------------------------------------------------------------------------------------------------
|
||||
template <class K = key_type, class F>
|
||||
bool erase_if(const key_arg<K>& key, F&& f) {
|
||||
return erase_if_impl<K, F, typename Lockable::ReadWriteLock>(key, std::forward<F>(f));
|
||||
return erase_if_impl<K, F, ReadWriteLock>(key, std::forward<F>(f));
|
||||
}
|
||||
|
||||
template <class K = key_type, class F, class L>
|
||||
@@ -3355,7 +3356,7 @@ public:
|
||||
template <class K = key_type, class FExists, class FEmplace>
|
||||
bool lazy_emplace_l(const key_arg<K>& key, FExists&& fExists, FEmplace&& fEmplace) {
|
||||
size_t hashval = this->hash(key);
|
||||
typename Lockable::ReadWriteLock m;
|
||||
ReadWriteLock m;
|
||||
auto res = this->find_or_prepare_insert_with_hash(hashval, key, m);
|
||||
Inner* inner = std::get<0>(res);
|
||||
if (std::get<2>(res)) {
|
||||
@@ -3380,7 +3381,7 @@ public:
|
||||
template <class F>
|
||||
void for_each(F&& fCallback) const {
|
||||
for (auto const& inner : sets_) {
|
||||
typename Lockable::SharedLock m(const_cast<Inner&>(inner));
|
||||
SharedLock m(const_cast<Inner&>(inner));
|
||||
std::for_each(inner.set_.begin(), inner.set_.end(), fCallback);
|
||||
}
|
||||
}
|
||||
@@ -3389,7 +3390,7 @@ public:
|
||||
template <class F>
|
||||
void for_each_m(F&& fCallback) {
|
||||
for (auto& inner : sets_) {
|
||||
typename Lockable::UniqueLock m(inner);
|
||||
UniqueLock m(inner);
|
||||
std::for_each(inner.set_.begin(), inner.set_.end(), fCallback);
|
||||
}
|
||||
}
|
||||
@@ -3400,7 +3401,7 @@ public:
|
||||
std::for_each(
|
||||
std::forward<ExecutionPolicy>(policy), sets_.begin(), sets_.end(),
|
||||
[&](auto const& inner) {
|
||||
typename Lockable::SharedLock m(const_cast<Inner&>(inner));
|
||||
SharedLock m(const_cast<Inner&>(inner));
|
||||
std::for_each(inner.set_.begin(), inner.set_.end(), fCallback);
|
||||
}
|
||||
);
|
||||
@@ -3411,7 +3412,7 @@ public:
|
||||
std::for_each(
|
||||
std::forward<ExecutionPolicy>(policy), sets_.begin(), sets_.end(),
|
||||
[&](auto& inner) {
|
||||
typename Lockable::UniqueLock m(inner);
|
||||
UniqueLock m(inner);
|
||||
std::for_each(inner.set_.begin(), inner.set_.end(), fCallback);
|
||||
}
|
||||
);
|
||||
@@ -3427,7 +3428,7 @@ public:
|
||||
void with_submap(size_t idx, F&& fCallback) const {
|
||||
const Inner& inner = sets_[idx];
|
||||
const auto& set = inner.set_;
|
||||
typename Lockable::SharedLock m(const_cast<Inner&>(inner));
|
||||
SharedLock m(const_cast<Inner&>(inner));
|
||||
fCallback(set);
|
||||
}
|
||||
|
||||
@@ -3435,7 +3436,7 @@ public:
|
||||
void with_submap_m(size_t idx, F&& fCallback) {
|
||||
Inner& inner = sets_[idx];
|
||||
auto& set = inner.set_;
|
||||
typename Lockable::UniqueLock m(inner);
|
||||
UniqueLock m(inner);
|
||||
fCallback(set);
|
||||
}
|
||||
|
||||
@@ -3492,7 +3493,7 @@ public:
|
||||
Inner* inner = it.inner_;
|
||||
assert(inner != nullptr);
|
||||
auto& set = inner->set_;
|
||||
// typename Lockable::UniqueLock m(*inner); // don't lock here
|
||||
// UniqueLock m(*inner); // don't lock here
|
||||
|
||||
set._erase(it.it_);
|
||||
}
|
||||
@@ -3566,7 +3567,7 @@ public:
|
||||
size_t nn = n / num_tables;
|
||||
for (auto& inner : sets_)
|
||||
{
|
||||
typename Lockable::UniqueLock m(inner);
|
||||
UniqueLock m(inner);
|
||||
inner.set_.rehash(nn);
|
||||
}
|
||||
}
|
||||
@@ -3602,7 +3603,7 @@ public:
|
||||
void prefetch_hash(size_t hashval) const {
|
||||
const Inner& inner = sets_[subidx(hashval)];
|
||||
const auto& set = inner.set_;
|
||||
typename Lockable::SharedLock m(const_cast<Inner&>(inner));
|
||||
SharedLock m(const_cast<Inner&>(inner));
|
||||
set.prefetch_hash(hashval);
|
||||
}
|
||||
|
||||
@@ -3621,7 +3622,7 @@ public:
|
||||
// --------------------------------------------------------------------
|
||||
template <class K = key_type>
|
||||
iterator find(const key_arg<K>& key, size_t hashval) {
|
||||
typename Lockable::SharedLock m;
|
||||
SharedLock m;
|
||||
return find(key, hashval, m);
|
||||
}
|
||||
|
||||
@@ -3669,7 +3670,7 @@ public:
|
||||
size_t sz = 0;
|
||||
for (const auto& inner : sets_)
|
||||
{
|
||||
typename Lockable::SharedLock m(const_cast<Inner&>(inner));
|
||||
SharedLock m(const_cast<Inner&>(inner));
|
||||
sz += inner.set_.bucket_count();
|
||||
}
|
||||
return sz;
|
||||
@@ -3765,7 +3766,7 @@ private:
|
||||
void drop_deletes_without_resize() PHMAP_ATTRIBUTE_NOINLINE {
|
||||
for (auto& inner : sets_)
|
||||
{
|
||||
typename Lockable::UniqueLock m(inner);
|
||||
UniqueLock m(inner);
|
||||
inner.set_.drop_deletes_without_resize();
|
||||
}
|
||||
}
|
||||
@@ -3774,7 +3775,7 @@ private:
|
||||
size_t hashval = PolicyTraits::apply(HashElement{hash_ref()}, elem);
|
||||
Inner& inner = sets_[subidx(hashval)];
|
||||
auto& set = inner.set_;
|
||||
typename Lockable::SharedLock m(const_cast<Inner&>(inner));
|
||||
SharedLock m(const_cast<Inner&>(inner));
|
||||
return set.has_element(elem, hashval);
|
||||
}
|
||||
|
||||
@@ -3795,7 +3796,7 @@ private:
|
||||
}
|
||||
|
||||
protected:
|
||||
template <class K = key_type, class L = typename Lockable::SharedLock>
|
||||
template <class K = key_type, class L = SharedLock>
|
||||
pointer find_ptr(const key_arg<K>& key, size_t hashval, L& mutexlock)
|
||||
{
|
||||
Inner& inner = sets_[subidx(hashval)];
|
||||
@@ -3804,7 +3805,7 @@ protected:
|
||||
return set.find_ptr(key, hashval);
|
||||
}
|
||||
|
||||
template <class K = key_type, class L = typename Lockable::SharedLock>
|
||||
template <class K = key_type, class L = SharedLock>
|
||||
iterator find(const key_arg<K>& key, size_t hashval, L& mutexlock) {
|
||||
Inner& inner = sets_[subidx(hashval)];
|
||||
auto& set = inner.set_;
|
||||
@@ -3814,10 +3815,10 @@ protected:
|
||||
|
||||
template <class K>
|
||||
std::tuple<Inner*, size_t, bool>
|
||||
find_or_prepare_insert_with_hash(size_t hashval, const K& key, typename Lockable::ReadWriteLock &mutexlock) {
|
||||
find_or_prepare_insert_with_hash(size_t hashval, const K& key, ReadWriteLock &mutexlock) {
|
||||
Inner& inner = sets_[subidx(hashval)];
|
||||
auto& set = inner.set_;
|
||||
mutexlock = std::move(typename Lockable::ReadWriteLock(inner));
|
||||
mutexlock = std::move(ReadWriteLock(inner));
|
||||
size_t offset = set._find_key(key, hashval);
|
||||
if (offset == (size_t)-1 && mutexlock.switch_to_unique()) {
|
||||
// we did an unlock/lock, and another thread could have inserted the same key, so we need to
|
||||
@@ -3833,7 +3834,7 @@ protected:
|
||||
|
||||
template <class K>
|
||||
std::tuple<Inner*, size_t, bool>
|
||||
find_or_prepare_insert(const K& key, typename Lockable::ReadWriteLock &mutexlock) {
|
||||
find_or_prepare_insert(const K& key, ReadWriteLock &mutexlock) {
|
||||
return find_or_prepare_insert_with_hash<K>(this->hash(key), key, mutexlock);
|
||||
}
|
||||
|
||||
@@ -3901,7 +3902,10 @@ class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, Policy, Hash
|
||||
KeyArg<IsTransparent<Eq>::value && IsTransparent<Hash>::value>;
|
||||
|
||||
using Base = typename parallel_hash_map::parallel_hash_set;
|
||||
using Lockable = phmap::LockableImpl<Mtx_>;
|
||||
using Lockable = phmap::LockableImpl<Mtx_>;
|
||||
using UniqueLock = typename Lockable::UniqueLock;
|
||||
using SharedLock = typename Lockable::SharedLock;
|
||||
using ReadWriteLock = typename Lockable::ReadWriteLock;
|
||||
|
||||
public:
|
||||
using key_type = typename Policy::key_type;
|
||||
@@ -4052,7 +4056,7 @@ public:
|
||||
template <class K = key_type, class F, class... Args>
|
||||
bool try_emplace_l(K&& k, F&& f, Args&&... args) {
|
||||
size_t hashval = this->hash(k);
|
||||
typename Lockable::ReadWriteLock m;
|
||||
ReadWriteLock m;
|
||||
auto res = this->find_or_prepare_insert_with_hash(hashval, k, m);
|
||||
typename Base::Inner *inner = std::get<0>(res);
|
||||
if (std::get<2>(res)) {
|
||||
@@ -4073,7 +4077,7 @@ public:
|
||||
template <class K = key_type, class... Args>
|
||||
std::pair<typename parallel_hash_map::parallel_hash_set::pointer, bool> try_emplace_p(K&& k, Args&&... args) {
|
||||
size_t hashval = this->hash(k);
|
||||
typename Lockable::ReadWriteLock m;
|
||||
ReadWriteLock m;
|
||||
auto res = this->find_or_prepare_insert_with_hash(hashval, k, m);
|
||||
typename Base::Inner *inner = std::get<0>(res);
|
||||
if (std::get<2>(res)) {
|
||||
@@ -4103,7 +4107,7 @@ private:
|
||||
template <class K, class V>
|
||||
std::pair<iterator, bool> insert_or_assign_impl(K&& k, V&& v) {
|
||||
size_t hashval = this->hash(k);
|
||||
typename Lockable::ReadWriteLock m;
|
||||
ReadWriteLock m;
|
||||
auto res = this->find_or_prepare_insert_with_hash(hashval, k, m);
|
||||
typename Base::Inner *inner = std::get<0>(res);
|
||||
if (std::get<2>(res)) {
|
||||
@@ -4123,7 +4127,7 @@ private:
|
||||
|
||||
template <class K = key_type, class... Args>
|
||||
std::pair<iterator, bool> try_emplace_impl_with_hash(size_t hashval, K&& k, Args&&... args) {
|
||||
typename Lockable::ReadWriteLock m;
|
||||
ReadWriteLock m;
|
||||
auto res = this->find_or_prepare_insert_with_hash(hashval, k, m);
|
||||
typename Base::Inner *inner = std::get<0>(res);
|
||||
if (std::get<2>(res)) {
|
||||
|
||||
Reference in New Issue
Block a user