mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-29 08:34:39 +08:00
Merge branch 'master' of https://github.com/greg7mdp/parallel-hashmap
This commit is contained in:
Vendored
+6
-6
@@ -712,8 +712,8 @@ namespace phmap {
|
||||
|
||||
template <
|
||||
typename Compare, typename K, typename LK,
|
||||
phmap::enable_if_t<!std::is_same<bool, phmap::result_of_t<
|
||||
Compare(const K &, const LK &)>>::value,
|
||||
phmap::enable_if_t<!std::is_same<bool, phmap::invoke_result_t<
|
||||
Compare, const K &, const LK &>>::value,
|
||||
int> = 0>
|
||||
constexpr phmap::weak_ordering do_three_way_comparison(const Compare &compare,
|
||||
const K &x, const LK &y) {
|
||||
@@ -721,8 +721,8 @@ namespace phmap {
|
||||
}
|
||||
template <
|
||||
typename Compare, typename K, typename LK,
|
||||
phmap::enable_if_t<std::is_same<bool, phmap::result_of_t<Compare(
|
||||
const K &, const LK &)>>::value,
|
||||
phmap::enable_if_t<std::is_same<bool, phmap::invoke_result_t<Compare,
|
||||
const K &, const LK &>>::value,
|
||||
int> = 0>
|
||||
constexpr phmap::weak_ordering do_three_way_comparison(const Compare &compare,
|
||||
const K &x, const LK &y) {
|
||||
@@ -743,7 +743,7 @@ namespace container_internal {
|
||||
// comparator.
|
||||
template <typename Compare, typename T>
|
||||
using btree_is_key_compare_to =
|
||||
std::is_convertible<phmap::result_of_t<Compare(const T &, const T &)>,
|
||||
std::is_convertible<phmap::invoke_result_t<Compare, const T &, const T &>,
|
||||
phmap::weak_ordering>;
|
||||
|
||||
struct StringBtreeDefaultLess {
|
||||
@@ -2507,7 +2507,7 @@ namespace container_internal {
|
||||
|
||||
// Verify that key_compare returns an phmap::{weak,strong}_ordering or bool.
|
||||
using compare_result_type =
|
||||
phmap::result_of_t<key_compare(key_type, key_type)>;
|
||||
phmap::invoke_result_t<key_compare, key_type, key_type>;
|
||||
static_assert(
|
||||
std::is_same<compare_result_type, bool>::value ||
|
||||
std::is_convertible<compare_result_type, phmap::weak_ordering>::value,
|
||||
|
||||
Vendored
+26
-7
@@ -2866,7 +2866,7 @@ public:
|
||||
Inner& inner = sets_[subidx(hashval)];
|
||||
auto& set = inner.set_;
|
||||
typename Lockable::UniqueLock m(inner);
|
||||
return make_iterator(&inner, set.lazy_emplace(key, hashval, std::forward<F>(f)));
|
||||
return make_iterator(&inner, set.lazy_emplace_with_hash(key, hashval, std::forward<F>(f)));
|
||||
}
|
||||
|
||||
// Extension API: support for heterogeneous keys.
|
||||
@@ -3032,11 +3032,8 @@ public:
|
||||
// --------------------------------------------------------------------
|
||||
template <class K = key_type>
|
||||
iterator find(const key_arg<K>& key, size_t hashval) {
|
||||
Inner& inner = sets_[subidx(hashval)];
|
||||
auto& set = inner.set_;
|
||||
typename Lockable::SharedLock m(inner);
|
||||
auto it = set.find(key, hashval);
|
||||
return make_iterator(&inner, it);
|
||||
typename Lockable::SharedLock m;
|
||||
return find(key, hashval, m);
|
||||
}
|
||||
|
||||
template <class K = key_type>
|
||||
@@ -3194,6 +3191,15 @@ private:
|
||||
}
|
||||
|
||||
protected:
|
||||
template <class K = key_type>
|
||||
iterator find(const key_arg<K>& key, size_t hashval, typename Lockable::SharedLock &mutexlock) {
|
||||
Inner& inner = sets_[subidx(hashval)];
|
||||
auto& set = inner.set_;
|
||||
mutexlock = std::move(typename Lockable::SharedLock(inner));
|
||||
auto it = set.find(key, hashval);
|
||||
return make_iterator(&inner, it);
|
||||
}
|
||||
|
||||
template <class K>
|
||||
std::tuple<Inner*, size_t, bool>
|
||||
find_or_prepare_insert(const K& key, typename Lockable::UniqueLock &mutexlock) {
|
||||
@@ -3219,7 +3225,7 @@ protected:
|
||||
}
|
||||
|
||||
template <class K>
|
||||
size_t hash(const K& key) {
|
||||
size_t hash(const K& key) const {
|
||||
return HashElement{hash_ref()}(key);
|
||||
}
|
||||
|
||||
@@ -3387,6 +3393,19 @@ public:
|
||||
return Policy::value(&*it);
|
||||
}
|
||||
|
||||
template <class K = key_type, class F>
|
||||
bool if_contains(const key_arg<K>& key, F&& f) const {
|
||||
#if __cplusplus >= 201703L
|
||||
static_assert(std::is_invocable<F, mapped_type&>::value);
|
||||
#endif
|
||||
typename Lockable::SharedLock m;
|
||||
auto it = const_cast<parallel_hash_map*>(this)->find(key, this->hash(key), m);
|
||||
if (it == this->end())
|
||||
return false;
|
||||
std::forward<F>(f)(Policy::value(&*it));
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class K = key_type, class P = Policy, K* = nullptr>
|
||||
MappedReference<P> operator[](key_arg<K>&& key) {
|
||||
return Policy::value(&*try_emplace(std::forward<K>(key)).first);
|
||||
|
||||
Vendored
+6
-2
@@ -328,8 +328,12 @@ using common_type_t = typename std::common_type<T...>::type;
|
||||
template <typename T>
|
||||
using underlying_type_t = typename std::underlying_type<T>::type;
|
||||
|
||||
template <typename T>
|
||||
using result_of_t = typename std::result_of<T>::type;
|
||||
template< class F, class... ArgTypes>
|
||||
#if __cplusplus >= 201703L
|
||||
using invoke_result_t = typename std::invoke_result_t<F, ArgTypes...>;
|
||||
#else
|
||||
using invoke_result_t = typename std::result_of<F(ArgTypes...)>::type;
|
||||
#endif
|
||||
|
||||
namespace type_traits_internal {
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -21,14 +21,14 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#if defined(PHMAP_USE_ABSL_HASH)
|
||||
#if defined(PHMAP_USE_ABSL_HASH) && !defined(ABSL_HASH_HASH_H_)
|
||||
namespace absl { template <class T> struct Hash; };
|
||||
#endif
|
||||
|
||||
namespace phmap {
|
||||
|
||||
#if defined(PHMAP_USE_ABSL_HASH)
|
||||
template <class T> using Hash = absl::Hash<T>;
|
||||
template <class T> using Hash = ::absl::Hash<T>;
|
||||
#else
|
||||
template <class T> struct Hash;
|
||||
#endif
|
||||
|
||||
Vendored
+9
-3
@@ -33,6 +33,13 @@
|
||||
#include <tuple>
|
||||
#include "phmap_bits.h"
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Absl forward declaration requires global scope.
|
||||
// ---------------------------------------------------------------
|
||||
#if defined(PHMAP_USE_ABSL_HASH) && !defined(phmap_fwd_decl_h_guard_) && !defined(ABSL_HASH_HASH_H_)
|
||||
namespace absl { template <class T> struct Hash; };
|
||||
#endif
|
||||
|
||||
namespace phmap
|
||||
{
|
||||
|
||||
@@ -132,9 +139,8 @@ public:
|
||||
};
|
||||
|
||||
#if defined(PHMAP_USE_ABSL_HASH) && !defined(phmap_fwd_decl_h_guard_)
|
||||
namespace absl { template <class T> struct Hash; };
|
||||
template <class T> using Hash = absl::Hash<T>;
|
||||
#else
|
||||
template <class T> using Hash = ::absl::Hash<T>;
|
||||
#elif !defined(PHMAP_USE_ABSL_HASH)
|
||||
// ---------------------------------------------------------------
|
||||
// phmap::Hash
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user