Skip to content

Commit

Permalink
Reduce verbosity with using directives.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed Nov 19, 2023
1 parent 4d7b07f commit d51c761
Showing 1 changed file with 43 additions and 39 deletions.
82 changes: 43 additions & 39 deletions parallel_hashmap/phmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -2579,7 +2579,10 @@ class parallel_hash_set
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;


// --------------------------------------------------------------------
Expand Down Expand Up @@ -2631,9 +2634,7 @@ class parallel_hash_set
// --------------------------------------------------------------------
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.
Expand Down Expand Up @@ -2960,7 +2961,7 @@ class parallel_hash_set
PHMAP_ATTRIBUTE_REINITIALIZES void clear() {
for (auto& inner : sets_)
{
typename Lockable::UniqueLock m(inner);
UniqueLock m(inner);
inner.set_.clear();
}
}
Expand All @@ -2969,7 +2970,7 @@ class parallel_hash_set
// ----------------------------------------
void clear(std::size_t submap_index) {
Inner& inner = sets_[submap_index];
typename Lockable::UniqueLock m(inner);
UniqueLock m(inner);
inner.set_.clear();
}

Expand Down Expand Up @@ -3062,7 +3063,7 @@ class parallel_hash_set
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,
Expand Down Expand Up @@ -3125,7 +3126,7 @@ class parallel_hash_set
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));
}
Expand All @@ -3144,7 +3145,7 @@ class parallel_hash_set
{
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()) {
Expand Down Expand Up @@ -3205,7 +3206,7 @@ class parallel_hash_set
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));
}
Expand Down Expand Up @@ -3234,7 +3235,7 @@ class parallel_hash_set
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
Expand All @@ -3260,7 +3261,7 @@ class parallel_hash_set
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));
}

Expand All @@ -3275,7 +3276,7 @@ class parallel_hash_set
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,
Expand All @@ -3293,7 +3294,7 @@ class parallel_hash_set
// ----------------------------------------------------------------------------------------------------
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));
}

// -----------------------------------------------------------------------------------------
Expand All @@ -3317,7 +3318,7 @@ class parallel_hash_set
// ----------------------------------------------------------------------------------------------------
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>
Expand Down Expand Up @@ -3355,7 +3356,7 @@ class parallel_hash_set
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)) {
Expand All @@ -3380,7 +3381,7 @@ class parallel_hash_set
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);
}
}
Expand All @@ -3389,7 +3390,7 @@ class parallel_hash_set
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);
}
}
Expand All @@ -3400,7 +3401,7 @@ class parallel_hash_set
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);
}
);
Expand All @@ -3411,7 +3412,7 @@ class parallel_hash_set
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);
}
);
Expand All @@ -3427,15 +3428,15 @@ class parallel_hash_set
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);
}

template <class F>
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);
}

Expand Down Expand Up @@ -3492,7 +3493,7 @@ class parallel_hash_set
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_);
}
Expand Down Expand Up @@ -3566,7 +3567,7 @@ class parallel_hash_set
size_t nn = n / num_tables;
for (auto& inner : sets_)
{
typename Lockable::UniqueLock m(inner);
UniqueLock m(inner);
inner.set_.rehash(nn);
}
}
Expand Down Expand Up @@ -3602,7 +3603,7 @@ class parallel_hash_set
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);
}

Expand All @@ -3621,7 +3622,7 @@ class parallel_hash_set
// --------------------------------------------------------------------
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);
}

Expand Down Expand Up @@ -3669,7 +3670,7 @@ class parallel_hash_set
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;
Expand Down Expand Up @@ -3765,7 +3766,7 @@ class parallel_hash_set
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();
}
}
Expand All @@ -3774,7 +3775,7 @@ class parallel_hash_set
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);
}

Expand All @@ -3795,7 +3796,7 @@ class parallel_hash_set
}

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)];
Expand All @@ -3804,7 +3805,7 @@ class parallel_hash_set
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_;
Expand All @@ -3814,10 +3815,10 @@ class parallel_hash_set

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
Expand All @@ -3833,7 +3834,7 @@ class parallel_hash_set

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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -4052,7 +4056,7 @@ class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, Policy, Hash
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)) {
Expand All @@ -4073,7 +4077,7 @@ class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, Policy, Hash
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)) {
Expand Down Expand Up @@ -4103,7 +4107,7 @@ class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, Policy, Hash
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)) {
Expand All @@ -4123,7 +4127,7 @@ class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, Policy, Hash

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)) {
Expand Down

0 comments on commit d51c761

Please sign in to comment.