Skip to content

Commit 4b4bded

Browse files
committed
[ThirdParty] The Parallel Hashmap の更新 #1297
1 parent 8c2d9b3 commit 4b4bded

File tree

9 files changed

+801
-683
lines changed

9 files changed

+801
-683
lines changed

Siv3D/include/ThirdParty/parallel_hashmap/btree.h

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include <cstring>
6161
#include <limits>
6262
#include <new>
63+
#include <type_traits>
6364

6465
#include "phmap_fwd_decl.h"
6566
#include "phmap_base.h"
@@ -76,14 +77,6 @@
7677

7778
namespace phmap {
7879

79-
// Defined and documented later on in this file.
80-
template <typename T>
81-
struct is_trivially_destructible;
82-
83-
// Defined and documented later on in this file.
84-
template <typename T>
85-
struct is_trivially_move_assignable;
86-
8780
namespace type_traits_internal {
8881

8982
// Silence MSVC warnings about the destructor being defined as deleted.
@@ -107,26 +100,26 @@ namespace phmap {
107100
: std::integral_constant<
108101
bool, std::is_move_constructible<
109102
type_traits_internal::SingleMemberUnion<T>>::value &&
110-
phmap::is_trivially_destructible<T>::value> {};
103+
std::is_trivially_destructible<T>::value> {};
111104

112105
template <class T>
113106
struct IsTriviallyCopyConstructibleObject
114107
: std::integral_constant<
115108
bool, std::is_copy_constructible<
116109
type_traits_internal::SingleMemberUnion<T>>::value &&
117-
phmap::is_trivially_destructible<T>::value> {};
118-
110+
std::is_trivially_destructible<T>::value> {};
111+
#if 0
119112
template <class T>
120113
struct IsTriviallyMoveAssignableReference : std::false_type {};
121114

122115
template <class T>
123116
struct IsTriviallyMoveAssignableReference<T&>
124-
: phmap::is_trivially_move_assignable<T>::type {};
117+
: std::is_trivially_move_assignable<T>::type {};
125118

126119
template <class T>
127120
struct IsTriviallyMoveAssignableReference<T&&>
128-
: phmap::is_trivially_move_assignable<T>::type {};
129-
121+
: std::is_trivially_move_assignable<T>::type {};
122+
#endif
130123
} // namespace type_traits_internal
131124

132125

@@ -155,10 +148,10 @@ namespace phmap {
155148

156149
public:
157150
static constexpr bool kValue =
158-
(__has_trivial_copy(ExtentsRemoved) || !kIsCopyOrMoveConstructible) &&
159-
(__has_trivial_assign(ExtentsRemoved) || !kIsCopyOrMoveAssignable) &&
151+
(phmap::is_trivially_copyable<ExtentsRemoved>::value || !kIsCopyOrMoveConstructible) &&
152+
(phmap::is_trivially_copy_assignable<ExtentsRemoved>::value || !kIsCopyOrMoveAssignable) &&
160153
(kIsCopyOrMoveConstructible || kIsCopyOrMoveAssignable) &&
161-
is_trivially_destructible<ExtentsRemoved>::value &&
154+
std::is_trivially_destructible<ExtentsRemoved>::value &&
162155
// We need to check for this explicitly because otherwise we'll say
163156
// references are trivial copyable when compiled by MSVC.
164157
!std::is_reference<ExtentsRemoved>::value;
@@ -744,13 +737,13 @@ namespace priv {
744737
StringBtreeDefaultLess(std::less<std::string_view>) {} // NOLINT
745738
StringBtreeDefaultLess(phmap::Less<std::string_view>) {} // NOLINT
746739

747-
phmap::weak_ordering operator()(std::string_view lhs,
748-
std::string_view rhs) const {
740+
phmap::weak_ordering operator()(const std::string_view &lhs,
741+
const std::string_view &rhs) const {
749742
return compare_internal::compare_result_as_ordering(lhs.compare(rhs));
750743
}
751744
#else
752-
phmap::weak_ordering operator()(std::string lhs,
753-
std::string rhs) const {
745+
phmap::weak_ordering operator()(const std::string &lhs,
746+
const std::string &rhs) const {
754747
return compare_internal::compare_result_as_ordering(lhs.compare(rhs));
755748
}
756749
#endif
@@ -770,8 +763,8 @@ namespace priv {
770763
return compare_internal::compare_result_as_ordering(rhs.compare(lhs));
771764
}
772765
#else
773-
phmap::weak_ordering operator()(std::string lhs,
774-
std::string rhs) const {
766+
phmap::weak_ordering operator()(const std::string &lhs,
767+
const std::string &rhs) const {
775768
return compare_internal::compare_result_as_ordering(rhs.compare(lhs));
776769
}
777770
#endif
@@ -1868,7 +1861,7 @@ namespace priv {
18681861
void swap(btree &x);
18691862

18701863
const key_compare &key_comp() const noexcept {
1871-
return root_.template get<0>();
1864+
return std::get<0>(root_);
18721865
}
18731866
template <typename K, typename LK>
18741867
bool compare_keys(const K &x, const LK &y) const {
@@ -1961,21 +1954,21 @@ namespace priv {
19611954

19621955
private:
19631956
// Internal accessor routines.
1964-
node_type *root() { return root_.template get<2>(); }
1965-
const node_type *root() const { return root_.template get<2>(); }
1966-
node_type *&mutable_root() noexcept { return root_.template get<2>(); }
1967-
key_compare *mutable_key_comp() noexcept { return &root_.template get<0>(); }
1957+
node_type *root() { return std::get<2>(root_); }
1958+
const node_type *root() const { return std::get<2>(root_); }
1959+
node_type *&mutable_root() noexcept { return std::get<2>(root_); }
1960+
key_compare *mutable_key_comp() noexcept { return &std::get<0>(root_); }
19681961

19691962
// The leftmost node is stored as the parent of the root node.
19701963
node_type *leftmost() { return root()->parent(); }
19711964
const node_type *leftmost() const { return root()->parent(); }
19721965

19731966
// Allocator routines.
19741967
allocator_type *mutable_allocator() noexcept {
1975-
return &root_.template get<1>();
1968+
return &std::get<1>(root_);
19761969
}
19771970
const allocator_type &allocator() const noexcept {
1978-
return root_.template get<1>();
1971+
return std::get<1>(root_);
19791972
}
19801973

19811974
// Allocates a correctly aligned node of at least size bytes using the
@@ -2117,11 +2110,7 @@ namespace priv {
21172110
}
21182111

21192112
private:
2120-
// We use compressed tuple in order to save space because key_compare and
2121-
// allocator_type are usually empty.
2122-
phmap::priv::CompressedTuple<key_compare, allocator_type,
2123-
node_type *>
2124-
root_;
2113+
std::tuple<key_compare, allocator_type, node_type *> root_;
21252114

21262115
// A pointer to the rightmost node. Note that the leftmost node is stored as
21272116
// the root's parent.
@@ -3332,8 +3321,8 @@ namespace priv {
33323321
// ----------------
33333322
template <typename K = key_type>
33343323
size_type count(const key_arg<K> &key) const {
3335-
auto equal_range = this->equal_range(key);
3336-
return std::distance(equal_range.first, equal_range.second);
3324+
auto er = this->equal_range(key);
3325+
return std::distance(er.first, er.second);
33373326
}
33383327
template <typename K = key_type>
33393328
iterator find(const key_arg<K> &key) {
@@ -3373,8 +3362,8 @@ namespace priv {
33733362
}
33743363
template <typename K = key_type>
33753364
size_type erase(const key_arg<K> &key) {
3376-
auto equal_range = this->equal_range(key);
3377-
return tree_.erase_range(equal_range.first, equal_range.second).first;
3365+
auto er = this->equal_range(key);
3366+
return tree_.erase_range(er.first, er.second).first;
33783367
}
33793368
node_type extract(iterator position) {
33803369
// Use Move instead of Transfer, because the rebalancing code expects to

0 commit comments

Comments
 (0)