/src/parallel-hashmap/parallel_hashmap/phmap.h
Line  | Count  | Source  | 
1  |  | #if !defined(phmap_h_guard_)  | 
2  |  | #define phmap_h_guard_  | 
3  |  |  | 
4  |  | // ---------------------------------------------------------------------------  | 
5  |  | // Copyright (c) 2019, Gregory Popovitch - greg7mdp@gmail.com  | 
6  |  | //  | 
7  |  | // Licensed under the Apache License, Version 2.0 (the "License");  | 
8  |  | // you may not use this file except in compliance with the License.  | 
9  |  | // You may obtain a copy of the License at  | 
10  |  | //  | 
11  |  | //      https://www.apache.org/licenses/LICENSE-2.0  | 
12  |  | //  | 
13  |  | // Unless required by applicable law or agreed to in writing, software  | 
14  |  | // distributed under the License is distributed on an "AS IS" BASIS,  | 
15  |  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
16  |  | // See the License for the specific language governing permissions and  | 
17  |  | // limitations under the License.  | 
18  |  | //  | 
19  |  | // Includes work from abseil-cpp (https://github.com/abseil/abseil-cpp)  | 
20  |  | // with modifications.  | 
21  |  | //   | 
22  |  | // Copyright 2018 The Abseil Authors.  | 
23  |  | //  | 
24  |  | // Licensed under the Apache License, Version 2.0 (the "License");  | 
25  |  | // you may not use this file except in compliance with the License.  | 
26  |  | // You may obtain a copy of the License at  | 
27  |  | //  | 
28  |  | //      https://www.apache.org/licenses/LICENSE-2.0  | 
29  |  | //  | 
30  |  | // Unless required by applicable law or agreed to in writing, software  | 
31  |  | // distributed under the License is distributed on an "AS IS" BASIS,  | 
32  |  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
33  |  | // See the License for the specific language governing permissions and  | 
34  |  | // limitations under the License.  | 
35  |  | // ---------------------------------------------------------------------------  | 
36  |  |  | 
37  |  | // ---------------------------------------------------------------------------  | 
38  |  | // IMPLEMENTATION DETAILS  | 
39  |  | //  | 
40  |  | // The table stores elements inline in a slot array. In addition to the slot  | 
41  |  | // array the table maintains some control state per slot. The extra state is one  | 
42  |  | // byte per slot and stores empty or deleted marks, or alternatively 7 bits from  | 
43  |  | // the hash of an occupied slot. The table is split into logical groups of  | 
44  |  | // slots, like so:  | 
45  |  | //  | 
46  |  | //      Group 1         Group 2        Group 3  | 
47  |  | // +---------------+---------------+---------------+  | 
48  |  | // | | | | | | | | | | | | | | | | | | | | | | | | |  | 
49  |  | // +---------------+---------------+---------------+  | 
50  |  | //  | 
51  |  | // On lookup the hash is split into two parts:  | 
52  |  | // - H2: 7 bits (those stored in the control bytes)  | 
53  |  | // - H1: the rest of the bits  | 
54  |  | // The groups are probed using H1. For each group the slots are matched to H2 in  | 
55  |  | // parallel. Because H2 is 7 bits (128 states) and the number of slots per group  | 
56  |  | // is low (8 or 16) in almost all cases a match in H2 is also a lookup hit.  | 
57  |  | //  | 
58  |  | // On insert, once the right group is found (as in lookup), its slots are  | 
59  |  | // filled in order.  | 
60  |  | //  | 
61  |  | // On erase a slot is cleared. In case the group did not have any empty slots  | 
62  |  | // before the erase, the erased slot is marked as deleted.  | 
63  |  | //  | 
64  |  | // Groups without empty slots (but maybe with deleted slots) extend the probe  | 
65  |  | // sequence. The probing algorithm is quadratic. Given N the number of groups,  | 
66  |  | // the probing function for the i'th probe is:  | 
67  |  | //  | 
68  |  | //   P(0) = H1 % N  | 
69  |  | //  | 
70  |  | //   P(i) = (P(i - 1) + i) % N  | 
71  |  | //  | 
72  |  | // This probing function guarantees that after N probes, all the groups of the  | 
73  |  | // table will be probed exactly once.  | 
74  |  | //  | 
75  |  | // The control state and slot array are stored contiguously in a shared heap  | 
76  |  | // allocation. The layout of this allocation is: `capacity()` control bytes,  | 
77  |  | // one sentinel control byte, `Group::kWidth - 1` cloned control bytes,  | 
78  |  | // <possible padding>, `capacity()` slots. The sentinel control byte is used in  | 
79  |  | // iteration so we know when we reach the end of the table. The cloned control  | 
80  |  | // bytes at the end of the table are cloned from the beginning of the table so  | 
81  |  | // groups that begin near the end of the table can see a full group. In cases in  | 
82  |  | // which there are more than `capacity()` cloned control bytes, the extra bytes  | 
83  |  | // are `kEmpty`, and these ensure that we always see at least one empty slot and  | 
84  |  | // can stop an unsuccessful search.  | 
85  |  | // ---------------------------------------------------------------------------  | 
86  |  |  | 
87  |  |  | 
88  |  |  | 
89  |  | #ifdef _MSC_VER  | 
90  |  |     #pragma warning(push)    | 
91  |  |  | 
92  |  |     #pragma warning(disable : 4127) // conditional expression is constant  | 
93  |  |     #pragma warning(disable : 4324) // structure was padded due to alignment specifier  | 
94  |  |     #pragma warning(disable : 4514) // unreferenced inline function has been removed  | 
95  |  |     #pragma warning(disable : 4623) // default constructor was implicitly defined as deleted  | 
96  |  |     #pragma warning(disable : 4625) // copy constructor was implicitly defined as deleted  | 
97  |  |     #pragma warning(disable : 4626) // assignment operator was implicitly defined as deleted  | 
98  |  |     #pragma warning(disable : 4710) // function not inlined  | 
99  |  |     #pragma warning(disable : 4711) // selected for automatic inline expansion  | 
100  |  |     #pragma warning(disable : 4820) // '6' bytes padding added after data member  | 
101  |  |     #pragma warning(disable : 4868) // compiler may not enforce left-to-right evaluation order in braced initializer list  | 
102  |  |     #pragma warning(disable : 5027) // move assignment operator was implicitly defined as deleted  | 
103  |  |     #pragma warning(disable : 5045) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified  | 
104  |  | #endif  | 
105  |  |  | 
106  |  | #include <algorithm>  | 
107  |  | #include <cmath>  | 
108  |  | #include <cstring>  | 
109  |  | #include <iterator>  | 
110  |  | #include <limits>  | 
111  |  | #include <memory>  | 
112  |  | #include <tuple>  | 
113  |  | #include <type_traits>  | 
114  |  | #include <utility>  | 
115  |  | #include <array>  | 
116  |  | #include <cassert>  | 
117  |  | #include <atomic>  | 
118  |  |  | 
119  |  | #include "phmap_fwd_decl.h"  | 
120  |  | #include "phmap_utils.h"  | 
121  |  | #include "phmap_base.h"  | 
122  |  |  | 
123  |  | #if PHMAP_HAVE_STD_STRING_VIEW  | 
124  |  |     #include <string_view>  | 
125  |  | #endif  | 
126  |  |  | 
127  |  | namespace phmap { | 
128  |  |  | 
129  |  | namespace priv { | 
130  |  |  | 
131  |  | // --------------------------------------------------------------------------  | 
132  |  | template <typename AllocType>  | 
133  |  | void SwapAlloc(AllocType& lhs, AllocType& rhs,  | 
134  |  |                std::true_type /* propagate_on_container_swap */) { | 
135  |  |   using std::swap;  | 
136  |  |   swap(lhs, rhs);  | 
137  |  | }  | 
138  |  |  | 
139  |  | template <typename AllocType>  | 
140  |  | void SwapAlloc(AllocType& /*lhs*/, AllocType& /*rhs*/,  | 
141  | 595  |                std::false_type /* propagate_on_container_swap */) {} | 
142  |  |  | 
143  |  | // --------------------------------------------------------------------------  | 
144  |  | template <size_t Width>  | 
145  |  | class probe_seq   | 
146  |  | { | 
147  |  | public:  | 
148  | 13.3M  |     probe_seq(size_t hashval, size_t mask) { | 
149  | 13.3M  |         assert(((mask + 1) & mask) == 0 && "not a mask");  | 
150  | 13.3M  |         mask_ = mask;  | 
151  | 13.3M  |         offset_ = hashval & mask_;  | 
152  | 13.3M  |     }  | 
153  | 14.5M  |     size_t offset() const { return offset_; } | 
154  | 26.2M  |     size_t offset(size_t i) const { return (offset_ + i) & mask_; } | 
155  |  |  | 
156  | 1.17M  |     void next() { | 
157  | 1.17M  |         index_ += Width;  | 
158  | 1.17M  |         offset_ += index_;  | 
159  | 1.17M  |         offset_ &= mask_;  | 
160  | 1.17M  |     }  | 
161  |  |     // 0-based probe index. The i-th probe in the probe sequence.  | 
162  | 1.61M  |     size_t getindex() const { return index_; } | 
163  |  |  | 
164  |  | private:  | 
165  |  |     size_t mask_;  | 
166  |  |     size_t offset_;  | 
167  |  |     size_t index_ = 0;  | 
168  |  | };  | 
169  |  |  | 
170  |  | // --------------------------------------------------------------------------  | 
171  |  | template <class ContainerKey, class Hash, class Eq>  | 
172  |  | struct RequireUsableKey   | 
173  |  | { | 
174  |  |     template <class PassedKey, class... Args>  | 
175  |  |     std::pair<  | 
176  |  |         decltype(std::declval<const Hash&>()(std::declval<const PassedKey&>())),  | 
177  |  |         decltype(std::declval<const Eq&>()(std::declval<const ContainerKey&>(),  | 
178  |  |                                            std::declval<const PassedKey&>()))>*  | 
179  |  |     operator()(const PassedKey&, const Args&...) const;  | 
180  |  | };  | 
181  |  |  | 
182  |  | // --------------------------------------------------------------------------  | 
183  |  | template <class E, class Policy, class Hash, class Eq, class... Ts>  | 
184  |  | struct IsDecomposable : std::false_type {}; | 
185  |  |  | 
186  |  | template <class Policy, class Hash, class Eq, class... Ts>  | 
187  |  | struct IsDecomposable<  | 
188  |  |     phmap::void_t<decltype(  | 
189  |  |         Policy::apply(RequireUsableKey<typename Policy::key_type, Hash, Eq>(),  | 
190  |  |                       std::declval<Ts>()...))>,  | 
191  |  |     Policy, Hash, Eq, Ts...> : std::true_type {}; | 
192  |  |  | 
193  |  | // TODO(alkis): Switch to std::is_nothrow_swappable when gcc/clang supports it.  | 
194  |  | // --------------------------------------------------------------------------  | 
195  |  | template <class T>  | 
196  | 0  | constexpr bool IsNoThrowSwappable(std::true_type = {} /* is_swappable */) { | 
197  | 0  |     using std::swap;  | 
198  | 0  |     return noexcept(swap(std::declval<T&>(), std::declval<T&>()));  | 
199  | 0  | } Unexecuted instantiation: bool phmap::priv::IsNoThrowSwappable<phmap::Hash<unsigned int> >(std::__1::integral_constant<bool, true>) Unexecuted instantiation: bool phmap::priv::IsNoThrowSwappable<phmap::EqualTo<unsigned int> >(std::__1::integral_constant<bool, true>)  | 
200  |  |  | 
201  |  | template <class T>  | 
202  | 0  | constexpr bool IsNoThrowSwappable(std::false_type /* is_swappable */) { | 
203  | 0  |   return false;  | 
204  | 0  | }  | 
205  |  |  | 
206  |  | // --------------------------------------------------------------------------  | 
207  |  | template <typename T>  | 
208  | 15.6M  | uint32_t TrailingZeros(T x) { | 
209  | 15.6M  |     uint32_t res;  | 
210  | 15.6M  |     PHMAP_IF_CONSTEXPR(sizeof(T) == 8)  | 
211  |  |         res = base_internal::CountTrailingZerosNonZero64(static_cast<uint64_t>(x));  | 
212  |  |     else  | 
213  | 15.6M  |         res = base_internal::CountTrailingZerosNonZero32(static_cast<uint32_t>(x));  | 
214  | 15.6M  |     return res;  | 
215  | 15.6M  | } unsigned int phmap::priv::TrailingZeros<unsigned int>(unsigned int) Line  | Count  | Source  |  208  | 15.6M  | uint32_t TrailingZeros(T x) { |  209  | 15.6M  |     uint32_t res;  |  210  | 15.6M  |     PHMAP_IF_CONSTEXPR(sizeof(T) == 8)  |  211  |  |         res = base_internal::CountTrailingZerosNonZero64(static_cast<uint64_t>(x));  |  212  |  |     else  |  213  | 15.6M  |         res = base_internal::CountTrailingZerosNonZero32(static_cast<uint32_t>(x));  |  214  | 15.6M  |     return res;  |  215  | 15.6M  | }  |  
 Unexecuted instantiation: unsigned int phmap::priv::TrailingZeros<unsigned long>(unsigned long)  | 
216  |  |  | 
217  |  | // --------------------------------------------------------------------------  | 
218  |  | template <typename T>  | 
219  | 0  | uint32_t LeadingZeros(T x) { | 
220  | 0  |     uint32_t res;  | 
221  | 0  |     PHMAP_IF_CONSTEXPR(sizeof(T) == 8)  | 
222  | 0  |         res = base_internal::CountLeadingZeros64(static_cast<uint64_t>(x));  | 
223  | 0  |     else  | 
224  | 0  |         res = base_internal::CountLeadingZeros32(static_cast<uint32_t>(x));  | 
225  | 0  |     return res;  | 
226  | 0  | }  | 
227  |  |  | 
228  |  | // --------------------------------------------------------------------------  | 
229  |  | // An abstraction over a bitmask. It provides an easy way to iterate through the  | 
230  |  | // indexes of the set bits of a bitmask.  When Shift=0 (platforms with SSE),  | 
231  |  | // this is a true bitmask.  On non-SSE, platforms the arithematic used to  | 
232  |  | // emulate the SSE behavior works in bytes (Shift=3) and leaves each bytes as  | 
233  |  | // either 0x00 or 0x80.  | 
234  |  | //  | 
235  |  | // For example:  | 
236  |  | //   for (int i : BitMask<uint32_t, 16>(0x5)) -> yields 0, 2  | 
237  |  | //   for (int i : BitMask<uint64_t, 8, 3>(0x0000000080800000)) -> yields 2, 3  | 
238  |  | // --------------------------------------------------------------------------  | 
239  |  | template <class T, int SignificantBits, int Shift = 0>  | 
240  |  | class BitMask   | 
241  |  | { | 
242  |  |     static_assert(std::is_unsigned<T>::value, "");  | 
243  |  |     static_assert(Shift == 0 || Shift == 3, "");  | 
244  |  |  | 
245  |  | public:  | 
246  |  |     // These are useful for unit tests (gunit).  | 
247  |  |     using value_type = int;  | 
248  |  |     using iterator = BitMask;  | 
249  |  |     using const_iterator = BitMask;  | 
250  |  |  | 
251  | 29.1M  |     explicit BitMask(T mask) : mask_(mask) {} | 
252  |  |  | 
253  | 2.61M  |     BitMask& operator++() {    // ++iterator | 
254  | 2.61M  |         mask_ &= (mask_ - 1);  // clear the least significant bit set  | 
255  | 2.61M  |         return *this;  | 
256  | 2.61M  |     }  | 
257  |  |  | 
258  | 3.23M  |     explicit operator bool() const { return mask_ != 0; } | 
259  | 13.9M  |     uint32_t operator*() const { return LowestBitSet(); } | 
260  |  |  | 
261  | 15.4M  |     uint32_t LowestBitSet() const { | 
262  | 15.4M  |         return priv::TrailingZeros(mask_) >> Shift;  | 
263  | 15.4M  |     }  | 
264  |  |  | 
265  |  |     uint32_t HighestBitSet() const { | 
266  |  |         return (sizeof(T) * CHAR_BIT - priv::LeadingZeros(mask_) - 1) >> Shift;  | 
267  |  |     }  | 
268  |  |  | 
269  | 12.9M  |     BitMask begin() const { return *this; } | 
270  | 12.9M  |     BitMask end() const { return BitMask(0); } | 
271  |  |  | 
272  |  |     uint32_t TrailingZeros() const { | 
273  |  |         return priv::TrailingZeros(mask_) >> Shift;  | 
274  |  |     }  | 
275  |  |  | 
276  |  |     uint32_t LeadingZeros() const { | 
277  |  |         constexpr uint32_t total_significant_bits = SignificantBits << Shift;  | 
278  |  |         constexpr uint32_t extra_bits = sizeof(T) * 8 - total_significant_bits;  | 
279  |  |         return priv::LeadingZeros(mask_ << extra_bits) >> Shift;  | 
280  |  |     }  | 
281  |  |  | 
282  |  | private:  | 
283  |  |     friend bool operator==(const BitMask& a, const BitMask& b) { | 
284  |  |         return a.mask_ == b.mask_;  | 
285  |  |     }  | 
286  | 15.5M  |     friend bool operator!=(const BitMask& a, const BitMask& b) { | 
287  | 15.5M  |         return a.mask_ != b.mask_;  | 
288  | 15.5M  |     }  | 
289  |  |  | 
290  |  |     T mask_;  | 
291  |  | };  | 
292  |  |  | 
293  |  | // --------------------------------------------------------------------------  | 
294  |  | using ctrl_t = signed char;  | 
295  |  | using h2_t = uint8_t;  | 
296  |  |  | 
297  |  | // --------------------------------------------------------------------------  | 
298  |  | // The values here are selected for maximum performance. See the static asserts  | 
299  |  | // below for details.  | 
300  |  | // --------------------------------------------------------------------------  | 
301  |  | enum Ctrl : ctrl_t   | 
302  |  | { | 
303  |  |     kEmpty = -128,   // 0b10000000 or 0x80  | 
304  |  |     kDeleted = -2,   // 0b11111110 or 0xfe  | 
305  |  |     kSentinel = -1,  // 0b11111111 or 0xff  | 
306  |  | };  | 
307  |  |  | 
308  |  | static_assert(  | 
309  |  |     kEmpty & kDeleted & kSentinel & 0x80,  | 
310  |  |     "Special markers need to have the MSB to make checking for them efficient");  | 
311  |  | static_assert(kEmpty < kSentinel && kDeleted < kSentinel,  | 
312  |  |               "kEmpty and kDeleted must be smaller than kSentinel to make the "  | 
313  |  |               "SIMD test of IsEmptyOrDeleted() efficient");  | 
314  |  | static_assert(kSentinel == -1,  | 
315  |  |               "kSentinel must be -1 to elide loading it from memory into SIMD "  | 
316  |  |               "registers (pcmpeqd xmm, xmm)");  | 
317  |  | static_assert(kEmpty == -128,  | 
318  |  |               "kEmpty must be -128 to make the SIMD check for its "  | 
319  |  |               "existence efficient (psignb xmm, xmm)");  | 
320  |  | static_assert(~kEmpty & ~kDeleted & kSentinel & 0x7F,  | 
321  |  |               "kEmpty and kDeleted must share an unset bit that is not shared "  | 
322  |  |               "by kSentinel to make the scalar test for MatchEmptyOrDeleted() "  | 
323  |  |               "efficient");  | 
324  |  | static_assert(kDeleted == -2,  | 
325  |  |               "kDeleted must be -2 to make the implementation of "  | 
326  |  |               "ConvertSpecialToEmptyAndFullToDeleted efficient");  | 
327  |  |  | 
328  |  | // --------------------------------------------------------------------------  | 
329  |  | // A single block of empty control bytes for tables without any slots allocated.  | 
330  |  | // This enables removing a branch in the hot path of find().  | 
331  |  | // --------------------------------------------------------------------------  | 
332  |  | template <class std_alloc_t>  | 
333  | 3.07k  | inline ctrl_t* EmptyGroup() { | 
334  | 3.07k  |   PHMAP_IF_CONSTEXPR (std_alloc_t::value) { | 
335  | 3.07k  |       alignas(16) static constexpr ctrl_t empty_group[] = { | 
336  | 3.07k  |           kSentinel, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty,  | 
337  | 3.07k  |           kEmpty,    kEmpty, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty};  | 
338  |  |  | 
339  | 3.07k  |       return const_cast<ctrl_t*>(empty_group);  | 
340  |  |   } else { | 
341  |  |        return nullptr;  | 
342  |  |   }  | 
343  | 3.07k  | } signed char* phmap::priv::EmptyGroup<std::__1::is_same<std::__1::allocator<std::__1::pair<unsigned int const, int> >, std::__1::allocator<std::__1::pair<unsigned int const, int> > > >() Line  | Count  | Source  |  333  | 2.47k  | inline ctrl_t* EmptyGroup() { |  334  | 2.47k  |   PHMAP_IF_CONSTEXPR (std_alloc_t::value) { |  335  | 2.47k  |       alignas(16) static constexpr ctrl_t empty_group[] = { |  336  | 2.47k  |           kSentinel, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty,  |  337  | 2.47k  |           kEmpty,    kEmpty, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty};  |  338  |  |  |  339  | 2.47k  |       return const_cast<ctrl_t*>(empty_group);  |  340  |  |   } else { |  341  |  |        return nullptr;  |  342  |  |   }  |  343  | 2.47k  | }  |  
 signed char* phmap::priv::EmptyGroup<std::__1::is_same<std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > >() Line  | Count  | Source  |  333  | 595  | inline ctrl_t* EmptyGroup() { |  334  | 595  |   PHMAP_IF_CONSTEXPR (std_alloc_t::value) { |  335  | 595  |       alignas(16) static constexpr ctrl_t empty_group[] = { |  336  | 595  |           kSentinel, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty,  |  337  | 595  |           kEmpty,    kEmpty, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty, kEmpty};  |  338  |  |  |  339  | 595  |       return const_cast<ctrl_t*>(empty_group);  |  340  |  |   } else { |  341  |  |        return nullptr;  |  342  |  |   }  |  343  | 595  | }  |  
  | 
344  |  |  | 
345  |  | // --------------------------------------------------------------------------  | 
346  | 0  | inline size_t HashSeed(const ctrl_t* ctrl) { | 
347  | 0  |   // The low bits of the pointer have little or no entropy because of  | 
348  | 0  |   // alignment. We shift the pointer to try to use higher entropy bits. A  | 
349  | 0  |   // good number seems to be 12 bits, because that aligns with page size.  | 
350  | 0  |   return reinterpret_cast<uintptr_t>(ctrl) >> 12;  | 
351  | 0  | }  | 
352  |  |  | 
353  |  | #ifdef PHMAP_NON_DETERMINISTIC  | 
354  |  |  | 
355  |  | inline size_t H1(size_t hashval, const ctrl_t* ctrl) { | 
356  |  |     // use ctrl_ pointer to add entropy to ensure  | 
357  |  |     // non-deterministic iteration order.  | 
358  |  |     return (hashval >> 7) ^ HashSeed(ctrl);  | 
359  |  | }  | 
360  |  |  | 
361  |  | #else  | 
362  |  |  | 
363  | 13.3M  | inline size_t H1(size_t hashval, const ctrl_t* ) { | 
364  | 13.3M  |     return (hashval >> 7);  | 
365  | 13.3M  | }  | 
366  |  |  | 
367  |  | #endif  | 
368  |  |  | 
369  |  |  | 
370  | 14.4M  | inline ctrl_t H2(size_t hashval)       { return (ctrl_t)(hashval & 0x7F); } | 
371  |  |  | 
372  | 538k  | inline bool IsEmpty(ctrl_t c)          { return c == kEmpty; } | 
373  | 2.64M  | inline bool IsFull(ctrl_t c)           { return c >= static_cast<ctrl_t>(0); } | 
374  | 3.10k  | inline bool IsDeleted(ctrl_t c)        { return c == kDeleted; } | 
375  | 737k  | inline bool IsEmptyOrDeleted(ctrl_t c) { return c < kSentinel; } | 
376  |  |  | 
377  |  | #if PHMAP_HAVE_SSE2  | 
378  |  |  | 
379  |  | #ifdef _MSC_VER  | 
380  |  |     #pragma warning(push)    | 
381  |  |     #pragma warning(disable : 4365) // conversion from 'int' to 'T', signed/unsigned mismatch  | 
382  |  | #endif  | 
383  |  |  | 
384  |  | // --------------------------------------------------------------------------  | 
385  |  | // https://github.com/abseil/abseil-cpp/issues/209  | 
386  |  | // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87853  | 
387  |  | // _mm_cmpgt_epi8 is broken under GCC with -funsigned-char  | 
388  |  | // Work around this by using the portable implementation of Group  | 
389  |  | // when using -funsigned-char under GCC.  | 
390  |  | // --------------------------------------------------------------------------  | 
391  | 1.82M  | inline __m128i _mm_cmpgt_epi8_fixed(__m128i a, __m128i b) { | 
392  |  | #if defined(__GNUC__) && !defined(__clang__)  | 
393  |  |   #pragma GCC diagnostic push  | 
394  |  |   #pragma GCC diagnostic ignored "-Woverflow"  | 
395  |  |  | 
396  |  |   if (std::is_unsigned<char>::value) { | 
397  |  |     const __m128i mask = _mm_set1_epi8(static_cast<char>(0x80));  | 
398  |  |     const __m128i diff = _mm_subs_epi8(b, a);  | 
399  |  |     return _mm_cmpeq_epi8(_mm_and_si128(diff, mask), mask);  | 
400  |  |   }  | 
401  |  |  | 
402  |  |   #pragma GCC diagnostic pop  | 
403  |  | #endif  | 
404  | 1.82M  |   return _mm_cmpgt_epi8(a, b);  | 
405  | 1.82M  | }  | 
406  |  |  | 
407  |  | // --------------------------------------------------------------------------  | 
408  |  | // --------------------------------------------------------------------------  | 
409  |  | struct GroupSse2Impl   | 
410  |  | { | 
411  |  |     enum { kWidth = 16 };  // the number of slots per group | 
412  |  |  | 
413  | 14.7M  |     explicit GroupSse2Impl(const ctrl_t* pos) { | 
414  | 14.7M  |         ctrl = _mm_loadu_si128(reinterpret_cast<const __m128i*>(pos));  | 
415  | 14.7M  |     }  | 
416  |  |  | 
417  |  |     // Returns a bitmask representing the positions of slots that match hash.  | 
418  |  |     // ----------------------------------------------------------------------  | 
419  | 14.5M  |     BitMask<uint32_t, kWidth> Match(h2_t hash) const { | 
420  | 14.5M  |         auto match = _mm_set1_epi8((char)hash);  | 
421  | 14.5M  |         return BitMask<uint32_t, kWidth>(  | 
422  | 14.5M  |             static_cast<uint32_t>(_mm_movemask_epi8(_mm_cmpeq_epi8(match, ctrl))));  | 
423  | 14.5M  |     }  | 
424  |  |  | 
425  |  |     // Returns a bitmask representing the positions of empty slots.  | 
426  |  |     // ------------------------------------------------------------  | 
427  | 1.62M  |     BitMask<uint32_t, kWidth> MatchEmpty() const { | 
428  |  | #if PHMAP_HAVE_SSSE3  | 
429  |  |         // This only works because kEmpty is -128.  | 
430  |  |         return BitMask<uint32_t, kWidth>(  | 
431  |  |             static_cast<uint32_t>(_mm_movemask_epi8(_mm_sign_epi8(ctrl, ctrl))));  | 
432  |  | #else  | 
433  | 1.62M  |         return Match(static_cast<h2_t>(kEmpty));  | 
434  | 1.62M  | #endif  | 
435  | 1.62M  |     }  | 
436  |  |  | 
437  |  |     // Returns a bitmask representing the positions of empty or deleted slots.  | 
438  |  |     // -----------------------------------------------------------------------  | 
439  | 1.61M  |     BitMask<uint32_t, kWidth> MatchEmptyOrDeleted() const { | 
440  | 1.61M  |         auto special = _mm_set1_epi8(static_cast<char>(kSentinel));  | 
441  | 1.61M  |         return BitMask<uint32_t, kWidth>(  | 
442  | 1.61M  |             static_cast<uint32_t>(_mm_movemask_epi8(_mm_cmpgt_epi8_fixed(special, ctrl))));  | 
443  | 1.61M  |     }  | 
444  |  |  | 
445  |  |     // Returns the number of trailing empty or deleted elements in the group.  | 
446  |  |     // ----------------------------------------------------------------------  | 
447  | 214k  |     uint32_t CountLeadingEmptyOrDeleted() const { | 
448  | 214k  |         auto special = _mm_set1_epi8(static_cast<char>(kSentinel));  | 
449  | 214k  |         return TrailingZeros(  | 
450  | 214k  |             static_cast<uint32_t>(_mm_movemask_epi8(_mm_cmpgt_epi8_fixed(special, ctrl)) + 1));  | 
451  | 214k  |     }  | 
452  |  |  | 
453  |  |     // ----------------------------------------------------------------------  | 
454  | 0  |     void ConvertSpecialToEmptyAndFullToDeleted(ctrl_t* dst) const { | 
455  | 0  |         auto msbs = _mm_set1_epi8(static_cast<char>(-128));  | 
456  | 0  |         auto x126 = _mm_set1_epi8(126);  | 
457  |  | #if PHMAP_HAVE_SSSE3  | 
458  |  |         auto res = _mm_or_si128(_mm_shuffle_epi8(x126, ctrl), msbs);  | 
459  |  | #else  | 
460  | 0  |         auto zero = _mm_setzero_si128();  | 
461  | 0  |         auto special_mask = _mm_cmpgt_epi8_fixed(zero, ctrl);  | 
462  | 0  |         auto res = _mm_or_si128(msbs, _mm_andnot_si128(special_mask, x126));  | 
463  | 0  | #endif  | 
464  | 0  |         _mm_storeu_si128(reinterpret_cast<__m128i*>(dst), res);  | 
465  | 0  |     }  | 
466  |  |  | 
467  |  |     __m128i ctrl;  | 
468  |  | };  | 
469  |  |  | 
470  |  | #ifdef _MSC_VER  | 
471  |  |      #pragma warning(pop)    | 
472  |  | #endif  | 
473  |  |  | 
474  |  | #endif  // PHMAP_HAVE_SSE2  | 
475  |  |  | 
476  |  | // --------------------------------------------------------------------------  | 
477  |  | // --------------------------------------------------------------------------  | 
478  |  | struct GroupPortableImpl   | 
479  |  | { | 
480  |  |     enum { kWidth = 8 }; | 
481  |  |  | 
482  |  |     explicit GroupPortableImpl(const ctrl_t* pos)  | 
483  | 0  |         : ctrl(little_endian::Load64(pos)) {} | 
484  |  |  | 
485  | 0  |     BitMask<uint64_t, kWidth, 3> Match(h2_t hash) const { | 
486  | 0  |         // For the technique, see:  | 
487  | 0  |         // http://graphics.stanford.edu/~seander/bithacks.html##ValueInWord  | 
488  | 0  |         // (Determine if a word has a byte equal to n).  | 
489  | 0  |         //  | 
490  | 0  |         // Caveat: there are false positives but:  | 
491  | 0  |         // - they only occur if there is a real match  | 
492  | 0  |         // - they never occur on kEmpty, kDeleted, kSentinel  | 
493  | 0  |         // - they will be handled gracefully by subsequent checks in code  | 
494  | 0  |         //  | 
495  | 0  |         // Example:  | 
496  | 0  |         //   v = 0x1716151413121110  | 
497  | 0  |         //   hash = 0x12  | 
498  | 0  |         //   retval = (v - lsbs) & ~v & msbs = 0x0000000080800000  | 
499  | 0  |         constexpr uint64_t msbs = 0x8080808080808080ULL;  | 
500  | 0  |         constexpr uint64_t lsbs = 0x0101010101010101ULL;  | 
501  | 0  |         auto x = ctrl ^ (lsbs * hash);  | 
502  | 0  |         return BitMask<uint64_t, kWidth, 3>((x - lsbs) & ~x & msbs);  | 
503  | 0  |     }  | 
504  |  |  | 
505  | 0  |     BitMask<uint64_t, kWidth, 3> MatchEmpty() const {          // bit 1 of each byte is 0 for empty (but not for deleted) | 
506  | 0  |         constexpr uint64_t msbs = 0x8080808080808080ULL;  | 
507  | 0  |         return BitMask<uint64_t, kWidth, 3>((ctrl & (~ctrl << 6)) & msbs);  | 
508  | 0  |     }  | 
509  |  |  | 
510  | 0  |     BitMask<uint64_t, kWidth, 3> MatchEmptyOrDeleted() const { // lsb of each byte is 0 for empty or deleted | 
511  | 0  |         constexpr uint64_t msbs = 0x8080808080808080ULL;  | 
512  | 0  |         return BitMask<uint64_t, kWidth, 3>((ctrl & (~ctrl << 7)) & msbs);  | 
513  | 0  |     }  | 
514  |  |  | 
515  | 0  |     uint32_t CountLeadingEmptyOrDeleted() const { | 
516  | 0  |         constexpr uint64_t gaps = 0x00FEFEFEFEFEFEFEULL;  | 
517  | 0  |         return (uint32_t)((TrailingZeros(((~ctrl & (ctrl >> 7)) | gaps) + 1) + 7) >> 3);  | 
518  | 0  |     }  | 
519  |  |  | 
520  | 0  |     void ConvertSpecialToEmptyAndFullToDeleted(ctrl_t* dst) const { | 
521  | 0  |         constexpr uint64_t msbs = 0x8080808080808080ULL;  | 
522  | 0  |         constexpr uint64_t lsbs = 0x0101010101010101ULL;  | 
523  | 0  |         auto x = ctrl & msbs;  | 
524  | 0  |         auto res = (~x + (x >> 7)) & ~lsbs;  | 
525  | 0  |         little_endian::Store64(dst, res);  | 
526  | 0  |     }  | 
527  |  |  | 
528  |  |     uint64_t ctrl;  | 
529  |  | };  | 
530  |  |  | 
531  |  | #if PHMAP_HAVE_SSE2    | 
532  |  |     using Group = GroupSse2Impl;  | 
533  |  | #else  | 
534  |  |     using Group = GroupPortableImpl;  | 
535  |  | #endif  | 
536  |  |  | 
537  |  | // The number of cloned control bytes that we copy from the beginning to the  | 
538  |  | // end of the control bytes array.  | 
539  |  | // -------------------------------------------------------------------------  | 
540  | 0  | constexpr size_t NumClonedBytes() { return Group::kWidth - 1; } | 
541  |  |  | 
542  |  | template <class Policy, class Hash, class Eq, class Alloc>  | 
543  |  | class raw_hash_set;  | 
544  |  |  | 
545  | 15.3k  | inline bool IsValidCapacity(size_t n) { return ((n + 1) & n) == 0 && n > 0; } | 
546  |  |  | 
547  |  | // --------------------------------------------------------------------------  | 
548  |  | // PRECONDITION:  | 
549  |  | //   IsValidCapacity(capacity)  | 
550  |  | //   ctrl[capacity] == kSentinel  | 
551  |  | //   ctrl[i] != kSentinel for all i < capacity  | 
552  |  | // Applies mapping for every byte in ctrl:  | 
553  |  | //   DELETED -> EMPTY  | 
554  |  | //   EMPTY -> EMPTY  | 
555  |  | //   FULL -> DELETED  | 
556  |  | // --------------------------------------------------------------------------  | 
557  |  | inline void ConvertDeletedToEmptyAndFullToDeleted(  | 
558  |  |     ctrl_t* PHMAP_RESTRICT ctrl, size_t capacity)   | 
559  | 0  | { | 
560  | 0  |     assert(ctrl[capacity] == kSentinel);  | 
561  | 0  |     assert(IsValidCapacity(capacity));  | 
562  | 0  |     for (ctrl_t* pos = ctrl; pos != ctrl + capacity + 1; pos += Group::kWidth) { | 
563  | 0  |         Group{pos}.ConvertSpecialToEmptyAndFullToDeleted(pos); | 
564  | 0  |     }  | 
565  |  |     // Copy the cloned ctrl bytes.  | 
566  | 0  |     std::memcpy(ctrl + capacity + 1, ctrl, Group::kWidth);  | 
567  | 0  |     ctrl[capacity] = kSentinel;  | 
568  | 0  | }  | 
569  |  |  | 
570  |  | // --------------------------------------------------------------------------  | 
571  |  | // Rounds up the capacity to the next power of 2 minus 1, with a minimum of 1.  | 
572  |  | // --------------------------------------------------------------------------  | 
573  |  | inline size_t NormalizeCapacity(size_t n)   | 
574  | 0  | { | 
575  | 0  |     return n ? ~size_t{} >> LeadingZeros(n) : 1; | 
576  | 0  | }  | 
577  |  |  | 
578  |  | // --------------------------------------------------------------------------  | 
579  |  | // We use 7/8th as maximum load factor.  | 
580  |  | // For 16-wide groups, that gives an average of two empty slots per group.  | 
581  |  | // --------------------------------------------------------------------------  | 
582  |  | inline size_t CapacityToGrowth(size_t capacity)   | 
583  | 5.78k  | { | 
584  | 5.78k  |     assert(IsValidCapacity(capacity));  | 
585  |  |     // `capacity*7/8`  | 
586  | 5.78k  |     PHMAP_IF_CONSTEXPR (Group::kWidth == 8) { | 
587  | 5.78k  |         if (capacity == 7) { | 
588  |  |             // x-x/8 does not work when x==7.  | 
589  |  |             return 6;  | 
590  |  |         }  | 
591  |  |     }  | 
592  | 5.78k  |     return capacity - capacity / 8;  | 
593  | 5.78k  | }  | 
594  |  |  | 
595  |  | // --------------------------------------------------------------------------  | 
596  |  | // From desired "growth" to a lowerbound of the necessary capacity.  | 
597  |  | // Might not be a valid one and required NormalizeCapacity().  | 
598  |  | // --------------------------------------------------------------------------  | 
599  |  | inline size_t GrowthToLowerboundCapacity(size_t growth)   | 
600  | 0  | { | 
601  | 0  |     // `growth*8/7`  | 
602  | 0  |     PHMAP_IF_CONSTEXPR (Group::kWidth == 8) { | 
603  | 0  |         if (growth == 7) { | 
604  | 0  |             // x+(x-1)/7 does not work when x==7.  | 
605  | 0  |             return 8;  | 
606  | 0  |         }  | 
607  | 0  |     }  | 
608  | 0  |     return growth + static_cast<size_t>((static_cast<int64_t>(growth) - 1) / 7);  | 
609  | 0  | }  | 
610  |  |  | 
611  |  | namespace hashtable_debug_internal { | 
612  |  |  | 
613  |  | // If it is a map, call get<0>().  | 
614  |  | using std::get;  | 
615  |  | template <typename T, typename = typename T::mapped_type>  | 
616  |  | auto GetKey(const typename T::value_type& pair, int) -> decltype(get<0>(pair)) { | 
617  |  |     return get<0>(pair);  | 
618  |  | }  | 
619  |  |  | 
620  |  | // If it is not a map, return the value directly.  | 
621  |  | template <typename T>  | 
622  |  | const typename T::key_type& GetKey(const typename T::key_type& key, char) { | 
623  |  |     return key;  | 
624  |  | }  | 
625  |  |  | 
626  |  | // --------------------------------------------------------------------------  | 
627  |  | // Containers should specialize this to provide debug information for that  | 
628  |  | // container.  | 
629  |  | // --------------------------------------------------------------------------  | 
630  |  | template <class Container, typename Enabler = void>  | 
631  |  | struct HashtableDebugAccess  | 
632  |  | { | 
633  |  |     // Returns the number of probes required to find `key` in `c`.  The "number of  | 
634  |  |     // probes" is a concept that can vary by container.  Implementations should  | 
635  |  |     // return 0 when `key` was found in the minimum number of operations and  | 
636  |  |     // should increment the result for each non-trivial operation required to find  | 
637  |  |     // `key`.  | 
638  |  |     //  | 
639  |  |     // The default implementation uses the bucket api from the standard and thus  | 
640  |  |     // works for `std::unordered_*` containers.  | 
641  |  |     // --------------------------------------------------------------------------  | 
642  |  |     static size_t GetNumProbes(const Container& c,  | 
643  |  |                                const typename Container::key_type& key) { | 
644  |  |         if (!c.bucket_count()) return {}; | 
645  |  |         size_t num_probes = 0;  | 
646  |  |         size_t bucket = c.bucket(key);  | 
647  |  |         for (auto it = c.begin(bucket), e = c.end(bucket);; ++it, ++num_probes) { | 
648  |  |             if (it == e) return num_probes;  | 
649  |  |             if (c.key_eq()(key, GetKey<Container>(*it, 0))) return num_probes;  | 
650  |  |         }  | 
651  |  |     }  | 
652  |  | };  | 
653  |  |  | 
654  |  | }  // namespace hashtable_debug_internal  | 
655  |  |  | 
656  |  | // ----------------------------------------------------------------------------  | 
657  |  | //                    I N F O Z   S T U B S  | 
658  |  | // ----------------------------------------------------------------------------  | 
659  |  | struct HashtablezInfo   | 
660  |  | { | 
661  | 0  |     void PrepareForSampling() {} | 
662  |  | };  | 
663  |  |  | 
664  | 0  | inline void RecordRehashSlow(HashtablezInfo*, size_t ) {} | 
665  |  |  | 
666  | 0  | static inline void RecordInsertSlow(HashtablezInfo* , size_t, size_t ) {} | 
667  |  |  | 
668  | 0  | static inline void RecordEraseSlow(HashtablezInfo*) {} | 
669  |  |  | 
670  | 0  | static inline HashtablezInfo* SampleSlow(int64_t*) { return nullptr; } | 
671  | 0  | static inline void UnsampleSlow(HashtablezInfo* ) {} | 
672  |  |  | 
673  |  | class HashtablezInfoHandle   | 
674  |  | { | 
675  |  | public:  | 
676  | 3.23k  |     inline void RecordStorageChanged(size_t , size_t ) {} | 
677  | 0  |     inline void RecordRehash(size_t ) {} | 
678  | 538k  |     inline void RecordInsert(size_t , size_t ) {} | 
679  | 0  |     inline void RecordErase() {} | 
680  |  |     friend inline void swap(HashtablezInfoHandle& ,  | 
681  | 595  |                             HashtablezInfoHandle& ) noexcept {} | 
682  |  | };  | 
683  |  |  | 
684  | 691  | static inline HashtablezInfoHandle Sample() { return HashtablezInfoHandle(); } | 
685  |  |  | 
686  |  | class HashtablezSampler   | 
687  |  | { | 
688  |  | public:  | 
689  |  |     // Returns a global Sampler.  | 
690  | 0  |     static HashtablezSampler& Global() {  static HashtablezSampler hzs; return hzs; } | 
691  | 0  |     HashtablezInfo* Register() {  static HashtablezInfo info; return &info; } | 
692  | 0  |     void Unregister(HashtablezInfo* ) {} | 
693  |  |  | 
694  |  |     using DisposeCallback = void (*)(const HashtablezInfo&);  | 
695  | 0  |     DisposeCallback SetDisposeCallback(DisposeCallback ) { return nullptr; } | 
696  | 0  |     int64_t Iterate(const std::function<void(const HashtablezInfo& stack)>& ) { return 0; } | 
697  |  | };  | 
698  |  |  | 
699  | 0  | static inline void SetHashtablezEnabled(bool ) {} | 
700  | 0  | static inline void SetHashtablezSampleParameter(int32_t ) {} | 
701  | 0  | static inline void SetHashtablezMaxSamples(int32_t ) {} | 
702  |  |  | 
703  |  |  | 
704  |  | namespace memory_internal { | 
705  |  |  | 
706  |  | // Constructs T into uninitialized storage pointed by `ptr` using the args  | 
707  |  | // specified in the tuple.  | 
708  |  | // ----------------------------------------------------------------------------  | 
709  |  | template <class Alloc, class T, class Tuple, size_t... I>  | 
710  |  | void ConstructFromTupleImpl(Alloc* alloc, T* ptr, Tuple&& t,  | 
711  |  |                             phmap::index_sequence<I...>) { | 
712  |  |     phmap::allocator_traits<Alloc>::construct(  | 
713  |  |         *alloc, ptr, std::get<I>(std::forward<Tuple>(t))...);  | 
714  |  | }  | 
715  |  |  | 
716  |  | template <class T, class F>  | 
717  |  | struct WithConstructedImplF { | 
718  |  |     template <class... Args>  | 
719  |  |     decltype(std::declval<F>()(std::declval<T>())) operator()(  | 
720  |  |         Args&&... args) const { | 
721  |  |         return std::forward<F>(f)(T(std::forward<Args>(args)...));  | 
722  |  |     }  | 
723  |  |     F&& f;  | 
724  |  | };  | 
725  |  |  | 
726  |  | template <class T, class Tuple, size_t... Is, class F>  | 
727  |  | decltype(std::declval<F>()(std::declval<T>())) WithConstructedImpl(  | 
728  |  |     Tuple&& t, phmap::index_sequence<Is...>, F&& f) { | 
729  |  |     return WithConstructedImplF<T, F>{std::forward<F>(f)}( | 
730  |  |         std::get<Is>(std::forward<Tuple>(t))...);  | 
731  |  | }  | 
732  |  |  | 
733  |  | template <class T, size_t... Is>  | 
734  |  | auto TupleRefImpl(T&& t, phmap::index_sequence<Is...>)  | 
735  |  |     -> decltype(std::forward_as_tuple(std::get<Is>(std::forward<T>(t))...)) { | 
736  |  |   return std::forward_as_tuple(std::get<Is>(std::forward<T>(t))...);  | 
737  |  | }  | 
738  |  |  | 
739  |  | // Returns a tuple of references to the elements of the input tuple. T must be a  | 
740  |  | // tuple.  | 
741  |  | // ----------------------------------------------------------------------------  | 
742  |  | template <class T>  | 
743  |  | auto TupleRef(T&& t) -> decltype(  | 
744  |  |     TupleRefImpl(std::forward<T>(t),  | 
745  |  |                  phmap::make_index_sequence<  | 
746  |  |                      std::tuple_size<typename std::decay<T>::type>::value>())) { | 
747  |  |   return TupleRefImpl(  | 
748  |  |       std::forward<T>(t),  | 
749  |  |       phmap::make_index_sequence<  | 
750  |  |           std::tuple_size<typename std::decay<T>::type>::value>());  | 
751  |  | }  | 
752  |  |  | 
753  |  | template <class F, class K, class V>  | 
754  |  | decltype(std::declval<F>()(std::declval<const K&>(), std::piecewise_construct,  | 
755  |  |                            std::declval<std::tuple<K>>(), std::declval<V>()))  | 
756  | 26.2M  | DecomposePairImpl(F&& f, std::pair<std::tuple<K>, V> p) { | 
757  | 26.2M  |     const auto& key = std::get<0>(p.first);  | 
758  | 26.2M  |     return std::forward<F>(f)(key, std::piecewise_construct, std::move(p.first),  | 
759  | 26.2M  |                               std::move(p.second));  | 
760  | 26.2M  | } _ZN5phmap4priv15memory_internal17DecomposePairImplINS0_12raw_hash_setINS0_17FlatHashMapPolicyIjiEENS_4HashIjEENS_7EqualToIjEENSt3__19allocatorINSA_4pairIKjiEEEEE19EmplaceDecomposableEOSD_NSA_5tupleIJOiEEEEEDTclclsr3stdE7declvalIT_EEclsr3stdE7declvalIRKT0_EEL_ZNSA_19piecewise_constructEEclsr3stdE7declvalINSJ_IJSN_EEEEEclsr3stdE7declvalIT1_EEEEOSM_NSC_ISQ_SR_EE Line  | Count  | Source  |  756  | 11.3M  | DecomposePairImpl(F&& f, std::pair<std::tuple<K>, V> p) { |  757  | 11.3M  |     const auto& key = std::get<0>(p.first);  |  758  | 11.3M  |     return std::forward<F>(f)(key, std::piecewise_construct, std::move(p.first),  |  759  | 11.3M  |                               std::move(p.second));  |  760  | 11.3M  | }  |  
 _ZN5phmap4priv15memory_internal17DecomposePairImplINS0_12raw_hash_setINS0_17FlatHashMapPolicyIjiEENS_4HashIjEENS_7EqualToIjEENSt3__19allocatorINSA_4pairIKjiEEEEE12EqualElementIjEERSD_NSA_5tupleIJRKiEEEEEDTclclsr3stdE7declvalIT_EEclsr3stdE7declvalIRKT0_EEL_ZNSA_19piecewise_constructEEclsr3stdE7declvalINSK_IJSP_EEEEEclsr3stdE7declvalIT1_EEEEOSO_NSC_ISS_ST_EE Line  | Count  | Source  |  756  | 13.4M  | DecomposePairImpl(F&& f, std::pair<std::tuple<K>, V> p) { |  757  | 13.4M  |     const auto& key = std::get<0>(p.first);  |  758  | 13.4M  |     return std::forward<F>(f)(key, std::piecewise_construct, std::move(p.first),  |  759  | 13.4M  |                               std::move(p.second));  |  760  | 13.4M  | }  |  
 _ZN5phmap4priv15memory_internal17DecomposePairImplINS0_12raw_hash_setINS0_17FlatHashMapPolicyIjiEENS_4HashIjEENS_7EqualToIjEENSt3__19allocatorINSA_4pairIKjiEEEEE11HashElementERSD_NSA_5tupleIJRKiEEEEEDTclclsr3stdE7declvalIT_EEclsr3stdE7declvalIRKT0_EEL_ZNSA_19piecewise_constructEEclsr3stdE7declvalINSJ_IJSO_EEEEEclsr3stdE7declvalIT1_EEEEOSN_NSC_ISR_SS_EE Line  | Count  | Source  |  756  | 1.50M  | DecomposePairImpl(F&& f, std::pair<std::tuple<K>, V> p) { |  757  | 1.50M  |     const auto& key = std::get<0>(p.first);  |  758  | 1.50M  |     return std::forward<F>(f)(key, std::piecewise_construct, std::move(p.first),  |  759  | 1.50M  |                               std::move(p.second));  |  760  | 1.50M  | }  |  
  | 
761  |  |  | 
762  |  | }  // namespace memory_internal  | 
763  |  |  | 
764  |  |  | 
765  |  | // ----------------------------------------------------------------------------  | 
766  |  | //                     R A W _ H A S H _ S E T  | 
767  |  | // ----------------------------------------------------------------------------  | 
768  |  | // An open-addressing  | 
769  |  | // hashtable with quadratic probing.  | 
770  |  | //  | 
771  |  | // This is a low level hashtable on top of which different interfaces can be  | 
772  |  | // implemented, like flat_hash_set, node_hash_set, string_hash_set, etc.  | 
773  |  | //  | 
774  |  | // The table interface is similar to that of std::unordered_set. Notable  | 
775  |  | // differences are that most member functions support heterogeneous keys when  | 
776  |  | // BOTH the hash and eq functions are marked as transparent. They do so by  | 
777  |  | // providing a typedef called `is_transparent`.  | 
778  |  | //  | 
779  |  | // When heterogeneous lookup is enabled, functions that take key_type act as if  | 
780  |  | // they have an overload set like:  | 
781  |  | //  | 
782  |  | //   iterator find(const key_type& key);  | 
783  |  | //   template <class K>  | 
784  |  | //   iterator find(const K& key);  | 
785  |  | //  | 
786  |  | //   size_type erase(const key_type& key);  | 
787  |  | //   template <class K>  | 
788  |  | //   size_type erase(const K& key);  | 
789  |  | //  | 
790  |  | //   std::pair<iterator, iterator> equal_range(const key_type& key);  | 
791  |  | //   template <class K>  | 
792  |  | //   std::pair<iterator, iterator> equal_range(const K& key);  | 
793  |  | //  | 
794  |  | // When heterogeneous lookup is disabled, only the explicit `key_type` overloads  | 
795  |  | // exist.  | 
796  |  | //  | 
797  |  | // find() also supports passing the hash explicitly:  | 
798  |  | //  | 
799  |  | //   iterator find(const key_type& key, size_t hash);  | 
800  |  | //   template <class U>  | 
801  |  | //   iterator find(const U& key, size_t hash);  | 
802  |  | //  | 
803  |  | // In addition the pointer to element and iterator stability guarantees are  | 
804  |  | // weaker: all iterators and pointers are invalidated after a new element is  | 
805  |  | // inserted.  | 
806  |  | //  | 
807  |  | // IMPLEMENTATION DETAILS  | 
808  |  | //  | 
809  |  | // The table stores elements inline in a slot array. In addition to the slot  | 
810  |  | // array the table maintains some control state per slot. The extra state is one  | 
811  |  | // byte per slot and stores empty or deleted marks, or alternatively 7 bits from  | 
812  |  | // the hash of an occupied slot. The table is split into logical groups of  | 
813  |  | // slots, like so:  | 
814  |  | //  | 
815  |  | //      Group 1         Group 2        Group 3  | 
816  |  | // +---------------+---------------+---------------+  | 
817  |  | // | | | | | | | | | | | | | | | | | | | | | | | | |  | 
818  |  | // +---------------+---------------+---------------+  | 
819  |  | //  | 
820  |  | // On lookup the hash is split into two parts:  | 
821  |  | // - H2: 7 bits (those stored in the control bytes)  | 
822  |  | // - H1: the rest of the bits  | 
823  |  | // The groups are probed using H1. For each group the slots are matched to H2 in  | 
824  |  | // parallel. Because H2 is 7 bits (128 states) and the number of slots per group  | 
825  |  | // is low (8 or 16) in almost all cases a match in H2 is also a lookup hit.  | 
826  |  | //  | 
827  |  | // On insert, once the right group is found (as in lookup), its slots are  | 
828  |  | // filled in order.  | 
829  |  | //  | 
830  |  | // On erase a slot is cleared. In case the group did not have any empty slots  | 
831  |  | // before the erase, the erased slot is marked as deleted.  | 
832  |  | //  | 
833  |  | // Groups without empty slots (but maybe with deleted slots) extend the probe  | 
834  |  | // sequence. The probing algorithm is quadratic. Given N the number of groups,  | 
835  |  | // the probing function for the i'th probe is:  | 
836  |  | //  | 
837  |  | //   P(0) = H1 % N  | 
838  |  | //  | 
839  |  | //   P(i) = (P(i - 1) + i) % N  | 
840  |  | //  | 
841  |  | // This probing function guarantees that after N probes, all the groups of the  | 
842  |  | // table will be probed exactly once.  | 
843  |  | // ----------------------------------------------------------------------------  | 
844  |  | template <class Policy, class Hash, class Eq, class Alloc>  | 
845  |  | class raw_hash_set   | 
846  |  | { | 
847  |  |     using PolicyTraits = hash_policy_traits<Policy>;  | 
848  |  |     using KeyArgImpl =  | 
849  |  |         KeyArg<IsTransparent<Eq>::value && IsTransparent<Hash>::value>;  | 
850  |  |  | 
851  |  | public:  | 
852  |  |     using init_type = typename PolicyTraits::init_type;  | 
853  |  |     using key_type = typename PolicyTraits::key_type;  | 
854  |  |     // TODO(sbenza): Hide slot_type as it is an implementation detail. Needs user  | 
855  |  |     // code fixes!  | 
856  |  |     using slot_type = typename PolicyTraits::slot_type;  | 
857  |  |     using allocator_type = Alloc;  | 
858  |  |     using size_type = size_t;  | 
859  |  |     using difference_type = ptrdiff_t;  | 
860  |  |     using hasher = Hash;  | 
861  |  |     using key_equal = Eq;  | 
862  |  |     using policy_type = Policy;  | 
863  |  |     using value_type = typename PolicyTraits::value_type;  | 
864  |  |     using reference = value_type&;  | 
865  |  |     using const_reference = const value_type&;  | 
866  |  |     using pointer = typename phmap::allocator_traits<  | 
867  |  |         allocator_type>::template rebind_traits<value_type>::pointer;  | 
868  |  |     using const_pointer = typename phmap::allocator_traits<  | 
869  |  |         allocator_type>::template rebind_traits<value_type>::const_pointer;  | 
870  |  |  | 
871  |  |     // Alias used for heterogeneous lookup functions.  | 
872  |  |     // `key_arg<K>` evaluates to `K` when the functors are transparent and to  | 
873  |  |     // `key_type` otherwise. It permits template argument deduction on `K` for the  | 
874  |  |     // transparent case.  | 
875  |  |     template <class K>  | 
876  |  |     using key_arg = typename KeyArgImpl::template type<K, key_type>;  | 
877  |  |  | 
878  |  |     using std_alloc_t = std::is_same<typename std::decay<Alloc>::type, phmap::priv::Allocator<value_type>>;  | 
879  |  |  | 
880  |  | private:  | 
881  |  |     // Give an early error when key_type is not hashable/eq.  | 
882  |  |     auto KeyTypeCanBeHashed(const Hash& h, const key_type& k) -> decltype(h(k));  | 
883  |  |     auto KeyTypeCanBeEq(const Eq& eq, const key_type& k) -> decltype(eq(k, k));  | 
884  |  |  | 
885  |  |     using Layout = phmap::priv::Layout<ctrl_t, slot_type>;  | 
886  |  |  | 
887  | 6.47k  |     static Layout MakeLayout(size_t capacity) { | 
888  | 6.47k  |         assert(IsValidCapacity(capacity));  | 
889  | 6.47k  |         return Layout(capacity + Group::kWidth + 1, capacity);  | 
890  | 6.47k  |     } phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::MakeLayout(unsigned long) Line  | Count  | Source  |  887  | 6.47k  |     static Layout MakeLayout(size_t capacity) { |  888  | 6.47k  |         assert(IsValidCapacity(capacity));  |  889  | 6.47k  |         return Layout(capacity + Group::kWidth + 1, capacity);  |  890  | 6.47k  |     }  |  
 Unexecuted instantiation: phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::MakeLayout(unsigned long)  | 
891  |  |  | 
892  |  |     using AllocTraits = phmap::allocator_traits<allocator_type>;  | 
893  |  |     using SlotAlloc = typename phmap::allocator_traits<  | 
894  |  |         allocator_type>::template rebind_alloc<slot_type>;  | 
895  |  |     using SlotAllocTraits = typename phmap::allocator_traits<  | 
896  |  |         allocator_type>::template rebind_traits<slot_type>;  | 
897  |  |  | 
898  |  |     static_assert(std::is_lvalue_reference<reference>::value,  | 
899  |  |                   "Policy::element() must return a reference");  | 
900  |  |  | 
901  |  |     template <typename T>  | 
902  |  |     struct SameAsElementReference  | 
903  |  |         : std::is_same<typename std::remove_cv<  | 
904  |  |                            typename std::remove_reference<reference>::type>::type,  | 
905  |  |                        typename std::remove_cv<  | 
906  |  |                            typename std::remove_reference<T>::type>::type> {}; | 
907  |  |  | 
908  |  |     // An enabler for insert(T&&): T must be convertible to init_type or be the  | 
909  |  |     // same as [cv] value_type [ref].  | 
910  |  |     // Note: we separate SameAsElementReference into its own type to avoid using  | 
911  |  |     // reference unless we need to. MSVC doesn't seem to like it in some  | 
912  |  |     // cases.  | 
913  |  |     template <class T>  | 
914  |  |     using RequiresInsertable = typename std::enable_if<  | 
915  |  |         phmap::disjunction<std::is_convertible<T, init_type>,  | 
916  |  |                            SameAsElementReference<T>>::value,  | 
917  |  |         int>::type;  | 
918  |  |  | 
919  |  |     // RequiresNotInit is a workaround for gcc prior to 7.1.  | 
920  |  |     // See https://godbolt.org/g/Y4xsUh.  | 
921  |  |     template <class T>  | 
922  |  |     using RequiresNotInit =  | 
923  |  |         typename std::enable_if<!std::is_same<T, init_type>::value, int>::type;  | 
924  |  |  | 
925  |  |     template <class... Ts>  | 
926  |  |     using IsDecomposable = IsDecomposable<void, PolicyTraits, Hash, Eq, Ts...>;  | 
927  |  |  | 
928  |  | public:  | 
929  |  |     class iterator  | 
930  |  |     { | 
931  |  |         friend class raw_hash_set;  | 
932  |  |  | 
933  |  |     public:  | 
934  |  |         using iterator_category = std::forward_iterator_tag;  | 
935  |  |         using value_type = typename raw_hash_set::value_type;  | 
936  |  |         using reference =  | 
937  |  |             phmap::conditional_t<PolicyTraits::constant_iterators::value,  | 
938  |  |                                  const value_type&, value_type&>;  | 
939  |  |         using pointer = phmap::remove_reference_t<reference>*;  | 
940  |  |         using difference_type = typename raw_hash_set::difference_type;  | 
941  |  |  | 
942  |  |         iterator() {} | 
943  |  |  | 
944  |  |         // PRECONDITION: not an end() iterator.  | 
945  | 522k  |         reference operator*() const { return PolicyTraits::element(slot_); }phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::iterator::operator*() const Line  | Count  | Source  |  945  | 522k  |         reference operator*() const { return PolicyTraits::element(slot_); } |  
 Unexecuted instantiation: phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::iterator::operator*() const  | 
946  |  |  | 
947  |  |         // PRECONDITION: not an end() iterator.  | 
948  |  |         pointer operator->() const { return &operator*(); } | 
949  |  |  | 
950  |  |         // PRECONDITION: not an end() iterator.  | 
951  | 522k  |         iterator& operator++() { | 
952  | 522k  |             ++ctrl_;  | 
953  | 522k  |             ++slot_;  | 
954  | 522k  |             skip_empty_or_deleted();  | 
955  | 522k  |             return *this;  | 
956  | 522k  |         } phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::iterator::operator++() Line  | Count  | Source  |  951  | 522k  |         iterator& operator++() { |  952  | 522k  |             ++ctrl_;  |  953  | 522k  |             ++slot_;  |  954  | 522k  |             skip_empty_or_deleted();  |  955  | 522k  |             return *this;  |  956  | 522k  |         }  |  
 Unexecuted instantiation: phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::iterator::operator++()  | 
957  |  |         // PRECONDITION: not an end() iterator.  | 
958  |  |         iterator operator++(int) { | 
959  |  |             auto tmp = *this;  | 
960  |  |             ++*this;  | 
961  |  |             return tmp;  | 
962  |  |         }  | 
963  |  |  | 
964  |  | #if 0 // PHMAP_BIDIRECTIONAL  | 
965  |  |         // PRECONDITION: not a begin() iterator.  | 
966  |  |         iterator& operator--() { | 
967  |  |             assert(ctrl_);  | 
968  |  |             do { | 
969  |  |                 --ctrl_;  | 
970  |  |                 --slot_;  | 
971  |  |             } while (IsEmptyOrDeleted(*ctrl_));  | 
972  |  |             return *this;  | 
973  |  |         }  | 
974  |  |  | 
975  |  |         // PRECONDITION: not a begin() iterator.  | 
976  |  |         iterator operator--(int) { | 
977  |  |             auto tmp = *this;  | 
978  |  |             --*this;  | 
979  |  |             return tmp;  | 
980  |  |         }  | 
981  |  | #endif  | 
982  |  |  | 
983  | 523k  |         friend bool operator==(const iterator& a, const iterator& b) { | 
984  | 523k  |             return a.ctrl_ == b.ctrl_;  | 
985  | 523k  |         } phmap::priv::operator==(phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::iterator const&, phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::iterator const&) Line  | Count  | Source  |  983  | 522k  |         friend bool operator==(const iterator& a, const iterator& b) { |  984  | 522k  |             return a.ctrl_ == b.ctrl_;  |  985  | 522k  |         }  |  
 phmap::priv::operator==(phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::iterator const&, phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::iterator const&) Line  | Count  | Source  |  983  | 595  |         friend bool operator==(const iterator& a, const iterator& b) { |  984  | 595  |             return a.ctrl_ == b.ctrl_;  |  985  | 595  |         }  |  
  | 
986  | 595  |         friend bool operator!=(const iterator& a, const iterator& b) { | 
987  | 595  |             return !(a == b);  | 
988  | 595  |         }  | 
989  |  |  | 
990  |  |     private:  | 
991  | 765  |         iterator(ctrl_t* ctrl) : ctrl_(ctrl) {}  // for end()phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::iterator::iterator(signed char*) Line  | Count  | Source  |  991  | 170  |         iterator(ctrl_t* ctrl) : ctrl_(ctrl) {}  // for end() |  
 phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::iterator::iterator(signed char*) Line  | Count  | Source  |  991  | 595  |         iterator(ctrl_t* ctrl) : ctrl_(ctrl) {}  // for end() |  
  | 
992  | 11.3M  |         iterator(ctrl_t* ctrl, slot_type* slot) : ctrl_(ctrl), slot_(slot) {}phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::iterator::iterator(signed char*, phmap::priv::map_slot_type<unsigned int, int>*) Line  | Count  | Source  |  992  | 11.3M  |         iterator(ctrl_t* ctrl, slot_type* slot) : ctrl_(ctrl), slot_(slot) {} |  
 phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::iterator::iterator(signed char*, phmap::priv::map_slot_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >*) Line  | Count  | Source  |  992  | 595  |         iterator(ctrl_t* ctrl, slot_type* slot) : ctrl_(ctrl), slot_(slot) {} |  
  | 
993  |  |  | 
994  | 523k  |         void skip_empty_or_deleted() { | 
995  | 523k  |             PHMAP_IF_CONSTEXPR (!std_alloc_t::value) { | 
996  |  |                 // ctrl_ could be nullptr  | 
997  |  |                 if (!ctrl_)  | 
998  |  |                     return;  | 
999  |  |             }  | 
1000  | 737k  |             while (IsEmptyOrDeleted(*ctrl_)) { | 
1001  |  |                 // ctrl is not necessarily aligned to Group::kWidth. It is also likely  | 
1002  |  |                 // to read past the space for ctrl bytes and into slots. This is ok  | 
1003  |  |                 // because ctrl has sizeof() == 1 and slot has sizeof() >= 1 so there  | 
1004  |  |                 // is no way to read outside the combined slot array.  | 
1005  | 214k  |                 uint32_t shift = Group{ctrl_}.CountLeadingEmptyOrDeleted(); | 
1006  | 214k  |                 ctrl_ += shift;  | 
1007  | 214k  |                 slot_ += shift;  | 
1008  | 214k  |             }  | 
1009  | 523k  |         } phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::iterator::skip_empty_or_deleted() Line  | Count  | Source  |  994  | 522k  |         void skip_empty_or_deleted() { |  995  | 522k  |             PHMAP_IF_CONSTEXPR (!std_alloc_t::value) { |  996  |  |                 // ctrl_ could be nullptr  |  997  |  |                 if (!ctrl_)  |  998  |  |                     return;  |  999  |  |             }  |  1000  | 736k  |             while (IsEmptyOrDeleted(*ctrl_)) { |  1001  |  |                 // ctrl is not necessarily aligned to Group::kWidth. It is also likely  |  1002  |  |                 // to read past the space for ctrl bytes and into slots. This is ok  |  1003  |  |                 // because ctrl has sizeof() == 1 and slot has sizeof() >= 1 so there  |  1004  |  |                 // is no way to read outside the combined slot array.  |  1005  | 214k  |                 uint32_t shift = Group{ctrl_}.CountLeadingEmptyOrDeleted(); |  1006  | 214k  |                 ctrl_ += shift;  |  1007  | 214k  |                 slot_ += shift;  |  1008  | 214k  |             }  |  1009  | 522k  |         }  |  
 phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::iterator::skip_empty_or_deleted() Line  | Count  | Source  |  994  | 595  |         void skip_empty_or_deleted() { |  995  | 595  |             PHMAP_IF_CONSTEXPR (!std_alloc_t::value) { |  996  |  |                 // ctrl_ could be nullptr  |  997  |  |                 if (!ctrl_)  |  998  |  |                     return;  |  999  |  |             }  |  1000  | 595  |             while (IsEmptyOrDeleted(*ctrl_)) { |  1001  |  |                 // ctrl is not necessarily aligned to Group::kWidth. It is also likely  |  1002  |  |                 // to read past the space for ctrl bytes and into slots. This is ok  |  1003  |  |                 // because ctrl has sizeof() == 1 and slot has sizeof() >= 1 so there  |  1004  |  |                 // is no way to read outside the combined slot array.  |  1005  | 0  |                 uint32_t shift = Group{ctrl_}.CountLeadingEmptyOrDeleted(); |  1006  | 0  |                 ctrl_ += shift;  |  1007  | 0  |                 slot_ += shift;  |  1008  | 0  |             }  |  1009  | 595  |         }  |  
  | 
1010  |  |  | 
1011  |  |         ctrl_t* ctrl_ = nullptr;  | 
1012  |  |         // To avoid uninitialized member warnings, put slot_ in an anonymous union.  | 
1013  |  |         // The member is not initialized on singleton and end iterators.  | 
1014  |  |         union { | 
1015  |  |             slot_type* slot_;  | 
1016  |  |         };  | 
1017  |  |     };  | 
1018  |  |  | 
1019  |  |     class const_iterator   | 
1020  |  |     { | 
1021  |  |         friend class raw_hash_set;  | 
1022  |  |  | 
1023  |  |     public:  | 
1024  |  |         using iterator_category = typename iterator::iterator_category;  | 
1025  |  |         using value_type = typename raw_hash_set::value_type;  | 
1026  |  |         using reference = typename raw_hash_set::const_reference;  | 
1027  |  |         using pointer = typename raw_hash_set::const_pointer;  | 
1028  |  |         using difference_type = typename raw_hash_set::difference_type;  | 
1029  |  |  | 
1030  |  |         const_iterator() {} | 
1031  |  |         // Implicit construction from iterator.  | 
1032  | 340  |         const_iterator(iterator i) : inner_(std::move(i)) {} | 
1033  |  |  | 
1034  | 522k  |         reference operator*() const { return *inner_; } | 
1035  |  |         pointer operator->() const { return inner_.operator->(); } | 
1036  |  |  | 
1037  | 522k  |         const_iterator& operator++() { | 
1038  | 522k  |             ++inner_;  | 
1039  | 522k  |             return *this;  | 
1040  | 522k  |         }  | 
1041  |  |         const_iterator operator++(int) { return inner_++; } | 
1042  |  |  | 
1043  | 522k  |         friend bool operator==(const const_iterator& a, const const_iterator& b) { | 
1044  | 522k  |             return a.inner_ == b.inner_;  | 
1045  | 522k  |         }  | 
1046  | 522k  |         friend bool operator!=(const const_iterator& a, const const_iterator& b) { | 
1047  | 522k  |             return !(a == b);  | 
1048  | 522k  |         }  | 
1049  |  |  | 
1050  |  |     private:  | 
1051  |  |         const_iterator(const ctrl_t* ctrl, const slot_type* slot)  | 
1052  |  |             : inner_(const_cast<ctrl_t*>(ctrl), const_cast<slot_type*>(slot)) {} | 
1053  |  |  | 
1054  |  |         iterator inner_;  | 
1055  |  |     };  | 
1056  |  |  | 
1057  |  |     using node_type = node_handle<Policy, hash_policy_traits<Policy>, Alloc>;  | 
1058  |  |     using insert_return_type = InsertReturnType<iterator, node_type>;  | 
1059  |  |  | 
1060  |  |     raw_hash_set() noexcept(  | 
1061  |  |         std::is_nothrow_default_constructible<hasher>::value&&  | 
1062  |  |         std::is_nothrow_default_constructible<key_equal>::value&&  | 
1063  | 2.38k  |         std::is_nothrow_default_constructible<allocator_type>::value) {}phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::raw_hash_set() Line  | Count  | Source  |  1063  | 1.78k  |         std::is_nothrow_default_constructible<allocator_type>::value) {} |  
 phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::raw_hash_set() Line  | Count  | Source  |  1063  | 595  |         std::is_nothrow_default_constructible<allocator_type>::value) {} |  
  | 
1064  |  |  | 
1065  |  |     explicit raw_hash_set(size_t bucket_cnt, const hasher& hashfn = hasher(),  | 
1066  |  |                           const key_equal& eq = key_equal(),  | 
1067  |  |                           const allocator_type& alloc = allocator_type())  | 
1068  |  |         : ctrl_(EmptyGroup<std_alloc_t>()), settings_(0, hashfn, eq, alloc) { | 
1069  |  |         if (bucket_cnt) { | 
1070  |  |             size_t new_capacity = NormalizeCapacity(bucket_cnt);  | 
1071  |  |             reset_growth_left(new_capacity);  | 
1072  |  |             initialize_slots(new_capacity);  | 
1073  |  |             capacity_ = new_capacity;  | 
1074  |  |         }  | 
1075  |  |     }  | 
1076  |  |  | 
1077  |  |     raw_hash_set(size_t bucket_cnt, const hasher& hashfn,  | 
1078  |  |                  const allocator_type& alloc)  | 
1079  |  |         : raw_hash_set(bucket_cnt, hashfn, key_equal(), alloc) {} | 
1080  |  |  | 
1081  |  |     raw_hash_set(size_t bucket_cnt, const allocator_type& alloc)  | 
1082  |  |         : raw_hash_set(bucket_cnt, hasher(), key_equal(), alloc) {} | 
1083  |  |  | 
1084  |  |     explicit raw_hash_set(const allocator_type& alloc)  | 
1085  |  |         : raw_hash_set(0, hasher(), key_equal(), alloc) {} | 
1086  |  |  | 
1087  |  |     template <class InputIter>  | 
1088  |  |     raw_hash_set(InputIter first, InputIter last, size_t bucket_cnt = 0,  | 
1089  |  |                  const hasher& hashfn = hasher(), const key_equal& eq = key_equal(),  | 
1090  |  |                  const allocator_type& alloc = allocator_type())  | 
1091  |  |         : raw_hash_set(bucket_cnt, hashfn, eq, alloc) { | 
1092  |  |         insert(first, last);  | 
1093  |  |     }  | 
1094  |  |  | 
1095  |  |     template <class InputIter>  | 
1096  |  |     raw_hash_set(InputIter first, InputIter last, size_t bucket_cnt,  | 
1097  |  |                  const hasher& hashfn, const allocator_type& alloc)  | 
1098  |  |         : raw_hash_set(first, last, bucket_cnt, hashfn, key_equal(), alloc) {} | 
1099  |  |  | 
1100  |  |     template <class InputIter>  | 
1101  |  |     raw_hash_set(InputIter first, InputIter last, size_t bucket_cnt,  | 
1102  |  |                  const allocator_type& alloc)  | 
1103  |  |         : raw_hash_set(first, last, bucket_cnt, hasher(), key_equal(), alloc) {} | 
1104  |  |  | 
1105  |  |     template <class InputIter>  | 
1106  |  |     raw_hash_set(InputIter first, InputIter last, const allocator_type& alloc)  | 
1107  |  |         : raw_hash_set(first, last, 0, hasher(), key_equal(), alloc) {} | 
1108  |  |  | 
1109  |  |     // Instead of accepting std::initializer_list<value_type> as the first  | 
1110  |  |     // argument like std::unordered_set<value_type> does, we have two overloads  | 
1111  |  |     // that accept std::initializer_list<T> and std::initializer_list<init_type>.  | 
1112  |  |     // This is advantageous for performance.  | 
1113  |  |     //  | 
1114  |  |     //   // Turns {"abc", "def"} into std::initializer_list<std::string>, then | 
1115  |  |     //   // copies the strings into the set.  | 
1116  |  |     //   std::unordered_set<std::string> s = {"abc", "def"}; | 
1117  |  |     //  | 
1118  |  |     //   // Turns {"abc", "def"} into std::initializer_list<const char*>, then | 
1119  |  |     //   // copies the strings into the set.  | 
1120  |  |     //   phmap::flat_hash_set<std::string> s = {"abc", "def"}; | 
1121  |  |     //  | 
1122  |  |     // The same trick is used in insert().  | 
1123  |  |     //  | 
1124  |  |     // The enabler is necessary to prevent this constructor from triggering where  | 
1125  |  |     // the copy constructor is meant to be called.  | 
1126  |  |     //  | 
1127  |  |     //   phmap::flat_hash_set<int> a, b{a}; | 
1128  |  |     //  | 
1129  |  |     // RequiresNotInit<T> is a workaround for gcc prior to 7.1.  | 
1130  |  |     template <class T, RequiresNotInit<T> = 0, RequiresInsertable<T> = 0>  | 
1131  |  |     raw_hash_set(std::initializer_list<T> init, size_t bucket_cnt = 0,  | 
1132  |  |                  const hasher& hashfn = hasher(), const key_equal& eq = key_equal(),  | 
1133  |  |                  const allocator_type& alloc = allocator_type())  | 
1134  |  |         : raw_hash_set(init.begin(), init.end(), bucket_cnt, hashfn, eq, alloc) {} | 
1135  |  |  | 
1136  |  |     raw_hash_set(std::initializer_list<init_type> init, size_t bucket_cnt = 0,  | 
1137  |  |                  const hasher& hashfn = hasher(), const key_equal& eq = key_equal(),  | 
1138  |  |                  const allocator_type& alloc = allocator_type())  | 
1139  |  |         : raw_hash_set(init.begin(), init.end(), bucket_cnt, hashfn, eq, alloc) {} | 
1140  |  |  | 
1141  |  |     template <class T, RequiresNotInit<T> = 0, RequiresInsertable<T> = 0>  | 
1142  |  |     raw_hash_set(std::initializer_list<T> init, size_t bucket_cnt,  | 
1143  |  |                  const hasher& hashfn, const allocator_type& alloc)  | 
1144  |  |         : raw_hash_set(init, bucket_cnt, hashfn, key_equal(), alloc) {} | 
1145  |  |  | 
1146  |  |     raw_hash_set(std::initializer_list<init_type> init, size_t bucket_cnt,  | 
1147  |  |                  const hasher& hashfn, const allocator_type& alloc)  | 
1148  |  |         : raw_hash_set(init, bucket_cnt, hashfn, key_equal(), alloc) {} | 
1149  |  |  | 
1150  |  |     template <class T, RequiresNotInit<T> = 0, RequiresInsertable<T> = 0>  | 
1151  |  |     raw_hash_set(std::initializer_list<T> init, size_t bucket_cnt,  | 
1152  |  |                  const allocator_type& alloc)  | 
1153  |  |         : raw_hash_set(init, bucket_cnt, hasher(), key_equal(), alloc) {} | 
1154  |  |  | 
1155  |  |     raw_hash_set(std::initializer_list<init_type> init, size_t bucket_cnt,  | 
1156  |  |                  const allocator_type& alloc)  | 
1157  |  |         : raw_hash_set(init, bucket_cnt, hasher(), key_equal(), alloc) {} | 
1158  |  |  | 
1159  |  |     template <class T, RequiresNotInit<T> = 0, RequiresInsertable<T> = 0>  | 
1160  |  |     raw_hash_set(std::initializer_list<T> init, const allocator_type& alloc)  | 
1161  |  |         : raw_hash_set(init, 0, hasher(), key_equal(), alloc) {} | 
1162  |  |  | 
1163  |  |     raw_hash_set(std::initializer_list<init_type> init,  | 
1164  |  |                  const allocator_type& alloc)  | 
1165  |  |         : raw_hash_set(init, 0, hasher(), key_equal(), alloc) {} | 
1166  |  |  | 
1167  |  |     raw_hash_set(const raw_hash_set& that)  | 
1168  |  |         : raw_hash_set(that, AllocTraits::select_on_container_copy_construction(  | 
1169  |  |                            that.alloc_ref())) {} | 
1170  |  |  | 
1171  |  |     raw_hash_set(const raw_hash_set& that, const allocator_type& a)  | 
1172  |  |         : raw_hash_set(0, that.hash_ref(), that.eq_ref(), a) { | 
1173  |  |         rehash(that.capacity());   // operator=() should preserve load_factor  | 
1174  |  |         // Because the table is guaranteed to be empty, we can do something faster  | 
1175  |  |         // than a full `insert`.  | 
1176  |  |         for (const auto& v : that) { | 
1177  |  |             const size_t hashval = PolicyTraits::apply(HashElement{hash_ref()}, v); | 
1178  |  |             auto target = find_first_non_full(hashval);  | 
1179  |  |             set_ctrl(target.offset, H2(hashval));  | 
1180  |  |             emplace_at(target.offset, v);  | 
1181  |  |             infoz_.RecordInsert(hashval, target.probe_length);  | 
1182  |  |         }  | 
1183  |  |         size_ = that.size();  | 
1184  |  |         growth_left() -= that.size();  | 
1185  |  |     }  | 
1186  |  |  | 
1187  |  |     raw_hash_set(raw_hash_set&& that) noexcept(  | 
1188  |  |         std::is_nothrow_copy_constructible<hasher>::value&&  | 
1189  |  |         std::is_nothrow_copy_constructible<key_equal>::value&&  | 
1190  |  |         std::is_nothrow_copy_constructible<allocator_type>::value)  | 
1191  |  |         : ctrl_(phmap::exchange(that.ctrl_, EmptyGroup<std_alloc_t>())),  | 
1192  |  |         slots_(phmap::exchange(that.slots_, nullptr)),  | 
1193  |  |         size_(phmap::exchange(that.size_, 0)),  | 
1194  |  |         capacity_(phmap::exchange(that.capacity_, 0)),  | 
1195  |  |         infoz_(phmap::exchange(that.infoz_, HashtablezInfoHandle())),  | 
1196  |  |         // Hash, equality and allocator are copied instead of moved because  | 
1197  |  |         // `that` must be left valid. If Hash is std::function<Key>, moving it  | 
1198  |  |         // would create a nullptr functor that cannot be called.  | 
1199  |  |         settings_(std::move(that.settings_)) { | 
1200  |  |         // growth_left was copied above, reset the one from `that`.  | 
1201  |  |         that.growth_left() = 0;  | 
1202  |  |     }  | 
1203  |  |  | 
1204  |  |     raw_hash_set(raw_hash_set&& that, const allocator_type& a)  | 
1205  |  |         : ctrl_(EmptyGroup<std_alloc_t>()),  | 
1206  |  |           slots_(nullptr),  | 
1207  |  |           size_(0),  | 
1208  |  |           capacity_(0),  | 
1209  |  |           settings_(0, that.hash_ref(), that.eq_ref(), a) { | 
1210  |  |         if (a == that.alloc_ref()) { | 
1211  |  |             std::swap(ctrl_, that.ctrl_);  | 
1212  |  |             std::swap(slots_, that.slots_);  | 
1213  |  |             std::swap(size_, that.size_);  | 
1214  |  |             std::swap(capacity_, that.capacity_);  | 
1215  |  |             std::swap(growth_left(), that.growth_left());  | 
1216  |  |             std::swap(infoz_, that.infoz_);  | 
1217  |  |         } else { | 
1218  |  |             reserve(that.size());  | 
1219  |  |             // Note: this will copy elements of dense_set and unordered_set instead of  | 
1220  |  |             // moving them. This can be fixed if it ever becomes an issue.  | 
1221  |  |             for (auto& elem : that) insert(std::move(elem));  | 
1222  |  |         }  | 
1223  |  |     }  | 
1224  |  |  | 
1225  |  |     raw_hash_set& operator=(const raw_hash_set& that) { | 
1226  |  |         raw_hash_set tmp(that,  | 
1227  |  |                          AllocTraits::propagate_on_container_copy_assignment::value  | 
1228  |  |                          ? that.alloc_ref()  | 
1229  |  |                          : alloc_ref());  | 
1230  |  |         swap(tmp);  | 
1231  |  |         return *this;  | 
1232  |  |     }  | 
1233  |  |  | 
1234  |  |     raw_hash_set& operator=(raw_hash_set&& that) noexcept(  | 
1235  |  |         phmap::allocator_traits<allocator_type>::is_always_equal::value&&  | 
1236  |  |         std::is_nothrow_move_assignable<hasher>::value&&  | 
1237  |  |         std::is_nothrow_move_assignable<key_equal>::value) { | 
1238  |  |         // TODO(sbenza): We should only use the operations from the noexcept clause  | 
1239  |  |         // to make sure we actually adhere to that contract.  | 
1240  |  |         return move_assign(  | 
1241  |  |             std::move(that),  | 
1242  |  |             typename AllocTraits::propagate_on_container_move_assignment());  | 
1243  |  |     }  | 
1244  |  |  | 
1245  | 2.38k  |     ~raw_hash_set() { destroy_slots(); }phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::~raw_hash_set() Line  | Count  | Source  |  1245  | 1.78k  |     ~raw_hash_set() { destroy_slots(); } |  
 phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::~raw_hash_set() Line  | Count  | Source  |  1245  | 595  |     ~raw_hash_set() { destroy_slots(); } |  
  | 
1246  |  |  | 
1247  | 765  |     iterator begin() { | 
1248  | 765  |         auto it = iterator_at(0);  | 
1249  | 765  |         it.skip_empty_or_deleted();  | 
1250  | 765  |         return it;  | 
1251  | 765  |     } phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::begin() Line  | Count  | Source  |  1247  | 170  |     iterator begin() { |  1248  | 170  |         auto it = iterator_at(0);  |  1249  | 170  |         it.skip_empty_or_deleted();  |  1250  | 170  |         return it;  |  1251  | 170  |     }  |  
 phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::begin() Line  | Count  | Source  |  1247  | 595  |     iterator begin() { |  1248  | 595  |         auto it = iterator_at(0);  |  1249  | 595  |         it.skip_empty_or_deleted();  |  1250  | 595  |         return it;  |  1251  | 595  |     }  |  
  | 
1252  |  |     iterator end()   | 
1253  | 765  |     { | 
1254  |  | #if 0 // PHMAP_BIDIRECTIONAL  | 
1255  |  |         return iterator_at(capacity_);   | 
1256  |  | #else  | 
1257  | 765  |         return {ctrl_ + capacity_}; | 
1258  | 765  | #endif  | 
1259  | 765  |     } phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::end() Line  | Count  | Source  |  1253  | 170  |     { |  1254  |  | #if 0 // PHMAP_BIDIRECTIONAL  |  1255  |  |         return iterator_at(capacity_);   |  1256  |  | #else  |  1257  | 170  |         return {ctrl_ + capacity_}; |  1258  | 170  | #endif  |  1259  | 170  |     }  |  
 phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::end() Line  | Count  | Source  |  1253  | 595  |     { |  1254  |  | #if 0 // PHMAP_BIDIRECTIONAL  |  1255  |  |         return iterator_at(capacity_);   |  1256  |  | #else  |  1257  | 595  |         return {ctrl_ + capacity_}; |  1258  | 595  | #endif  |  1259  | 595  |     }  |  
  | 
1260  |  |  | 
1261  | 170  |     const_iterator begin() const { | 
1262  | 170  |         return const_cast<raw_hash_set*>(this)->begin();  | 
1263  | 170  |     }  | 
1264  | 170  |     const_iterator end() const { return const_cast<raw_hash_set*>(this)->end(); } | 
1265  |  |     const_iterator cbegin() const { return begin(); } | 
1266  |  |     const_iterator cend() const { return end(); } | 
1267  |  |  | 
1268  |  |     bool empty() const { return !size(); } | 
1269  | 3.73k  |     size_t size() const { return size_; } | 
1270  | 2.88k  |     size_t capacity() const { return capacity_; } | 
1271  |  |     size_t max_size() const { return (std::numeric_limits<size_t>::max)(); } | 
1272  |  |  | 
1273  |  |     PHMAP_ATTRIBUTE_REINITIALIZES void clear() { | 
1274  |  |         if (empty())  | 
1275  |  |             return;  | 
1276  |  |         if (capacity_) { | 
1277  |  |            PHMAP_IF_CONSTEXPR((!std::is_trivially_destructible<typename PolicyTraits::value_type>::value ||  | 
1278  |  |                                std::is_same<typename Policy::is_flat, std::false_type>::value)) { | 
1279  |  |                 // node map or not trivially destructible... we  need to iterate and destroy values one by one  | 
1280  |  |                 for (size_t i = 0; i != capacity_; ++i) { | 
1281  |  |                     if (IsFull(ctrl_[i])) { | 
1282  |  |                         PolicyTraits::destroy(&alloc_ref(), slots_ + i);  | 
1283  |  |                     }  | 
1284  |  |                 }  | 
1285  |  |             }  | 
1286  |  |             size_ = 0;  | 
1287  |  |             reset_ctrl(capacity_);  | 
1288  |  |             reset_growth_left(capacity_);  | 
1289  |  |         }  | 
1290  |  |         assert(empty());  | 
1291  |  |         infoz_.RecordStorageChanged(0, capacity_);  | 
1292  |  |     }  | 
1293  |  |  | 
1294  |  |     // This overload kicks in when the argument is an rvalue of insertable and  | 
1295  |  |     // decomposable type other than init_type.  | 
1296  |  |     //  | 
1297  |  |     //   flat_hash_map<std::string, int> m;  | 
1298  |  |     //   m.insert(std::make_pair("abc", 42)); | 
1299  |  |     template <class T, RequiresInsertable<T> = 0,  | 
1300  |  |               typename std::enable_if<IsDecomposable<T>::value, int>::type = 0,  | 
1301  |  |               T* = nullptr>  | 
1302  | 11.3M  |     std::pair<iterator, bool> insert(T&& value) { | 
1303  | 11.3M  |         return emplace(std::forward<T>(value));  | 
1304  | 11.3M  |     }  | 
1305  |  |  | 
1306  |  |     // This overload kicks in when the argument is a bitfield or an lvalue of  | 
1307  |  |     // insertable and decomposable type.  | 
1308  |  |     //  | 
1309  |  |     //   union { int n : 1; }; | 
1310  |  |     //   flat_hash_set<int> s;  | 
1311  |  |     //   s.insert(n);  | 
1312  |  |     //  | 
1313  |  |     //   flat_hash_set<std::string> s;  | 
1314  |  |     //   const char* p = "hello";  | 
1315  |  |     //   s.insert(p);  | 
1316  |  |     //  | 
1317  |  |     // TODO(romanp): Once we stop supporting gcc 5.1 and below, replace  | 
1318  |  |     // RequiresInsertable<T> with RequiresInsertable<const T&>.  | 
1319  |  |     // We are hitting this bug: https://godbolt.org/g/1Vht4f.  | 
1320  |  |     template <class T, RequiresInsertable<T> = 0,  | 
1321  |  |               typename std::enable_if<IsDecomposable<const T&>::value, int>::type = 0>  | 
1322  |  |     std::pair<iterator, bool> insert(const T& value) { | 
1323  |  |         return emplace(value);  | 
1324  |  |     }  | 
1325  |  |  | 
1326  |  |     // This overload kicks in when the argument is an rvalue of init_type. Its  | 
1327  |  |     // purpose is to handle brace-init-list arguments.  | 
1328  |  |     //  | 
1329  |  |     //   flat_hash_set<std::string, int> s;  | 
1330  |  |     //   s.insert({"abc", 42}); | 
1331  |  |     std::pair<iterator, bool> insert(init_type&& value) { | 
1332  |  |         return emplace(std::move(value));  | 
1333  |  |     }  | 
1334  |  |  | 
1335  |  |     template <class T, RequiresInsertable<T> = 0,  | 
1336  |  |               typename std::enable_if<IsDecomposable<T>::value, int>::type = 0,  | 
1337  |  |               T* = nullptr>  | 
1338  |  |     iterator insert(const_iterator, T&& value) { | 
1339  |  |         return insert(std::forward<T>(value)).first;  | 
1340  |  |     }  | 
1341  |  |  | 
1342  |  |     // TODO(romanp): Once we stop supporting gcc 5.1 and below, replace  | 
1343  |  |     // RequiresInsertable<T> with RequiresInsertable<const T&>.  | 
1344  |  |     // We are hitting this bug: https://godbolt.org/g/1Vht4f.  | 
1345  |  |     template <class T, RequiresInsertable<T> = 0,  | 
1346  |  |               typename std::enable_if<IsDecomposable<const T&>::value, int>::type = 0>  | 
1347  |  |     iterator insert(const_iterator, const T& value) { | 
1348  |  |         return insert(value).first;  | 
1349  |  |     }  | 
1350  |  |  | 
1351  |  |     iterator insert(const_iterator, init_type&& value) { | 
1352  |  |         return insert(std::move(value)).first;  | 
1353  |  |     }  | 
1354  |  |  | 
1355  |  |     template <typename It>  | 
1356  |  |     using IsRandomAccess = std::is_same<typename std::iterator_traits<It>::iterator_category,  | 
1357  |  |                                         std::random_access_iterator_tag>;  | 
1358  |  |  | 
1359  |  |  | 
1360  |  |     template<typename T>  | 
1361  |  |     struct has_difference_operator  | 
1362  |  |     { | 
1363  |  |     private:  | 
1364  |  |         using yes = std::true_type;  | 
1365  |  |         using no  = std::false_type;  | 
1366  |  |    | 
1367  |  |         template<typename U> static auto test(int) -> decltype(std::declval<U>() - std::declval<U>() == 1, yes());  | 
1368  |  |         template<typename>   static no   test(...);  | 
1369  |  |    | 
1370  |  |     public:  | 
1371  |  |         static constexpr bool value = std::is_same<decltype(test<T>(0)), yes>::value;  | 
1372  |  |     };  | 
1373  |  |  | 
1374  |  |     template <class InputIt, typename phmap::enable_if_t<has_difference_operator<InputIt>::value, int> = 0>  | 
1375  |  |     void insert(InputIt first, InputIt last) { | 
1376  |  |         this->reserve(this->size() + (last - first));  | 
1377  |  |         for (; first != last; ++first)   | 
1378  |  |             emplace(*first);  | 
1379  |  |     }  | 
1380  |  |  | 
1381  |  |     template <class InputIt, typename phmap::enable_if_t<!has_difference_operator<InputIt>::value, int> = 0>  | 
1382  |  |     void insert(InputIt first, InputIt last) { | 
1383  |  |         for (; first != last; ++first)   | 
1384  |  |             emplace(*first);  | 
1385  |  |     }  | 
1386  |  |  | 
1387  |  |     template <class T, RequiresNotInit<T> = 0, RequiresInsertable<const T&> = 0>  | 
1388  |  |     void insert(std::initializer_list<T> ilist) { | 
1389  |  |         insert(ilist.begin(), ilist.end());  | 
1390  |  |     }  | 
1391  |  |  | 
1392  |  |     void insert(std::initializer_list<init_type> ilist) { | 
1393  |  |         insert(ilist.begin(), ilist.end());  | 
1394  |  |     }  | 
1395  |  |  | 
1396  |  |     insert_return_type insert(node_type&& node) { | 
1397  |  |         if (!node) return {end(), false, node_type()}; | 
1398  |  |         const auto& elem = PolicyTraits::element(CommonAccess::GetSlot(node));  | 
1399  |  |         auto res = PolicyTraits::apply(  | 
1400  |  |             InsertSlot<false>{*this, std::move(*CommonAccess::GetSlot(node))}, | 
1401  |  |             elem);  | 
1402  |  |         if (res.second) { | 
1403  |  |             CommonAccess::Reset(&node);  | 
1404  |  |             return {res.first, true, node_type()}; | 
1405  |  |         } else { | 
1406  |  |             return {res.first, false, std::move(node)}; | 
1407  |  |         }  | 
1408  |  |     }  | 
1409  |  |  | 
1410  |  |     insert_return_type insert(node_type&& node, size_t hashval) { | 
1411  |  |         if (!node) return {end(), false, node_type()}; | 
1412  |  |         const auto& elem = PolicyTraits::element(CommonAccess::GetSlot(node));  | 
1413  |  |         auto res = PolicyTraits::apply(  | 
1414  |  |             InsertSlotWithHash<false>{*this, std::move(*CommonAccess::GetSlot(node)), hashval}, | 
1415  |  |             elem);  | 
1416  |  |         if (res.second) { | 
1417  |  |             CommonAccess::Reset(&node);  | 
1418  |  |             return {res.first, true, node_type()}; | 
1419  |  |         } else { | 
1420  |  |             return {res.first, false, std::move(node)}; | 
1421  |  |         }  | 
1422  |  |     }  | 
1423  |  |  | 
1424  |  |     iterator insert(const_iterator, node_type&& node) { | 
1425  |  |         auto res = insert(std::move(node));  | 
1426  |  |         node = std::move(res.node);  | 
1427  |  |         return res.position;  | 
1428  |  |     }  | 
1429  |  |  | 
1430  |  |     // This overload kicks in if we can deduce the key from args. This enables us  | 
1431  |  |     // to avoid constructing value_type if an entry with the same key already  | 
1432  |  |     // exists.  | 
1433  |  |     //  | 
1434  |  |     // For example:  | 
1435  |  |     //  | 
1436  |  |     //   flat_hash_map<std::string, std::string> m = {{"abc", "def"}}; | 
1437  |  |     //   // Creates no std::string copies and makes no heap allocations.  | 
1438  |  |     //   m.emplace("abc", "xyz"); | 
1439  |  |     template <class... Args, typename std::enable_if<  | 
1440  |  |                                  IsDecomposable<Args...>::value, int>::type = 0>  | 
1441  | 11.3M  |     std::pair<iterator, bool> emplace(Args&&... args) { | 
1442  | 11.3M  |         return PolicyTraits::apply(EmplaceDecomposable{*this}, | 
1443  | 11.3M  |                                    std::forward<Args>(args)...);  | 
1444  | 11.3M  |     }  | 
1445  |  |  | 
1446  |  |     template <class... Args, typename std::enable_if<IsDecomposable<Args...>::value, int>::type = 0>  | 
1447  |  |     std::pair<iterator, bool> emplace_with_hash(size_t hashval, Args&&... args) { | 
1448  |  |         return PolicyTraits::apply(EmplaceDecomposableHashval{*this, hashval}, std::forward<Args>(args)...); | 
1449  |  |     }  | 
1450  |  |  | 
1451  |  |     // This overload kicks in if we cannot deduce the key from args. It constructs  | 
1452  |  |     // value_type unconditionally and then either moves it into the table or  | 
1453  |  |     // destroys.  | 
1454  |  |     template <class... Args, typename std::enable_if<!IsDecomposable<Args...>::value, int>::type = 0>  | 
1455  |  |     std::pair<iterator, bool> emplace(Args&&... args) { | 
1456  |  |         typename phmap::aligned_storage<sizeof(slot_type), alignof(slot_type)>::type  | 
1457  |  |             raw;  | 
1458  |  |         slot_type* slot = reinterpret_cast<slot_type*>(&raw);  | 
1459  |  |  | 
1460  |  |         PolicyTraits::construct(&alloc_ref(), slot, std::forward<Args>(args)...);  | 
1461  |  |         const auto& elem = PolicyTraits::element(slot);  | 
1462  |  |         return PolicyTraits::apply(InsertSlot<true>{*this, std::move(*slot)}, elem); | 
1463  |  |     }  | 
1464  |  |  | 
1465  |  |     template <class... Args, typename std::enable_if<!IsDecomposable<Args...>::value, int>::type = 0>  | 
1466  |  |     std::pair<iterator, bool> emplace_with_hash(size_t hashval, Args&&... args) { | 
1467  |  |         typename phmap::aligned_storage<sizeof(slot_type), alignof(slot_type)>::type raw;  | 
1468  |  |         slot_type* slot = reinterpret_cast<slot_type*>(&raw);  | 
1469  |  |  | 
1470  |  |         PolicyTraits::construct(&alloc_ref(), slot, std::forward<Args>(args)...);  | 
1471  |  |         const auto& elem = PolicyTraits::element(slot);  | 
1472  |  |         return PolicyTraits::apply(InsertSlotWithHash<true>{*this, std::move(*slot), hashval}, elem); | 
1473  |  |     }  | 
1474  |  |  | 
1475  |  |     template <class... Args>  | 
1476  |  |     iterator emplace_hint(const_iterator, Args&&... args) { | 
1477  |  |         return emplace(std::forward<Args>(args)...).first;  | 
1478  |  |     }  | 
1479  |  |  | 
1480  |  |     template <class... Args>  | 
1481  |  |     iterator emplace_hint_with_hash(size_t hashval, const_iterator, Args&&... args) { | 
1482  |  |         return emplace_with_hash(hashval, std::forward<Args>(args)...).first;  | 
1483  |  |     }  | 
1484  |  |  | 
1485  |  |     // Extension API: support for lazy emplace.  | 
1486  |  |     //  | 
1487  |  |     // Looks up key in the table. If found, returns the iterator to the element.  | 
1488  |  |     // Otherwise calls f with one argument of type raw_hash_set::constructor. f  | 
1489  |  |     // MUST call raw_hash_set::constructor with arguments as if a  | 
1490  |  |     // raw_hash_set::value_type is constructed, otherwise the behavior is  | 
1491  |  |     // undefined.  | 
1492  |  |     //  | 
1493  |  |     // For example:  | 
1494  |  |     //  | 
1495  |  |     //   std::unordered_set<ArenaString> s;  | 
1496  |  |     //   // Makes ArenaStr even if "abc" is in the map.  | 
1497  |  |     //   s.insert(ArenaString(&arena, "abc"));  | 
1498  |  |     //  | 
1499  |  |     //   flat_hash_set<ArenaStr> s;  | 
1500  |  |     //   // Makes ArenaStr only if "abc" is not in the map.  | 
1501  |  |     //   s.lazy_emplace("abc", [&](const constructor& ctor) { | 
1502  |  |     //     ctor(&arena, "abc");  | 
1503  |  |     //   });  | 
1504  |  |     //  | 
1505  |  |     // WARNING: This API is currently experimental. If there is a way to implement  | 
1506  |  |     // the same thing with the rest of the API, prefer that.  | 
1507  |  |     class constructor   | 
1508  |  |     { | 
1509  |  |         friend class raw_hash_set;  | 
1510  |  |  | 
1511  |  |     public:  | 
1512  |  |         slot_type* slot() const { | 
1513  |  |             return *slot_;  | 
1514  |  |         }  | 
1515  |  |  | 
1516  |  |         template <class... Args>  | 
1517  |  |         void operator()(Args&&... args) const { | 
1518  |  |             assert(*slot_);  | 
1519  |  |             PolicyTraits::construct(alloc_, *slot_, std::forward<Args>(args)...);  | 
1520  |  |             *slot_ = nullptr;  | 
1521  |  |         }  | 
1522  |  |  | 
1523  |  |     private:  | 
1524  |  |         constructor(allocator_type* a, slot_type** slot) : alloc_(a), slot_(slot) {} | 
1525  |  |  | 
1526  |  |         allocator_type* alloc_;  | 
1527  |  |         slot_type** slot_;  | 
1528  |  |     };  | 
1529  |  |  | 
1530  |  |     // Extension API: support for lazy emplace.  | 
1531  |  |     // Looks up key in the table. If found, returns the iterator to the element.  | 
1532  |  |     // Otherwise calls f with one argument of type raw_hash_set::constructor. f  | 
1533  |  |     // MUST call raw_hash_set::constructor with arguments as if a  | 
1534  |  |     // raw_hash_set::value_type is constructed, otherwise the behavior is  | 
1535  |  |     // undefined.  | 
1536  |  |     //  | 
1537  |  |     // For example:  | 
1538  |  |     //  | 
1539  |  |     //   std::unordered_set<ArenaString> s;  | 
1540  |  |     //   // Makes ArenaStr even if "abc" is in the map.  | 
1541  |  |     //   s.insert(ArenaString(&arena, "abc"));  | 
1542  |  |     //  | 
1543  |  |     //   flat_hash_set<ArenaStr> s;  | 
1544  |  |     //   // Makes ArenaStr only if "abc" is not in the map.  | 
1545  |  |     //   s.lazy_emplace("abc", [&](const constructor& ctor) { | 
1546  |  |     //                         ctor(&arena, "abc");  | 
1547  |  |     //   });  | 
1548  |  |     // -----------------------------------------------------  | 
1549  |  |     template <class K = key_type, class F>  | 
1550  |  |     iterator lazy_emplace(const key_arg<K>& key, F&& f) { | 
1551  |  |         return lazy_emplace_with_hash(key, this->hash(key), std::forward<F>(f));  | 
1552  |  |     }  | 
1553  |  |  | 
1554  |  |     template <class K = key_type, class F>  | 
1555  |  |     iterator lazy_emplace_with_hash(const key_arg<K>& key, size_t hashval, F&& f) { | 
1556  |  |         size_t offset = _find_key(key, hashval);  | 
1557  |  |         if (offset == (size_t)-1) { | 
1558  |  |             offset = prepare_insert(hashval);  | 
1559  |  |             lazy_emplace_at(offset, std::forward<F>(f));  | 
1560  |  |             this->set_ctrl(offset, H2(hashval));  | 
1561  |  |         }  | 
1562  |  |         return iterator_at(offset);  | 
1563  |  |     }  | 
1564  |  |  | 
1565  |  |     template <class K = key_type, class F>  | 
1566  |  |     void lazy_emplace_at(size_t& idx, F&& f) { | 
1567  |  |         slot_type* slot = slots_ + idx;  | 
1568  |  |         std::forward<F>(f)(constructor(&alloc_ref(), &slot));  | 
1569  |  |         assert(!slot);  | 
1570  |  |     }  | 
1571  |  |  | 
1572  |  |     template <class K = key_type, class F>  | 
1573  |  |     void emplace_single_with_hash(const key_arg<K>& key, size_t hashval, F&& f) { | 
1574  |  |         size_t offset = _find_key(key, hashval);  | 
1575  |  |         if (offset == (size_t)-1) { | 
1576  |  |             offset = prepare_insert(hashval);  | 
1577  |  |             lazy_emplace_at(offset, std::forward<F>(f));  | 
1578  |  |             this->set_ctrl(offset, H2(hashval));  | 
1579  |  |         } else  | 
1580  |  |             _erase(iterator_at(offset));  | 
1581  |  |     }  | 
1582  |  |  | 
1583  |  |  | 
1584  |  |     // Extension API: support for heterogeneous keys.  | 
1585  |  |     //  | 
1586  |  |     //   std::unordered_set<std::string> s;  | 
1587  |  |     //   // Turns "abc" into std::string.  | 
1588  |  |     //   s.erase("abc"); | 
1589  |  |     //  | 
1590  |  |     //   flat_hash_set<std::string> s;  | 
1591  |  |     //   // Uses "abc" directly without copying it into std::string.  | 
1592  |  |     //   s.erase("abc"); | 
1593  |  |     template <class K = key_type>  | 
1594  |  |     size_type erase(const key_arg<K>& key) { | 
1595  |  |         auto it = find(key);  | 
1596  |  |         if (it == end()) return 0;  | 
1597  |  |         _erase(it);  | 
1598  |  |         return 1;  | 
1599  |  |     }  | 
1600  |  |  | 
1601  |  |  | 
1602  |  |     iterator erase(const_iterator cit) { return erase(cit.inner_); } | 
1603  |  |       | 
1604  |  |     // Erases the element pointed to by `it`.  Unlike `std::unordered_set::erase`,  | 
1605  |  |     // this method returns void to reduce algorithmic complexity to O(1).  In  | 
1606  |  |     // order to erase while iterating across a map, use the following idiom (which  | 
1607  |  |     // also works for standard containers):  | 
1608  |  |     //  | 
1609  |  |     // for (auto it = m.begin(), end = m.end(); it != end;) { | 
1610  |  |     //   if (<pred>) { | 
1611  |  |     //     m._erase(it++);  | 
1612  |  |     //   } else { | 
1613  |  |     //     ++it;  | 
1614  |  |     //   }  | 
1615  |  |     // }  | 
1616  |  |     void _erase(iterator it) { | 
1617  |  |         assert(it != end());  | 
1618  |  |         PolicyTraits::destroy(&alloc_ref(), it.slot_);  | 
1619  |  |         erase_meta_only(it);  | 
1620  |  |     }  | 
1621  |  |     void _erase(const_iterator cit) { _erase(cit.inner_); } | 
1622  |  |  | 
1623  |  |     // This overload is necessary because otherwise erase<K>(const K&) would be  | 
1624  |  |     // a better match if non-const iterator is passed as an argument.  | 
1625  |  |     iterator erase(iterator it) { | 
1626  |  |         assert(it != end());  | 
1627  |  |         auto res = it;  | 
1628  |  |         ++res;  | 
1629  |  |         _erase(it);  | 
1630  |  |         return res;  | 
1631  |  |     }  | 
1632  |  |  | 
1633  |  |     iterator erase(const_iterator first, const_iterator last) { | 
1634  |  |         while (first != last) { | 
1635  |  |             _erase(first++);  | 
1636  |  |         }  | 
1637  |  |         return last.inner_;  | 
1638  |  |     }  | 
1639  |  |  | 
1640  |  |     // Moves elements from `src` into `this`.  | 
1641  |  |     // If the element already exists in `this`, it is left unmodified in `src`.  | 
1642  |  |     template <typename H, typename E>  | 
1643  |  |     void merge(raw_hash_set<Policy, H, E, Alloc>& src) {  // NOLINT | 
1644  |  |         assert(this != &src);  | 
1645  |  |         for (auto it = src.begin(), e = src.end(); it != e; ++it) { | 
1646  |  |             if (PolicyTraits::apply(InsertSlot<false>{*this, std::move(*it.slot_)}, | 
1647  |  |                                     PolicyTraits::element(it.slot_))  | 
1648  |  |                 .second) { | 
1649  |  |                 src.erase_meta_only(it);  | 
1650  |  |             }  | 
1651  |  |         }  | 
1652  |  |     }  | 
1653  |  |  | 
1654  |  |     template <typename H, typename E>  | 
1655  |  |     void merge(raw_hash_set<Policy, H, E, Alloc>&& src) { | 
1656  |  |         merge(src);  | 
1657  |  |     }  | 
1658  |  |  | 
1659  |  |     node_type extract(const_iterator position) { | 
1660  |  |         auto node =  | 
1661  |  |             CommonAccess::Make<node_type>(alloc_ref(), position.inner_.slot_);  | 
1662  |  |         erase_meta_only(position);  | 
1663  |  |         return node;  | 
1664  |  |     }  | 
1665  |  |  | 
1666  |  |     template <  | 
1667  |  |         class K = key_type,  | 
1668  |  |         typename std::enable_if<!std::is_same<K, iterator>::value, int>::type = 0>  | 
1669  |  |     node_type extract(const key_arg<K>& key) { | 
1670  |  |         auto it = find(key);  | 
1671  |  |         return it == end() ? node_type() : extract(const_iterator{it}); | 
1672  |  |     }  | 
1673  |  |  | 
1674  |  |     void swap(raw_hash_set& that) noexcept(  | 
1675  |  |         IsNoThrowSwappable<hasher>() && IsNoThrowSwappable<key_equal>() &&  | 
1676  |  |         (!AllocTraits::propagate_on_container_swap::value ||  | 
1677  | 595  |          IsNoThrowSwappable<allocator_type>(typename AllocTraits::propagate_on_container_swap{}))) { | 
1678  | 595  |         using std::swap;  | 
1679  | 595  |         swap(ctrl_, that.ctrl_);  | 
1680  | 595  |         swap(slots_, that.slots_);  | 
1681  | 595  |         swap(size_, that.size_);  | 
1682  | 595  |         swap(capacity_, that.capacity_);  | 
1683  | 595  |         swap(growth_left(), that.growth_left());  | 
1684  | 595  |         swap(hash_ref(), that.hash_ref());  | 
1685  | 595  |         swap(eq_ref(), that.eq_ref());  | 
1686  | 595  |         swap(infoz_, that.infoz_);  | 
1687  | 595  |         SwapAlloc(alloc_ref(), that.alloc_ref(), typename AllocTraits::propagate_on_container_swap{}); | 
1688  | 595  |     }  | 
1689  |  |  | 
1690  |  | #if !defined(PHMAP_NON_DETERMINISTIC)  | 
1691  |  |     template<typename OutputArchive>  | 
1692  |  |     bool phmap_dump(OutputArchive&) const;  | 
1693  |  |  | 
1694  |  |     template<typename InputArchive>  | 
1695  |  |     bool  phmap_load(InputArchive&);  | 
1696  |  | #endif  | 
1697  |  |  | 
1698  |  |     void rehash(size_t n) { | 
1699  |  |         if (n == 0 && capacity_ == 0) return;  | 
1700  |  |         if (n == 0 && size_ == 0) { | 
1701  |  |             destroy_slots();  | 
1702  |  |             infoz_.RecordStorageChanged(0, 0);  | 
1703  |  |             return;  | 
1704  |  |         }  | 
1705  |  |         // bitor is a faster way of doing `max` here. We will round up to the next  | 
1706  |  |         // power-of-2-minus-1, so bitor is good enough.  | 
1707  |  |         auto m = NormalizeCapacity((std::max)(n, size()));  | 
1708  |  |         // n == 0 unconditionally rehashes as per the standard.  | 
1709  |  |         if (n == 0 || m > capacity_) { | 
1710  |  |             resize(m);  | 
1711  |  |         }  | 
1712  |  |     }  | 
1713  |  |  | 
1714  |  |     void reserve(size_t n) { rehash(GrowthToLowerboundCapacity(n)); } | 
1715  |  |  | 
1716  |  |     // Extension API: support for heterogeneous keys.  | 
1717  |  |     //  | 
1718  |  |     //   std::unordered_set<std::string> s;  | 
1719  |  |     //   // Turns "abc" into std::string.  | 
1720  |  |     //   s.count("abc"); | 
1721  |  |     //  | 
1722  |  |     //   ch_set<std::string> s;  | 
1723  |  |     //   // Uses "abc" directly without copying it into std::string.  | 
1724  |  |     //   s.count("abc"); | 
1725  |  |     template <class K = key_type>  | 
1726  |  |     size_t count(const key_arg<K>& key) const { | 
1727  |  |         return find(key) == end() ? size_t(0) : size_t(1);  | 
1728  |  |     }  | 
1729  |  |  | 
1730  |  |     // Issues CPU prefetch instructions for the memory needed to find or insert  | 
1731  |  |     // a key.  Like all lookup functions, this support heterogeneous keys.  | 
1732  |  |     //  | 
1733  |  |     // NOTE: This is a very low level operation and should not be used without  | 
1734  |  |     // specific benchmarks indicating its importance.  | 
1735  |  |     void prefetch_hash(size_t hashval) const { | 
1736  |  |         (void)hashval;  | 
1737  |  | #if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))  | 
1738  |  |         auto seq = probe(hashval);  | 
1739  |  |         _mm_prefetch((const char *)(ctrl_ + seq.offset()), _MM_HINT_NTA);  | 
1740  |  |         _mm_prefetch((const char *)(slots_ + seq.offset()), _MM_HINT_NTA);  | 
1741  |  | #elif defined(__GNUC__)  | 
1742  |  |         auto seq = probe(hashval);  | 
1743  |  |         __builtin_prefetch(static_cast<const void*>(ctrl_ + seq.offset()));  | 
1744  |  |         __builtin_prefetch(static_cast<const void*>(slots_ + seq.offset()));  | 
1745  |  | #endif  // __GNUC__  | 
1746  |  |     }  | 
1747  |  |  | 
1748  |  |     template <class K = key_type>  | 
1749  |  |     void prefetch(const key_arg<K>& key) const { | 
1750  |  |         PHMAP_IF_CONSTEXPR (std_alloc_t::value)  | 
1751  |  |             prefetch_hash(this->hash(key));  | 
1752  |  |     }  | 
1753  |  |  | 
1754  |  |     // The API of find() has two extensions.  | 
1755  |  |     //  | 
1756  |  |     // 1. The hash can be passed by the user. It must be equal to the hash of the  | 
1757  |  |     // key.  | 
1758  |  |     //  | 
1759  |  |     // 2. The type of the key argument doesn't have to be key_type. This is so  | 
1760  |  |     // called heterogeneous key support.  | 
1761  |  |     template <class K = key_type>  | 
1762  |  |     iterator find(const key_arg<K>& key, size_t hashval) { | 
1763  |  |         size_t offset;  | 
1764  |  |         if (find_impl(key, hashval, offset))  | 
1765  |  |             return iterator_at(offset);  | 
1766  |  |         else  | 
1767  |  |             return end();  | 
1768  |  |     }  | 
1769  |  |  | 
1770  |  |     template <class K = key_type>  | 
1771  |  |     pointer find_ptr(const key_arg<K>& key, size_t hashval) { | 
1772  |  |         size_t offset;  | 
1773  |  |         if (find_impl(key, hashval, offset))  | 
1774  |  |             return &PolicyTraits::element(slots_ + offset);  | 
1775  |  |         else  | 
1776  |  |             return nullptr;  | 
1777  |  |     }  | 
1778  |  |  | 
1779  |  |     template <class K = key_type>  | 
1780  |  |     iterator find(const key_arg<K>& key) { | 
1781  |  |         return find(key, this->hash(key));  | 
1782  |  |     }  | 
1783  |  |  | 
1784  |  |     template <class K = key_type>  | 
1785  |  |     const_iterator find(const key_arg<K>& key, size_t hashval) const { | 
1786  |  |         return const_cast<raw_hash_set*>(this)->find(key, hashval);  | 
1787  |  |     }  | 
1788  |  |     template <class K = key_type>  | 
1789  |  |     const_iterator find(const key_arg<K>& key) const { | 
1790  |  |         return find(key, this->hash(key));  | 
1791  |  |     }  | 
1792  |  |  | 
1793  |  |     template <class K = key_type>  | 
1794  |  |     bool contains(const key_arg<K>& key) const { | 
1795  |  |         return find(key) != end();  | 
1796  |  |     }  | 
1797  |  |  | 
1798  |  |     template <class K = key_type>  | 
1799  |  |     bool contains(const key_arg<K>& key, size_t hashval) const { | 
1800  |  |         return find(key, hashval) != end();  | 
1801  |  |     }  | 
1802  |  |  | 
1803  |  |     template <class K = key_type>  | 
1804  |  |     std::pair<iterator, iterator> equal_range(const key_arg<K>& key) { | 
1805  |  |         auto it = find(key);  | 
1806  |  |         if (it != end()) return {it, std::next(it)}; | 
1807  |  |         return {it, it}; | 
1808  |  |     }  | 
1809  |  |     template <class K = key_type>  | 
1810  |  |     std::pair<const_iterator, const_iterator> equal_range(  | 
1811  |  |         const key_arg<K>& key) const { | 
1812  |  |         auto it = find(key);  | 
1813  |  |         if (it != end()) return {it, std::next(it)}; | 
1814  |  |         return {it, it}; | 
1815  |  |     }  | 
1816  |  |  | 
1817  |  |     size_t bucket_count() const { return capacity_; } | 
1818  |  |     float load_factor() const { | 
1819  |  |         return capacity_ ? static_cast<float>(static_cast<double>(size()) / capacity_) : 0.0f;  | 
1820  |  |     }  | 
1821  |  |     float max_load_factor() const { return 1.0f; } | 
1822  |  |     void max_load_factor(float) { | 
1823  |  |         // Does nothing.  | 
1824  |  |     }  | 
1825  |  |  | 
1826  |  |     hasher hash_function() const { return hash_ref(); } // warning: doesn't match internal hash - use hash() member function | 
1827  |  |     key_equal key_eq() const { return eq_ref(); } | 
1828  |  |     allocator_type get_allocator() const { return alloc_ref(); } | 
1829  |  |  | 
1830  | 595  |     friend bool operator==(const raw_hash_set& a, const raw_hash_set& b) { | 
1831  | 595  |         if (a.size() != b.size()) return false;  | 
1832  | 170  |         const raw_hash_set* outer = &a;  | 
1833  | 170  |         const raw_hash_set* inner = &b;  | 
1834  | 170  |         if (outer->capacity() > inner->capacity())   | 
1835  | 0  |             std::swap(outer, inner);  | 
1836  | 170  |         for (const value_type& elem : *outer)  | 
1837  | 522k  |             if (!inner->has_element(elem)) return false;  | 
1838  | 53  |         return true;  | 
1839  | 170  |     }  | 
1840  |  |  | 
1841  |  |     friend bool operator!=(const raw_hash_set& a, const raw_hash_set& b) { | 
1842  |  |         return !(a == b);  | 
1843  |  |     }  | 
1844  |  |  | 
1845  |  |     friend void swap(raw_hash_set& a,  | 
1846  |  |                      raw_hash_set& b) noexcept(noexcept(a.swap(b))) { | 
1847  |  |         a.swap(b);  | 
1848  |  |     }  | 
1849  |  |  | 
1850  |  |     template <class K>  | 
1851  | 11.3M  |     size_t hash(const K& key) const { | 
1852  | 11.3M  |         return HashElement{hash_ref()}(key); | 
1853  | 11.3M  |     }  | 
1854  |  |  | 
1855  |  | private:  | 
1856  |  |     template <class Container, typename Enabler>  | 
1857  |  |     friend struct phmap::priv::hashtable_debug_internal::HashtableDebugAccess;  | 
1858  |  |  | 
1859  |  |     template <class K = key_type>  | 
1860  |  |     bool find_impl(const key_arg<K>& PHMAP_RESTRICT key, size_t hashval, size_t& PHMAP_RESTRICT offset) { | 
1861  |  |         PHMAP_IF_CONSTEXPR (!std_alloc_t::value) { | 
1862  |  |             // ctrl_ could be nullptr  | 
1863  |  |             if (!ctrl_)  | 
1864  |  |                 return false;  | 
1865  |  |         }  | 
1866  |  |         auto seq = probe(hashval);  | 
1867  |  |         while (true) { | 
1868  |  |             Group g{ ctrl_ + seq.offset() }; | 
1869  |  |             for (uint32_t i : g.Match((h2_t)H2(hashval))) { | 
1870  |  |                 offset = seq.offset((size_t)i);  | 
1871  |  |                 if (PHMAP_PREDICT_TRUE(PolicyTraits::apply(  | 
1872  |  |                     EqualElement<K>{key, eq_ref()}, | 
1873  |  |                     PolicyTraits::element(slots_ + offset))))  | 
1874  |  |                     return true;  | 
1875  |  |             }  | 
1876  |  |             if (PHMAP_PREDICT_TRUE(g.MatchEmpty()))  | 
1877  |  |                 return false;  | 
1878  |  |             seq.next();  | 
1879  |  |         }  | 
1880  |  |     }  | 
1881  |  |  | 
1882  |  |     struct FindElement   | 
1883  |  |     { | 
1884  |  |         template <class K, class... Args>  | 
1885  |  |         const_iterator operator()(const K& key, Args&&...) const { | 
1886  |  |             return s.find(key);  | 
1887  |  |         }  | 
1888  |  |         const raw_hash_set& s;  | 
1889  |  |     };  | 
1890  |  |  | 
1891  |  |     struct HashElement   | 
1892  |  |     { | 
1893  |  |         template <class K, class... Args>  | 
1894  | 12.8M  |         size_t operator()(const K& key, Args&&...) const { | 
1895  |  | #if PHMAP_DISABLE_MIX  | 
1896  |  |             return h(key);  | 
1897  |  | #else  | 
1898  | 12.8M  |             return phmap_mix<sizeof(size_t)>()(h(key));  | 
1899  | 12.8M  | #endif  | 
1900  | 12.8M  |         } unsigned long phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::HashElement::operator()<unsigned int, std::__1::piecewise_construct_t const&, std::__1::tuple<unsigned int const&>, std::__1::tuple<int const&> >(unsigned int const&, std::__1::piecewise_construct_t const&, std::__1::tuple<unsigned int const&>&&, std::__1::tuple<int const&>&&) const Line  | Count  | Source  |  1894  | 1.50M  |         size_t operator()(const K& key, Args&&...) const { |  1895  |  | #if PHMAP_DISABLE_MIX  |  1896  |  |             return h(key);  |  1897  |  | #else  |  1898  | 1.50M  |             return phmap_mix<sizeof(size_t)>()(h(key));  |  1899  | 1.50M  | #endif  |  1900  | 1.50M  |         }  |  
 unsigned long phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::HashElement::operator()<unsigned int>(unsigned int const&) const Line  | Count  | Source  |  1894  | 11.3M  |         size_t operator()(const K& key, Args&&...) const { |  1895  |  | #if PHMAP_DISABLE_MIX  |  1896  |  |             return h(key);  |  1897  |  | #else  |  1898  | 11.3M  |             return phmap_mix<sizeof(size_t)>()(h(key));  |  1899  | 11.3M  | #endif  |  1900  | 11.3M  |         }  |  
  | 
1901  |  |         const hasher& h;  | 
1902  |  |     };  | 
1903  |  |  | 
1904  |  |     template <class K1>  | 
1905  |  |     struct EqualElement   | 
1906  |  |     { | 
1907  |  |         template <class K2, class... Args>  | 
1908  | 13.4M  |         bool operator()(const K2& lhs, Args&&...) const { | 
1909  | 13.4M  |             return eq(lhs, rhs);  | 
1910  | 13.4M  |         }  | 
1911  |  |         const K1& rhs;  | 
1912  |  |         const key_equal& eq;  | 
1913  |  |     };  | 
1914  |  |  | 
1915  |  |     template <class K, class... Args>  | 
1916  |  |     std::pair<iterator, bool> emplace_decomposable(const K& key, size_t hashval,   | 
1917  |  |                                                    Args&&... args)  | 
1918  | 11.3M  |     { | 
1919  | 11.3M  |         size_t offset = _find_key(key, hashval);  | 
1920  | 11.3M  |         if (offset == (size_t)-1) { | 
1921  | 538k  |             offset = prepare_insert(hashval);  | 
1922  | 538k  |             emplace_at(offset, std::forward<Args>(args)...);  | 
1923  | 538k  |             this->set_ctrl(offset, H2(hashval));  | 
1924  | 538k  |             return {iterator_at(offset), true}; | 
1925  | 538k  |         }  | 
1926  | 10.8M  |         return {iterator_at(offset), false}; | 
1927  | 11.3M  |     }  | 
1928  |  |  | 
1929  |  |     struct EmplaceDecomposable   | 
1930  |  |     { | 
1931  |  |         template <class K, class... Args>  | 
1932  | 11.3M  |         std::pair<iterator, bool> operator()(const K& key, Args&&... args) const { | 
1933  | 11.3M  |             return s.emplace_decomposable(key, s.hash(key), std::forward<Args>(args)...);  | 
1934  | 11.3M  |         }  | 
1935  |  |         raw_hash_set& s;  | 
1936  |  |     };  | 
1937  |  |  | 
1938  |  |     struct EmplaceDecomposableHashval { | 
1939  |  |         template <class K, class... Args>  | 
1940  |  |         std::pair<iterator, bool> operator()(const K& key, Args&&... args) const { | 
1941  |  |             return s.emplace_decomposable(key, hashval, std::forward<Args>(args)...);  | 
1942  |  |         }  | 
1943  |  |         raw_hash_set& s;  | 
1944  |  |         size_t hashval;  | 
1945  |  |     };  | 
1946  |  |  | 
1947  |  |     template <bool do_destroy>  | 
1948  |  |     struct InsertSlot   | 
1949  |  |     { | 
1950  |  |         template <class K, class... Args>  | 
1951  |  |         std::pair<iterator, bool> operator()(const K& key, Args&&...) && { | 
1952  |  |             size_t hashval = s.hash(key);  | 
1953  |  |             auto res = s.find_or_prepare_insert(key, hashval);  | 
1954  |  |             if (res.second) { | 
1955  |  |                 PolicyTraits::transfer(&s.alloc_ref(), s.slots_ + res.first, &slot);  | 
1956  |  |                 s.set_ctrl(res.first, H2(hashval));  | 
1957  |  |             } else if (do_destroy) { | 
1958  |  |                 PolicyTraits::destroy(&s.alloc_ref(), &slot);  | 
1959  |  |             }  | 
1960  |  |             return {s.iterator_at(res.first), res.second}; | 
1961  |  |         }  | 
1962  |  |         raw_hash_set& s;  | 
1963  |  |         // Constructed slot. Either moved into place or destroyed.  | 
1964  |  |         slot_type&& slot;  | 
1965  |  |     };  | 
1966  |  |  | 
1967  |  |     template <bool do_destroy>  | 
1968  |  |     struct InsertSlotWithHash   | 
1969  |  |     { | 
1970  |  |         template <class K, class... Args>  | 
1971  |  |         std::pair<iterator, bool> operator()(const K& key, Args&&...) && { | 
1972  |  |             auto res = s.find_or_prepare_insert(key, hashval);  | 
1973  |  |             if (res.second) { | 
1974  |  |                 PolicyTraits::transfer(&s.alloc_ref(), s.slots_ + res.first, &slot);  | 
1975  |  |                 s.set_ctrl(res.first, H2(hashval));  | 
1976  |  |             } else if (do_destroy) { | 
1977  |  |                 PolicyTraits::destroy(&s.alloc_ref(), &slot);  | 
1978  |  |             }  | 
1979  |  |             return {s.iterator_at(res.first), res.second}; | 
1980  |  |         }  | 
1981  |  |         raw_hash_set& s;  | 
1982  |  |         // Constructed slot. Either moved into place or destroyed.  | 
1983  |  |         slot_type&& slot;  | 
1984  |  |         size_t &hashval;  | 
1985  |  |     };  | 
1986  |  |  | 
1987  |  |     // "erases" the object from the container, except that it doesn't actually  | 
1988  |  |     // destroy the object. It only updates all the metadata of the class.  | 
1989  |  |     // This can be used in conjunction with Policy::transfer to move the object to  | 
1990  |  |     // another place.  | 
1991  |  |     void erase_meta_only(const_iterator it) { | 
1992  |  |         assert(IsFull(*it.inner_.ctrl_) && "erasing a dangling iterator");  | 
1993  |  |         --size_;  | 
1994  |  |         const size_t index = (size_t)(it.inner_.ctrl_ - ctrl_);  | 
1995  |  |         const size_t index_before = (index - Group::kWidth) & capacity_;  | 
1996  |  |         const auto empty_after = Group(it.inner_.ctrl_).MatchEmpty();  | 
1997  |  |         const auto empty_before = Group(ctrl_ + index_before).MatchEmpty();  | 
1998  |  |  | 
1999  |  |         // We count how many consecutive non empties we have to the right and to the  | 
2000  |  |         // left of `it`. If the sum is >= kWidth then there is at least one probe  | 
2001  |  |         // window that might have seen a full group.  | 
2002  |  |         bool was_never_full =  | 
2003  |  |             empty_before && empty_after &&  | 
2004  |  |             static_cast<size_t>(empty_after.TrailingZeros() +  | 
2005  |  |                                 empty_before.LeadingZeros()) < Group::kWidth;  | 
2006  |  |  | 
2007  |  |         set_ctrl(index, was_never_full ? kEmpty : kDeleted);  | 
2008  |  |         growth_left() += was_never_full;  | 
2009  |  |         infoz_.RecordErase();  | 
2010  |  |     }  | 
2011  |  |  | 
2012  | 3.23k  |     void initialize_slots(size_t new_capacity) { | 
2013  | 3.23k  |         assert(new_capacity);  | 
2014  | 3.23k  |         if (std::is_same<SlotAlloc, std::allocator<slot_type>>::value &&   | 
2015  | 3.23k  |             slots_ == nullptr) { | 
2016  | 691  |             infoz_ = Sample();  | 
2017  | 691  |         }  | 
2018  |  |  | 
2019  | 3.23k  |         auto layout = MakeLayout(new_capacity);  | 
2020  | 3.23k  |         char* mem = static_cast<char*>(  | 
2021  | 3.23k  |             Allocate<Layout::Alignment()>(&alloc_ref(), layout.AllocSize()));  | 
2022  | 3.23k  |         ctrl_ = reinterpret_cast<ctrl_t*>(layout.template Pointer<0>(mem));  | 
2023  | 3.23k  |         slots_ = layout.template Pointer<1>(mem);  | 
2024  | 3.23k  |         reset_ctrl(new_capacity);  | 
2025  | 3.23k  |         reset_growth_left(new_capacity);  | 
2026  | 3.23k  |         infoz_.RecordStorageChanged(size_, new_capacity);  | 
2027  | 3.23k  |     }  | 
2028  |  |  | 
2029  | 2.38k  |     void destroy_slots() { | 
2030  | 2.38k  |         if (!capacity_)  | 
2031  | 1.68k  |             return;  | 
2032  |  |           | 
2033  | 691  |         PHMAP_IF_CONSTEXPR((!std::is_trivially_destructible<typename PolicyTraits::value_type>::value ||  | 
2034  | 691  |                             std::is_same<typename Policy::is_flat, std::false_type>::value)) { | 
2035  |  |             // node map, or not trivially destructible... we  need to iterate and destroy values one by one  | 
2036  |  |             // std::cout << "either this is a node map or " << type_name<typename PolicyTraits::value_type>()  << " is not trivially_destructible\n";  | 
2037  | 0  |             for (size_t i = 0, cnt = capacity_; i != cnt; ++i) { | 
2038  | 0  |                 if (IsFull(ctrl_[i])) { | 
2039  | 0  |                     PolicyTraits::destroy(&alloc_ref(), slots_ + i);  | 
2040  | 0  |                 }  | 
2041  | 0  |             }  | 
2042  | 0  |         }   | 
2043  | 691  |         auto layout = MakeLayout(capacity_);  | 
2044  |  |         // Unpoison before returning the memory to the allocator.  | 
2045  | 691  |         SanitizerUnpoisonMemoryRegion(slots_, sizeof(slot_type) * capacity_);  | 
2046  | 691  |         Deallocate<Layout::Alignment()>(&alloc_ref(), ctrl_, layout.AllocSize());  | 
2047  | 691  |         ctrl_ = EmptyGroup<std_alloc_t>();  | 
2048  | 691  |         slots_ = nullptr;  | 
2049  | 691  |         size_ = 0;  | 
2050  | 691  |         capacity_ = 0;  | 
2051  | 691  |         growth_left() = 0;  | 
2052  | 691  |     } phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::destroy_slots() Line  | Count  | Source  |  2029  | 1.78k  |     void destroy_slots() { |  2030  | 1.78k  |         if (!capacity_)  |  2031  | 1.09k  |             return;  |  2032  |  |           |  2033  | 691  |         PHMAP_IF_CONSTEXPR((!std::is_trivially_destructible<typename PolicyTraits::value_type>::value ||  |  2034  | 691  |                             std::is_same<typename Policy::is_flat, std::false_type>::value)) { |  2035  |  |             // node map, or not trivially destructible... we  need to iterate and destroy values one by one  |  2036  |  |             // std::cout << "either this is a node map or " << type_name<typename PolicyTraits::value_type>()  << " is not trivially_destructible\n";  |  2037  |  |             for (size_t i = 0, cnt = capacity_; i != cnt; ++i) { |  2038  |  |                 if (IsFull(ctrl_[i])) { |  2039  |  |                     PolicyTraits::destroy(&alloc_ref(), slots_ + i);  |  2040  |  |                 }  |  2041  |  |             }  |  2042  |  |         }   |  2043  | 691  |         auto layout = MakeLayout(capacity_);  |  2044  |  |         // Unpoison before returning the memory to the allocator.  |  2045  | 691  |         SanitizerUnpoisonMemoryRegion(slots_, sizeof(slot_type) * capacity_);  |  2046  | 691  |         Deallocate<Layout::Alignment()>(&alloc_ref(), ctrl_, layout.AllocSize());  |  2047  | 691  |         ctrl_ = EmptyGroup<std_alloc_t>();  |  2048  | 691  |         slots_ = nullptr;  |  2049  | 691  |         size_ = 0;  |  2050  | 691  |         capacity_ = 0;  |  2051  | 691  |         growth_left() = 0;  |  2052  | 691  |     }  |  
 phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::destroy_slots() Line  | Count  | Source  |  2029  | 595  |     void destroy_slots() { |  2030  | 595  |         if (!capacity_)  |  2031  | 595  |             return;  |  2032  |  |           |  2033  | 0  |         PHMAP_IF_CONSTEXPR((!std::is_trivially_destructible<typename PolicyTraits::value_type>::value ||  |  2034  | 0  |                             std::is_same<typename Policy::is_flat, std::false_type>::value)) { |  2035  |  |             // node map, or not trivially destructible... we  need to iterate and destroy values one by one  |  2036  |  |             // std::cout << "either this is a node map or " << type_name<typename PolicyTraits::value_type>()  << " is not trivially_destructible\n";  |  2037  | 0  |             for (size_t i = 0, cnt = capacity_; i != cnt; ++i) { |  2038  | 0  |                 if (IsFull(ctrl_[i])) { |  2039  | 0  |                     PolicyTraits::destroy(&alloc_ref(), slots_ + i);  |  2040  | 0  |                 }  |  2041  | 0  |             }  |  2042  | 0  |         }   |  2043  | 0  |         auto layout = MakeLayout(capacity_);  |  2044  |  |         // Unpoison before returning the memory to the allocator.  |  2045  | 0  |         SanitizerUnpoisonMemoryRegion(slots_, sizeof(slot_type) * capacity_);  |  2046  | 0  |         Deallocate<Layout::Alignment()>(&alloc_ref(), ctrl_, layout.AllocSize());  |  2047  | 0  |         ctrl_ = EmptyGroup<std_alloc_t>();  |  2048  | 0  |         slots_ = nullptr;  |  2049  | 0  |         size_ = 0;  |  2050  | 0  |         capacity_ = 0;  |  2051  | 0  |         growth_left() = 0;  |  2052  | 0  |     }  |  
  | 
2053  |  |  | 
2054  | 3.10k  |     void resize(size_t new_capacity) { | 
2055  | 3.10k  |         assert(IsValidCapacity(new_capacity));  | 
2056  | 3.10k  |         auto* old_ctrl = ctrl_;  | 
2057  | 3.10k  |         auto* old_slots = slots_;  | 
2058  | 3.10k  |         const size_t old_capacity = capacity_;  | 
2059  | 3.10k  |         initialize_slots(new_capacity);  | 
2060  | 3.10k  |         capacity_ = new_capacity;  | 
2061  |  |  | 
2062  | 1.12M  |         for (size_t i = 0; i != old_capacity; ++i) { | 
2063  | 1.12M  |             if (IsFull(old_ctrl[i])) { | 
2064  | 984k  |                 size_t hashval = PolicyTraits::apply(HashElement{hash_ref()}, | 
2065  | 984k  |                                                      PolicyTraits::element(old_slots + i));  | 
2066  | 984k  |                 auto target = find_first_non_full(hashval);  | 
2067  | 984k  |                 size_t new_i = target.offset;  | 
2068  | 984k  |                 set_ctrl(new_i, H2(hashval));  | 
2069  | 984k  |                 PolicyTraits::transfer(&alloc_ref(), slots_ + new_i, old_slots + i);  | 
2070  | 984k  |             }  | 
2071  | 1.12M  |         }  | 
2072  | 3.10k  |         if (old_capacity) { | 
2073  | 2.54k  |             SanitizerUnpoisonMemoryRegion(old_slots,  | 
2074  | 2.54k  |                                           sizeof(slot_type) * old_capacity);  | 
2075  | 2.54k  |             auto layout = MakeLayout(old_capacity);  | 
2076  | 2.54k  |             Deallocate<Layout::Alignment()>(&alloc_ref(), old_ctrl,  | 
2077  | 2.54k  |                                             layout.AllocSize());  | 
2078  | 2.54k  |         }  | 
2079  | 3.10k  |     }  | 
2080  |  |  | 
2081  | 0  |     void drop_deletes_without_resize() PHMAP_ATTRIBUTE_NOINLINE { | 
2082  | 0  |         assert(IsValidCapacity(capacity_));  | 
2083  | 0  |         assert(!is_small());  | 
2084  |  |         // Algorithm:  | 
2085  |  |         // - mark all DELETED slots as EMPTY  | 
2086  |  |         // - mark all FULL slots as DELETED  | 
2087  |  |         // - for each slot marked as DELETED  | 
2088  |  |         //     hash = Hash(element)  | 
2089  |  |         //     target = find_first_non_full(hash)  | 
2090  |  |         //     if target is in the same group  | 
2091  |  |         //       mark slot as FULL  | 
2092  |  |         //     else if target is EMPTY  | 
2093  |  |         //       transfer element to target  | 
2094  |  |         //       mark slot as EMPTY  | 
2095  |  |         //       mark target as FULL  | 
2096  |  |         //     else if target is DELETED  | 
2097  |  |         //       swap current element with target element  | 
2098  |  |         //       mark target as FULL  | 
2099  |  |         //       repeat procedure for current slot with moved from element (target)  | 
2100  | 0  |         ConvertDeletedToEmptyAndFullToDeleted(ctrl_, capacity_);  | 
2101  | 0  |         typename phmap::aligned_storage<sizeof(slot_type), alignof(slot_type)>::type  | 
2102  | 0  |             raw;  | 
2103  | 0  |         slot_type* slot = reinterpret_cast<slot_type*>(&raw);  | 
2104  | 0  |         for (size_t i = 0; i != capacity_; ++i) { | 
2105  | 0  |             if (!IsDeleted(ctrl_[i])) continue;  | 
2106  | 0  |             size_t hashval = PolicyTraits::apply(HashElement{hash_ref()}, | 
2107  | 0  |                                                  PolicyTraits::element(slots_ + i));  | 
2108  | 0  |             auto target = find_first_non_full(hashval);  | 
2109  | 0  |             size_t new_i = target.offset;  | 
2110  |  |  | 
2111  |  |             // Verify if the old and new i fall within the same group wrt the hashval.  | 
2112  |  |             // If they do, we don't need to move the object as it falls already in the  | 
2113  |  |             // best probe we can.  | 
2114  | 0  |             const auto probe_index = [&](size_t pos) { | 
2115  | 0  |                 return ((pos - probe(hashval).offset()) & capacity_) / Group::kWidth;  | 
2116  | 0  |             };  | 
2117  |  |  | 
2118  |  |             // Element doesn't move.  | 
2119  | 0  |             if (PHMAP_PREDICT_TRUE(probe_index(new_i) == probe_index(i))) { | 
2120  | 0  |                 set_ctrl(i, H2(hashval));  | 
2121  | 0  |                 continue;  | 
2122  | 0  |             }  | 
2123  | 0  |             if (IsEmpty(ctrl_[new_i])) { | 
2124  |  |                 // Transfer element to the empty spot.  | 
2125  |  |                 // set_ctrl poisons/unpoisons the slots so we have to call it at the  | 
2126  |  |                 // right time.  | 
2127  | 0  |                 set_ctrl(new_i, H2(hashval));  | 
2128  | 0  |                 PolicyTraits::transfer(&alloc_ref(), slots_ + new_i, slots_ + i);  | 
2129  | 0  |                 set_ctrl(i, kEmpty);  | 
2130  | 0  |             } else { | 
2131  | 0  |                 assert(IsDeleted(ctrl_[new_i]));  | 
2132  | 0  |                 set_ctrl(new_i, H2(hashval));  | 
2133  |  |                 // Until we are done rehashing, DELETED marks previously FULL slots.  | 
2134  |  |                 // Swap i and new_i elements.  | 
2135  | 0  |                 PolicyTraits::transfer(&alloc_ref(), slot, slots_ + i);  | 
2136  | 0  |                 PolicyTraits::transfer(&alloc_ref(), slots_ + i, slots_ + new_i);  | 
2137  | 0  |                 PolicyTraits::transfer(&alloc_ref(), slots_ + new_i, slot);  | 
2138  | 0  |                 --i;  // repeat  | 
2139  | 0  |             }  | 
2140  | 0  |         }  | 
2141  | 0  |         reset_growth_left(capacity_);  | 
2142  | 0  |     }  | 
2143  |  |  | 
2144  | 3.10k  |     void rehash_and_grow_if_necessary() { | 
2145  | 3.10k  |         if (capacity_ == 0) { | 
2146  | 558  |             resize(1);  | 
2147  | 2.54k  |         } else if (size() <= CapacityToGrowth(capacity()) / 2) { | 
2148  |  |             // Squash DELETED without growing if there is enough capacity.  | 
2149  | 0  |             drop_deletes_without_resize();  | 
2150  | 2.54k  |         } else { | 
2151  |  |             // Otherwise grow the container.  | 
2152  | 2.54k  |             resize(capacity_ * 2 + 1);  | 
2153  | 2.54k  |         }  | 
2154  | 3.10k  |     }  | 
2155  |  |  | 
2156  | 522k  |     bool has_element(const value_type& PHMAP_RESTRICT elem, size_t hashval) const { | 
2157  | 522k  |         PHMAP_IF_CONSTEXPR (!std_alloc_t::value) { | 
2158  |  |             // ctrl_ could be nullptr  | 
2159  |  |             if (!ctrl_)  | 
2160  |  |                 return false;  | 
2161  |  |         }  | 
2162  | 522k  |         auto seq = probe(hashval);  | 
2163  | 523k  |         while (true) { | 
2164  | 523k  |             Group g{ctrl_ + seq.offset()}; | 
2165  | 524k  |             for (uint32_t i : g.Match((h2_t)H2(hashval))) { | 
2166  | 524k  |                 if (PHMAP_PREDICT_TRUE(PolicyTraits::element(slots_ + seq.offset((size_t)i)) ==  | 
2167  | 524k  |                                       elem))  | 
2168  | 522k  |                     return true;  | 
2169  | 524k  |             }  | 
2170  | 1.45k  |             if (PHMAP_PREDICT_TRUE(g.MatchEmpty())) return false;  | 
2171  | 1.33k  |             seq.next();  | 
2172  | 1.33k  |             assert(seq.getindex() < capacity_ && "full table!");  | 
2173  | 1.33k  |         }  | 
2174  | 0  |         return false;  | 
2175  | 522k  |     }  | 
2176  |  |  | 
2177  | 522k  |     bool has_element(const value_type& elem) const { | 
2178  | 522k  |         size_t hashval = PolicyTraits::apply(HashElement{hash_ref()}, elem); | 
2179  | 522k  |         return has_element(elem, hashval);  | 
2180  | 522k  |     }  | 
2181  |  |  | 
2182  |  |     // Probes the raw_hash_set with the probe sequence for hash and returns the  | 
2183  |  |     // pointer to the first empty or deleted slot.  | 
2184  |  |     // NOTE: this function must work with tables having both kEmpty and kDelete  | 
2185  |  |     // in one group. Such tables appears during drop_deletes_without_resize.  | 
2186  |  |     //  | 
2187  |  |     // This function is very useful when insertions happen and:  | 
2188  |  |     // - the input is already a set  | 
2189  |  |     // - there are enough slots  | 
2190  |  |     // - the element with the hash is not in the table  | 
2191  |  |     struct FindInfo   | 
2192  |  |     { | 
2193  |  |         size_t offset;  | 
2194  |  |         size_t probe_length;  | 
2195  |  |     };  | 
2196  | 1.52M  |     FindInfo find_first_non_full(size_t hashval) { | 
2197  | 1.52M  |         auto seq = probe(hashval);  | 
2198  | 1.61M  |         while (true) { | 
2199  | 1.61M  |             Group g{ctrl_ + seq.offset()}; | 
2200  | 1.61M  |             auto mask = g.MatchEmptyOrDeleted();  | 
2201  | 1.61M  |             if (mask) { | 
2202  | 1.52M  |                 return {seq.offset((size_t)mask.LowestBitSet()), seq.getindex()}; | 
2203  | 1.52M  |             }  | 
2204  | 1.61M  |             assert(seq.getindex() < capacity_ && "full table!");  | 
2205  | 84.8k  |             seq.next();  | 
2206  | 84.8k  |         }  | 
2207  | 1.52M  |     }  | 
2208  |  |  | 
2209  |  |     // TODO(alkis): Optimize this assuming *this and that don't overlap.  | 
2210  |  |     raw_hash_set& move_assign(raw_hash_set&& that, std::true_type) { | 
2211  |  |         raw_hash_set tmp(std::move(that));  | 
2212  |  |         swap(tmp);  | 
2213  |  |         return *this;  | 
2214  |  |     }  | 
2215  |  |     raw_hash_set& move_assign(raw_hash_set&& that, std::false_type) { | 
2216  |  |         raw_hash_set tmp(std::move(that), alloc_ref());  | 
2217  |  |         swap(tmp);  | 
2218  |  |         return *this;  | 
2219  |  |     }  | 
2220  |  |  | 
2221  |  | protected:  | 
2222  |  |     template <class K>  | 
2223  | 11.3M  |     size_t _find_key(const K& PHMAP_RESTRICT key, size_t hashval) { | 
2224  | 11.3M  |         PHMAP_IF_CONSTEXPR (!std_alloc_t::value) { | 
2225  |  |             // ctrl_ could be nullptr  | 
2226  |  |             if (!ctrl_)  | 
2227  |  |                 return (size_t)-1;  | 
2228  |  |         }  | 
2229  | 11.3M  |         auto seq = probe(hashval);  | 
2230  | 12.4M  |         while (true) { | 
2231  | 12.4M  |             Group g{ctrl_ + seq.offset()}; | 
2232  | 13.4M  |             for (uint32_t i : g.Match((h2_t)H2(hashval))) { | 
2233  | 13.4M  |                 if (PHMAP_PREDICT_TRUE(PolicyTraits::apply(  | 
2234  | 13.4M  |                                           EqualElement<K>{key, eq_ref()}, | 
2235  | 13.4M  |                                           PolicyTraits::element(slots_ + seq.offset((size_t)i)))))  | 
2236  | 10.8M  |                     return seq.offset((size_t)i);  | 
2237  | 13.4M  |             }  | 
2238  | 1.62M  |             if (PHMAP_PREDICT_TRUE(g.MatchEmpty())) break;  | 
2239  | 1.08M  |             seq.next();  | 
2240  | 1.08M  |         }  | 
2241  | 538k  |         return (size_t)-1;  | 
2242  | 11.3M  |     }  | 
2243  |  |  | 
2244  |  |     template <class K>  | 
2245  |  |     std::pair<size_t, bool> find_or_prepare_insert(const K& key, size_t hashval) { | 
2246  |  |         size_t offset = _find_key(key, hashval);  | 
2247  |  |         if (offset == (size_t)-1)  | 
2248  |  |             return {prepare_insert(hashval), true}; | 
2249  |  |         return {offset, false}; | 
2250  |  |     }  | 
2251  |  |  | 
2252  | 538k  |     size_t prepare_insert(size_t hashval) PHMAP_ATTRIBUTE_NOINLINE { | 
2253  | 538k  |         PHMAP_IF_CONSTEXPR (!std_alloc_t::value) { | 
2254  |  |             // ctrl_ could be nullptr  | 
2255  |  |             if (!ctrl_)  | 
2256  |  |                 rehash_and_grow_if_necessary();  | 
2257  |  |         }  | 
2258  | 538k  |         FindInfo target = find_first_non_full(hashval);  | 
2259  | 538k  |         if (PHMAP_PREDICT_FALSE(growth_left() == 0 &&  | 
2260  | 538k  |                                !IsDeleted(ctrl_[target.offset]))) { | 
2261  | 3.10k  |             rehash_and_grow_if_necessary();  | 
2262  | 3.10k  |             target = find_first_non_full(hashval);  | 
2263  | 3.10k  |         }  | 
2264  | 538k  |         ++size_;  | 
2265  | 538k  |         growth_left() -= IsEmpty(ctrl_[target.offset]);  | 
2266  |  |         // set_ctrl(target.offset, H2(hashval));  | 
2267  | 538k  |         infoz_.RecordInsert(hashval, target.probe_length);  | 
2268  | 538k  |         return target.offset;  | 
2269  | 538k  |     }  | 
2270  |  |  | 
2271  |  |     // Constructs the value in the space pointed by the iterator. This only works  | 
2272  |  |     // after an unsuccessful find_or_prepare_insert() and before any other  | 
2273  |  |     // modifications happen in the raw_hash_set.  | 
2274  |  |     //  | 
2275  |  |     // PRECONDITION: i is an index returned from find_or_prepare_insert(k), where  | 
2276  |  |     // k is the key decomposed from `forward<Args>(args)...`, and the bool  | 
2277  |  |     // returned by find_or_prepare_insert(k) was true.  | 
2278  |  |     // POSTCONDITION: *m.iterator_at(i) == value_type(forward<Args>(args)...).  | 
2279  |  |     template <class... Args>  | 
2280  | 538k  |     void emplace_at(size_t i, Args&&... args) { | 
2281  | 538k  |         PolicyTraits::construct(&alloc_ref(), slots_ + i,  | 
2282  | 538k  |                                 std::forward<Args>(args)...);  | 
2283  |  |           | 
2284  |  | #ifdef PHMAP_CHECK_CONSTRUCTED_VALUE  | 
2285  |  |         // this check can be costly, so do it only when requested  | 
2286  |  |         assert(PolicyTraits::apply(FindElement{*this}, *iterator_at(i)) == | 
2287  |  |                iterator_at(i) &&  | 
2288  |  |                "constructed value does not match the lookup key");  | 
2289  |  | #endif  | 
2290  | 538k  |     }  | 
2291  |  |  | 
2292  | 11.3M  |     iterator iterator_at(size_t i) { return {ctrl_ + i, slots_ + i}; }phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::iterator_at(unsigned long) Line  | Count  | Source  |  2292  | 11.3M  |     iterator iterator_at(size_t i) { return {ctrl_ + i, slots_ + i}; } |  
 phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::iterator_at(unsigned long) Line  | Count  | Source  |  2292  | 595  |     iterator iterator_at(size_t i) { return {ctrl_ + i, slots_ + i}; } |  
  | 
2293  |  |     const_iterator iterator_at(size_t i) const { return {ctrl_ + i, slots_ + i}; } | 
2294  |  |  | 
2295  |  | protected:  | 
2296  |  |     // Sets the control byte, and if `i < Group::kWidth`, set the cloned byte at  | 
2297  |  |     // the end too.  | 
2298  | 1.52M  |     void set_ctrl(size_t i, ctrl_t h) { | 
2299  | 1.52M  |         assert(i < capacity_);  | 
2300  |  |  | 
2301  | 1.52M  |         if (IsFull(h)) { | 
2302  | 1.52M  |             SanitizerUnpoisonObject(slots_ + i);  | 
2303  | 1.52M  |         } else { | 
2304  | 0  |             SanitizerPoisonObject(slots_ + i);  | 
2305  | 0  |         }  | 
2306  |  |  | 
2307  | 1.52M  |         ctrl_[i] = h;  | 
2308  | 1.52M  |         ctrl_[((i - Group::kWidth) & capacity_) + 1 +  | 
2309  | 1.52M  |               ((Group::kWidth - 1) & capacity_)] = h;  | 
2310  | 1.52M  |     }  | 
2311  |  |  | 
2312  |  | private:  | 
2313  |  |     friend struct RawHashSetTestOnlyAccess;  | 
2314  |  |  | 
2315  | 13.3M  |     probe_seq<Group::kWidth> probe(size_t hashval) const { | 
2316  | 13.3M  |         return probe_seq<Group::kWidth>(H1(hashval, ctrl_), capacity_);  | 
2317  | 13.3M  |     }  | 
2318  |  |  | 
2319  |  |     // Reset all ctrl bytes back to kEmpty, except the sentinel.  | 
2320  | 3.23k  |     void reset_ctrl(size_t new_capacity) { | 
2321  | 3.23k  |         std::memset(ctrl_, kEmpty, new_capacity + Group::kWidth);  | 
2322  | 3.23k  |         ctrl_[new_capacity] = kSentinel;  | 
2323  | 3.23k  |         SanitizerPoisonMemoryRegion(slots_, sizeof(slot_type) * new_capacity);  | 
2324  | 3.23k  |     }  | 
2325  |  |  | 
2326  | 3.23k  |     void reset_growth_left(size_t new_capacity) { | 
2327  | 3.23k  |         growth_left() = CapacityToGrowth(new_capacity) - size_;  | 
2328  | 3.23k  |     }  | 
2329  |  |  | 
2330  | 1.08M  |     size_t& growth_left() { return std::get<0>(settings_); }phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::growth_left() Line  | Count  | Source  |  2330  | 1.08M  |     size_t& growth_left() { return std::get<0>(settings_); } |  
 Unexecuted instantiation: phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::growth_left()  | 
2331  |  |  | 
2332  | 558  |     const size_t& growth_left() const { return std::get<0>(settings_); } | 
2333  |  |  | 
2334  |  |     template <size_t N,  | 
2335  |  |               template <class, class, class, class> class RefSet,  | 
2336  |  |               class M, class P, class H, class E, class A>  | 
2337  |  |     friend class parallel_hash_set;  | 
2338  |  |  | 
2339  |  |     template <size_t N,  | 
2340  |  |               template <class, class, class, class> class RefSet,  | 
2341  |  |               class M, class P, class H, class E, class A>  | 
2342  |  |     friend class parallel_hash_map;  | 
2343  |  |  | 
2344  |  |     // The representation of the object has two modes:  | 
2345  |  |     //  - small: For capacities < kWidth-1  | 
2346  |  |     //  - large: For the rest.  | 
2347  |  |     //  | 
2348  |  |     // Differences:  | 
2349  |  |     //  - In small mode we are able to use the whole capacity. The extra control  | 
2350  |  |     //  bytes give us at least one "empty" control byte to stop the iteration.  | 
2351  |  |     //  This is important to make 1 a valid capacity.  | 
2352  |  |     //  | 
2353  |  |     //  - In small mode only the first `capacity()` control bytes after the  | 
2354  |  |     //  sentinel are valid. The rest contain dummy kEmpty values that do not  | 
2355  |  |     //  represent a real slot. This is important to take into account on  | 
2356  |  |     //  find_first_non_full(), where we never try ShouldInsertBackwards() for  | 
2357  |  |     //  small tables.  | 
2358  | 0  |     bool is_small() const { return capacity_ < Group::kWidth - 1; } | 
2359  |  |  | 
2360  | 986k  |     hasher& hash_ref() { return std::get<1>(settings_); } | 
2361  | 11.8M  |     const hasher& hash_ref() const { return std::get<1>(settings_); } | 
2362  | 13.4M  |     key_equal& eq_ref() { return std::get<2>(settings_); } | 
2363  |  |     const key_equal& eq_ref() const { return std::get<2>(settings_); } | 
2364  | 1.53M  |     allocator_type& alloc_ref() { return std::get<3>(settings_); }phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::alloc_ref() Line  | Count  | Source  |  2364  | 1.53M  |     allocator_type& alloc_ref() { return std::get<3>(settings_); } |  
 Unexecuted instantiation: phmap::priv::raw_hash_set<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::alloc_ref()  | 
2365  |  |     const allocator_type& alloc_ref() const { | 
2366  |  |         return std::get<3>(settings_);  | 
2367  |  |     }  | 
2368  |  |  | 
2369  |  |     // TODO(alkis): Investigate removing some of these fields:  | 
2370  |  |     // - ctrl/slots can be derived from each other  | 
2371  |  |     // - size can be moved into the slot array  | 
2372  |  |     ctrl_t* ctrl_ = EmptyGroup<std_alloc_t>();    // [(capacity + 1) * ctrl_t]  | 
2373  |  |     slot_type* slots_ = nullptr;                  // [capacity * slot_type]  | 
2374  |  |     size_t size_ = 0;                             // number of full slots  | 
2375  |  |     size_t capacity_ = 0;                         // total number of slots  | 
2376  |  |     HashtablezInfoHandle infoz_;  | 
2377  |  |     std::tuple<size_t /* growth_left */, hasher, key_equal, allocator_type>  | 
2378  |  |         settings_{0, hasher{}, key_equal{}, allocator_type{}}; | 
2379  |  | };  | 
2380  |  |  | 
2381  |  |  | 
2382  |  | // --------------------------------------------------------------------------  | 
2383  |  | // --------------------------------------------------------------------------  | 
2384  |  | template <class Policy, class Hash, class Eq, class Alloc>  | 
2385  |  | class raw_hash_map : public raw_hash_set<Policy, Hash, Eq, Alloc>   | 
2386  |  | { | 
2387  |  |     // P is Policy. It's passed as a template argument to support maps that have  | 
2388  |  |     // incomplete types as values, as in unordered_map<K, IncompleteType>.  | 
2389  |  |     // MappedReference<> may be a non-reference type.  | 
2390  |  |     template <class P>  | 
2391  |  |     using MappedReference = decltype(P::value(  | 
2392  |  |                std::addressof(std::declval<typename raw_hash_map::reference>())));  | 
2393  |  |  | 
2394  |  |     // MappedConstReference<> may be a non-reference type.  | 
2395  |  |     template <class P>  | 
2396  |  |     using MappedConstReference = decltype(P::value(  | 
2397  |  |                std::addressof(std::declval<typename raw_hash_map::const_reference>())));  | 
2398  |  |  | 
2399  |  |     using KeyArgImpl =  | 
2400  |  |         KeyArg<IsTransparent<Eq>::value && IsTransparent<Hash>::value>;  | 
2401  |  |  | 
2402  |  |     using Base = raw_hash_set<Policy, Hash, Eq, Alloc>;  | 
2403  |  |  | 
2404  |  | public:  | 
2405  |  |     using key_type = typename Policy::key_type;  | 
2406  |  |     using mapped_type = typename Policy::mapped_type;  | 
2407  |  |     template <class K>  | 
2408  |  |     using key_arg = typename KeyArgImpl::template type<K, key_type>;  | 
2409  |  |  | 
2410  |  |     static_assert(!std::is_reference<key_type>::value, "");  | 
2411  |  |  | 
2412  |  |     // TODO(b/187807849): Evaluate whether to support reference mapped_type and  | 
2413  |  |     // remove this assertion if/when it is supported.  | 
2414  |  |      static_assert(!std::is_reference<mapped_type>::value, "");  | 
2415  |  |  | 
2416  |  |     using iterator = typename raw_hash_map::raw_hash_set::iterator;  | 
2417  |  |     using const_iterator = typename raw_hash_map::raw_hash_set::const_iterator;  | 
2418  |  |  | 
2419  | 1.78k  |     raw_hash_map() {}phmap::priv::raw_hash_map<phmap::priv::FlatHashMapPolicy<unsigned int, int>, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::raw_hash_map() Line  | Count  | Source  |  2419  | 1.19k  |     raw_hash_map() {} |  
 phmap::priv::raw_hash_map<phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::raw_hash_map() Line  | Count  | Source  |  2419  | 595  |     raw_hash_map() {} |  
  | 
2420  |  |     using Base::raw_hash_set; // use raw_hash_set constructor    | 
2421  |  |  | 
2422  |  |     // The last two template parameters ensure that both arguments are rvalues  | 
2423  |  |     // (lvalue arguments are handled by the overloads below). This is necessary  | 
2424  |  |     // for supporting bitfield arguments.  | 
2425  |  |     //  | 
2426  |  |     //   union { int n : 1; }; | 
2427  |  |     //   flat_hash_map<int, int> m;  | 
2428  |  |     //   m.insert_or_assign(n, n);  | 
2429  |  |     template <class K = key_type, class V = mapped_type, K* = nullptr,  | 
2430  |  |               V* = nullptr>  | 
2431  |  |     std::pair<iterator, bool> insert_or_assign(key_arg<K>&& k, V&& v) { | 
2432  |  |         return insert_or_assign_impl(std::forward<K>(k), std::forward<V>(v));  | 
2433  |  |     }  | 
2434  |  |  | 
2435  |  |     template <class K = key_type, class V = mapped_type, K* = nullptr>  | 
2436  |  |     std::pair<iterator, bool> insert_or_assign(key_arg<K>&& k, const V& v) { | 
2437  |  |         return insert_or_assign_impl(std::forward<K>(k), v);  | 
2438  |  |     }  | 
2439  |  |  | 
2440  |  |     template <class K = key_type, class V = mapped_type, V* = nullptr>  | 
2441  |  |     std::pair<iterator, bool> insert_or_assign(const key_arg<K>& k, V&& v) { | 
2442  |  |         return insert_or_assign_impl(k, std::forward<V>(v));  | 
2443  |  |     }  | 
2444  |  |  | 
2445  |  |     template <class K = key_type, class V = mapped_type>  | 
2446  |  |     std::pair<iterator, bool> insert_or_assign(const key_arg<K>& k, const V& v) { | 
2447  |  |         return insert_or_assign_impl(k, v);  | 
2448  |  |     }  | 
2449  |  |  | 
2450  |  |     template <class K = key_type, class V = mapped_type, K* = nullptr,  | 
2451  |  |               V* = nullptr>  | 
2452  |  |     iterator insert_or_assign(const_iterator, key_arg<K>&& k, V&& v) { | 
2453  |  |         return insert_or_assign(std::forward<K>(k), std::forward<V>(v)).first;  | 
2454  |  |     }  | 
2455  |  |  | 
2456  |  |     template <class K = key_type, class V = mapped_type, K* = nullptr>  | 
2457  |  |     iterator insert_or_assign(const_iterator, key_arg<K>&& k, const V& v) { | 
2458  |  |         return insert_or_assign(std::forward<K>(k), v).first;  | 
2459  |  |     }  | 
2460  |  |  | 
2461  |  |     template <class K = key_type, class V = mapped_type, V* = nullptr>  | 
2462  |  |     iterator insert_or_assign(const_iterator, const key_arg<K>& k, V&& v) { | 
2463  |  |         return insert_or_assign(k, std::forward<V>(v)).first;  | 
2464  |  |     }  | 
2465  |  |  | 
2466  |  |     template <class K = key_type, class V = mapped_type>  | 
2467  |  |     iterator insert_or_assign(const_iterator, const key_arg<K>& k, const V& v) { | 
2468  |  |         return insert_or_assign(k, v).first;  | 
2469  |  |     }  | 
2470  |  |  | 
2471  |  |     template <class K = key_type, class... Args,  | 
2472  |  |               typename std::enable_if<  | 
2473  |  |                   !std::is_convertible<K, const_iterator>::value, int>::type = 0,  | 
2474  |  |               K* = nullptr>  | 
2475  |  |     std::pair<iterator, bool> try_emplace(key_arg<K>&& k, Args&&... args) { | 
2476  |  |         return try_emplace_impl(std::forward<K>(k), std::forward<Args>(args)...);  | 
2477  |  |     }  | 
2478  |  |  | 
2479  |  |     template <class K = key_type, class... Args,  | 
2480  |  |               typename std::enable_if<  | 
2481  |  |                   !std::is_convertible<K, const_iterator>::value, int>::type = 0>  | 
2482  |  |     std::pair<iterator, bool> try_emplace(const key_arg<K>& k, Args&&... args) { | 
2483  |  |         return try_emplace_impl(k, std::forward<Args>(args)...);  | 
2484  |  |     }  | 
2485  |  |  | 
2486  |  |     template <class K = key_type, class... Args, K* = nullptr>  | 
2487  |  |     iterator try_emplace(const_iterator, key_arg<K>&& k, Args&&... args) { | 
2488  |  |         return try_emplace(std::forward<K>(k), std::forward<Args>(args)...).first;  | 
2489  |  |     }  | 
2490  |  |  | 
2491  |  |     template <class K = key_type, class... Args>  | 
2492  |  |     iterator try_emplace(const_iterator, const key_arg<K>& k, Args&&... args) { | 
2493  |  |         return try_emplace(k, std::forward<Args>(args)...).first;  | 
2494  |  |     }  | 
2495  |  |  | 
2496  |  |     template <class K = key_type, class P = Policy>  | 
2497  |  |     MappedReference<P> at(const key_arg<K>& key) { | 
2498  |  |         auto it = this->find(key);  | 
2499  |  |         if (it == this->end())   | 
2500  |  |             phmap::base_internal::ThrowStdOutOfRange("phmap at(): lookup non-existent key"); | 
2501  |  |         return Policy::value(&*it);  | 
2502  |  |     }  | 
2503  |  |  | 
2504  |  |     template <class K = key_type, class P = Policy>  | 
2505  |  |     MappedConstReference<P> at(const key_arg<K>& key) const { | 
2506  |  |         auto it = this->find(key);  | 
2507  |  |         if (it == this->end())  | 
2508  |  |             phmap::base_internal::ThrowStdOutOfRange("phmap at(): lookup non-existent key"); | 
2509  |  |         return Policy::value(&*it);  | 
2510  |  |     }  | 
2511  |  |  | 
2512  |  |     template <class K = key_type, class P = Policy, K* = nullptr>  | 
2513  |  |     MappedReference<P> operator[](key_arg<K>&& key) { | 
2514  |  |         return Policy::value(&*try_emplace(std::forward<K>(key)).first);  | 
2515  |  |     }  | 
2516  |  |  | 
2517  |  |     template <class K = key_type, class P = Policy>  | 
2518  |  |     MappedReference<P> operator[](const key_arg<K>& key) { | 
2519  |  |         return Policy::value(&*try_emplace(key).first);  | 
2520  |  |     }  | 
2521  |  |  | 
2522  |  | private:  | 
2523  |  |     template <class K, class V>  | 
2524  |  |     std::pair<iterator, bool> insert_or_assign_impl(K&& k, V&& v) { | 
2525  |  |         size_t hashval = this->hash(k);  | 
2526  |  |         size_t offset = this->_find_key(k, hashval);  | 
2527  |  |         if (offset == (size_t)-1) { | 
2528  |  |             offset = this->prepare_insert(hashval);  | 
2529  |  |             this->emplace_at(offset, std::forward<K>(k), std::forward<V>(v));  | 
2530  |  |             this->set_ctrl(offset, H2(hashval));  | 
2531  |  |             return {this->iterator_at(offset), true}; | 
2532  |  |         }   | 
2533  |  |         Policy::value(&*this->iterator_at(offset)) = std::forward<V>(v);  | 
2534  |  |         return {this->iterator_at(offset), false}; | 
2535  |  |     }  | 
2536  |  |  | 
2537  |  |     template <class K = key_type, class... Args>  | 
2538  |  |     std::pair<iterator, bool> try_emplace_impl(K&& k, Args&&... args) { | 
2539  |  |         size_t hashval = this->hash(k);  | 
2540  |  |         size_t offset = this->_find_key(k, hashval);  | 
2541  |  |         if (offset == (size_t)-1) { | 
2542  |  |             offset = this->prepare_insert(hashval);  | 
2543  |  |             this->emplace_at(offset, std::piecewise_construct,  | 
2544  |  |                              std::forward_as_tuple(std::forward<K>(k)),  | 
2545  |  |                              std::forward_as_tuple(std::forward<Args>(args)...));  | 
2546  |  |             this->set_ctrl(offset, H2(hashval));  | 
2547  |  |             return {this->iterator_at(offset), true}; | 
2548  |  |         }  | 
2549  |  |         return {this->iterator_at(offset), false}; | 
2550  |  |     }  | 
2551  |  | };  | 
2552  |  |  | 
2553  |  | // ----------------------------------------------------------------------------  | 
2554  |  | // ----------------------------------------------------------------------------  | 
2555  |  | // Returns "random" seed.  | 
2556  |  | inline size_t RandomSeed()   | 
2557  | 0  | { | 
2558  | 0  | #if PHMAP_HAVE_THREAD_LOCAL  | 
2559  | 0  |     static thread_local size_t counter = 0;  | 
2560  | 0  |     size_t value = ++counter;  | 
2561  | 0  | #else   // PHMAP_HAVE_THREAD_LOCAL  | 
2562  | 0  |     static std::atomic<size_t> counter(0);  | 
2563  | 0  |     size_t value = counter.fetch_add(1, std::memory_order_relaxed);  | 
2564  | 0  | #endif  // PHMAP_HAVE_THREAD_LOCAL  | 
2565  | 0  |     return value ^ static_cast<size_t>(reinterpret_cast<uintptr_t>(&counter));  | 
2566  | 0  | }  | 
2567  |  |  | 
2568  |  | // ----------------------------------------------------------------------------  | 
2569  |  | // ----------------------------------------------------------------------------  | 
2570  |  | template <size_t N,  | 
2571  |  |           template <class, class, class, class> class RefSet,  | 
2572  |  |           class Mtx_,  | 
2573  |  |           class Policy, class Hash, class Eq, class Alloc>  | 
2574  |  | class parallel_hash_set   | 
2575  |  | { | 
2576  |  |     using PolicyTraits = hash_policy_traits<Policy>;  | 
2577  |  |     using KeyArgImpl =  | 
2578  |  |         KeyArg<IsTransparent<Eq>::value && IsTransparent<Hash>::value>;  | 
2579  |  |  | 
2580  |  |     static_assert(N <= 12, "N = 12 means 4096 hash tables!");  | 
2581  |  |     constexpr static size_t num_tables = 1 << N;  | 
2582  |  |     constexpr static size_t mask = num_tables - 1;  | 
2583  |  |  | 
2584  |  | public:  | 
2585  |  |     using EmbeddedSet     = RefSet<Policy, Hash, Eq, Alloc>;  | 
2586  |  |     using EmbeddedIterator= typename EmbeddedSet::iterator;  | 
2587  |  |     using EmbeddedConstIterator= typename EmbeddedSet::const_iterator;  | 
2588  |  |     using constructor     = typename EmbeddedSet::constructor;  | 
2589  |  |     using init_type       = typename PolicyTraits::init_type;  | 
2590  |  |     using key_type        = typename PolicyTraits::key_type;  | 
2591  |  |     using slot_type       = typename PolicyTraits::slot_type;  | 
2592  |  |     using allocator_type  = Alloc;  | 
2593  |  |     using size_type       = size_t;  | 
2594  |  |     using difference_type = ptrdiff_t;  | 
2595  |  |     using hasher          = Hash;  | 
2596  |  |     using key_equal       = Eq;  | 
2597  |  |     using policy_type     = Policy;  | 
2598  |  |     using value_type      = typename PolicyTraits::value_type;  | 
2599  |  |     using reference       = value_type&;  | 
2600  |  |     using const_reference = const value_type&;  | 
2601  |  |     using pointer         = typename phmap::allocator_traits<  | 
2602  |  |         allocator_type>::template rebind_traits<value_type>::pointer;  | 
2603  |  |     using const_pointer   = typename phmap::allocator_traits<  | 
2604  |  |         allocator_type>::template rebind_traits<value_type>::const_pointer;  | 
2605  |  |  | 
2606  |  |     // Alias used for heterogeneous lookup functions.  | 
2607  |  |     // `key_arg<K>` evaluates to `K` when the functors are transparent and to  | 
2608  |  |     // `key_type` otherwise. It permits template argument deduction on `K` for the  | 
2609  |  |     // transparent case.  | 
2610  |  |     // --------------------------------------------------------------------  | 
2611  |  |     template <class K>  | 
2612  |  |     using key_arg         = typename KeyArgImpl::template type<K, key_type>;  | 
2613  |  |  | 
2614  |  | protected:  | 
2615  |  |     using Lockable      = phmap::LockableImpl<Mtx_>;  | 
2616  |  |     using UniqueLock    = typename Lockable::UniqueLock;  | 
2617  |  |     using SharedLock    = typename Lockable::SharedLock;  | 
2618  |  |     using ReadWriteLock = typename Lockable::ReadWriteLock;  | 
2619  |  |  | 
2620  |  |     // --------------------------------------------------------------------  | 
2621  |  |     struct Inner : public Lockable  | 
2622  |  |     { | 
2623  |  |         struct Params  | 
2624  |  |         { | 
2625  |  |             size_t bucket_cnt;  | 
2626  |  |             const hasher& hashfn;  | 
2627  |  |             const key_equal& eq;  | 
2628  |  |             const allocator_type& alloc;  | 
2629  |  |         };  | 
2630  |  |  | 
2631  |  |         Inner() {} | 
2632  |  |  | 
2633  |  |         Inner(Params const &p) : set_(p.bucket_cnt, p.hashfn, p.eq, p.alloc)  | 
2634  |  |         {} | 
2635  |  |  | 
2636  |  |         bool operator==(const Inner& o) const  | 
2637  |  |         { | 
2638  |  |             typename Lockable::SharedLocks l(const_cast<Inner &>(*this), const_cast<Inner &>(o));  | 
2639  |  |             return set_ == o.set_;  | 
2640  |  |         }  | 
2641  |  |  | 
2642  |  |         EmbeddedSet set_;  | 
2643  |  |     };  | 
2644  |  |  | 
2645  |  | private:  | 
2646  |  |     // Give an early error when key_type is not hashable/eq.  | 
2647  |  |     // --------------------------------------------------------------------  | 
2648  |  |     auto KeyTypeCanBeHashed(const Hash& h, const key_type& k) -> decltype(h(k));  | 
2649  |  |     auto KeyTypeCanBeEq(const Eq& eq, const key_type& k)      -> decltype(eq(k, k));  | 
2650  |  |  | 
2651  |  |     using AllocTraits     = phmap::allocator_traits<allocator_type>;  | 
2652  |  |  | 
2653  |  |     static_assert(std::is_lvalue_reference<reference>::value,  | 
2654  |  |                   "Policy::element() must return a reference");  | 
2655  |  |  | 
2656  |  |     template <typename T>  | 
2657  |  |     struct SameAsElementReference : std::is_same<  | 
2658  |  |         typename std::remove_cv<typename std::remove_reference<reference>::type>::type,  | 
2659  |  |         typename std::remove_cv<typename std::remove_reference<T>::type>::type> {}; | 
2660  |  |  | 
2661  |  |     // An enabler for insert(T&&): T must be convertible to init_type or be the  | 
2662  |  |     // same as [cv] value_type [ref].  | 
2663  |  |     // Note: we separate SameAsElementReference into its own type to avoid using  | 
2664  |  |     // reference unless we need to. MSVC doesn't seem to like it in some  | 
2665  |  |     // cases.  | 
2666  |  |     // --------------------------------------------------------------------  | 
2667  |  |     template <class T>  | 
2668  |  |     using RequiresInsertable = typename std::enable_if<  | 
2669  |  |         phmap::disjunction<std::is_convertible<T, init_type>, SameAsElementReference<T>>::value, int>::type;  | 
2670  |  |  | 
2671  |  |     // RequiresNotInit is a workaround for gcc prior to 7.1.  | 
2672  |  |     // See https://godbolt.org/g/Y4xsUh.  | 
2673  |  |     template <class T>  | 
2674  |  |     using RequiresNotInit =  | 
2675  |  |         typename std::enable_if<!std::is_same<T, init_type>::value, int>::type;  | 
2676  |  |  | 
2677  |  |     template <class... Ts>  | 
2678  |  |     using IsDecomposable = IsDecomposable<void, PolicyTraits, Hash, Eq, Ts...>;  | 
2679  |  |  | 
2680  |  | public:  | 
2681  |  |     static_assert(std::is_same<pointer, value_type*>::value,  | 
2682  |  |                   "Allocators with custom pointer types are not supported");  | 
2683  |  |     static_assert(std::is_same<const_pointer, const value_type*>::value,  | 
2684  |  |                   "Allocators with custom pointer types are not supported");  | 
2685  |  |  | 
2686  |  |     // --------------------- i t e r a t o r ------------------------------  | 
2687  |  |     class iterator   | 
2688  |  |     { | 
2689  |  |         friend class parallel_hash_set;  | 
2690  |  |  | 
2691  |  |     public:  | 
2692  |  |         using iterator_category = std::forward_iterator_tag;  | 
2693  |  |         using value_type        = typename parallel_hash_set::value_type;  | 
2694  |  |         using reference         =  | 
2695  |  |             phmap::conditional_t<PolicyTraits::constant_iterators::value,  | 
2696  |  |                                 const value_type&, value_type&>;  | 
2697  |  |         using pointer           = phmap::remove_reference_t<reference>*;  | 
2698  |  |         using difference_type   = typename parallel_hash_set::difference_type;  | 
2699  |  |         using Inner             = typename parallel_hash_set::Inner;  | 
2700  |  |         using EmbeddedSet       = typename parallel_hash_set::EmbeddedSet;  | 
2701  |  |         using EmbeddedIterator  = typename EmbeddedSet::iterator;  | 
2702  |  |  | 
2703  |  |         iterator() {} | 
2704  |  |  | 
2705  |  |         reference operator*()  const { return *it_; } | 
2706  |  |         pointer   operator->() const { return &operator*(); } | 
2707  |  |  | 
2708  |  |         iterator& operator++() { | 
2709  |  |             assert(inner_); // null inner means we are already at the end  | 
2710  |  |             ++it_;  | 
2711  |  |             skip_empty();  | 
2712  |  |             return *this;  | 
2713  |  |         }  | 
2714  |  |       | 
2715  |  |         iterator operator++(int) { | 
2716  |  |             assert(inner_);  // null inner means we are already at the end  | 
2717  |  |             auto tmp = *this;  | 
2718  |  |             ++*this;  | 
2719  |  |             return tmp;  | 
2720  |  |         }  | 
2721  |  |  | 
2722  |  |         friend bool operator==(const iterator& a, const iterator& b) { | 
2723  |  |             return a.inner_ == b.inner_ && (!a.inner_ || a.it_ == b.it_);  | 
2724  |  |         }  | 
2725  |  |  | 
2726  |  |         friend bool operator!=(const iterator& a, const iterator& b) { | 
2727  |  |             return !(a == b);  | 
2728  |  |         }  | 
2729  |  |  | 
2730  |  |     private:  | 
2731  |  |         iterator(Inner *inner, Inner *inner_end, const EmbeddedIterator& it) :   | 
2732  |  |             inner_(inner), inner_end_(inner_end), it_(it)  {  // for begin() and end() | 
2733  |  |             if (inner)  | 
2734  |  |                 it_end_ = inner->set_.end();  | 
2735  |  |         }  | 
2736  |  |  | 
2737  |  |         void skip_empty() { | 
2738  |  |             while (it_ == it_end_) { | 
2739  |  |                 ++inner_;  | 
2740  |  |                 if (inner_ == inner_end_) { | 
2741  |  |                     inner_ = nullptr; // marks end()  | 
2742  |  |                     break;  | 
2743  |  |                 }  | 
2744  |  |                 else { | 
2745  |  |                     it_ = inner_->set_.begin();  | 
2746  |  |                     it_end_ = inner_->set_.end();  | 
2747  |  |                 }  | 
2748  |  |             }  | 
2749  |  |         }  | 
2750  |  |  | 
2751  |  |         Inner *inner_      = nullptr;  | 
2752  |  |         Inner *inner_end_  = nullptr;  | 
2753  |  |         EmbeddedIterator it_, it_end_;  | 
2754  |  |     };  | 
2755  |  |  | 
2756  |  |     // --------------------- c o n s t   i t e r a t o r -----------------  | 
2757  |  |     class const_iterator   | 
2758  |  |     { | 
2759  |  |         friend class parallel_hash_set;  | 
2760  |  |  | 
2761  |  |     public:  | 
2762  |  |         using iterator_category = typename iterator::iterator_category;  | 
2763  |  |         using value_type        = typename parallel_hash_set::value_type;  | 
2764  |  |         using reference         = typename parallel_hash_set::const_reference;  | 
2765  |  |         using pointer           = typename parallel_hash_set::const_pointer;  | 
2766  |  |         using difference_type   = typename parallel_hash_set::difference_type;  | 
2767  |  |         using Inner             = typename parallel_hash_set::Inner;  | 
2768  |  |  | 
2769  |  |         const_iterator() {} | 
2770  |  |         // Implicit construction from iterator.  | 
2771  |  |         const_iterator(iterator i) : iter_(std::move(i)) {} | 
2772  |  |  | 
2773  |  |         reference operator*()  const { return *(iter_); } | 
2774  |  |         pointer   operator->() const { return iter_.operator->(); } | 
2775  |  |  | 
2776  |  |         const_iterator& operator++() { | 
2777  |  |             ++iter_;  | 
2778  |  |             return *this;  | 
2779  |  |         }  | 
2780  |  |         const_iterator operator++(int) { return iter_++; } | 
2781  |  |  | 
2782  |  |         friend bool operator==(const const_iterator& a, const const_iterator& b) { | 
2783  |  |             return a.iter_ == b.iter_;  | 
2784  |  |         }  | 
2785  |  |         friend bool operator!=(const const_iterator& a, const const_iterator& b) { | 
2786  |  |             return !(a == b);  | 
2787  |  |         }  | 
2788  |  |  | 
2789  |  |     private:  | 
2790  |  |         const_iterator(const Inner *inner, const Inner *inner_end, const EmbeddedIterator& it)  | 
2791  |  |             : iter_(const_cast<Inner**>(inner),   | 
2792  |  |                     const_cast<Inner**>(inner_end),  | 
2793  |  |                     const_cast<EmbeddedIterator*>(it)) {} | 
2794  |  |  | 
2795  |  |         iterator iter_;  | 
2796  |  |     };  | 
2797  |  |  | 
2798  |  |     using node_type = node_handle<Policy, hash_policy_traits<Policy>, Alloc>;  | 
2799  |  |     using insert_return_type = InsertReturnType<iterator, node_type>;  | 
2800  |  |  | 
2801  |  |     // ------------------------- c o n s t r u c t o r s ------------------  | 
2802  |  |  | 
2803  |  |     parallel_hash_set() noexcept(  | 
2804  |  |         std::is_nothrow_default_constructible<hasher>::value&&  | 
2805  |  |         std::is_nothrow_default_constructible<key_equal>::value&&  | 
2806  |  |         std::is_nothrow_default_constructible<allocator_type>::value) {} | 
2807  |  |  | 
2808  |  | #if  (__cplusplus >= 201703L || _MSVC_LANG >= 201402) && (defined(_MSC_VER) || defined(__clang__) || (defined(__GNUC__) && __GNUC__ > 6))  | 
2809  |  |     explicit parallel_hash_set(size_t bucket_cnt,   | 
2810  |  |                                const hasher& hash_param    = hasher(),  | 
2811  |  |                                const key_equal& eq         = key_equal(),  | 
2812  |  |                                const allocator_type& alloc = allocator_type()) :  | 
2813  |  |         parallel_hash_set(typename Inner::Params{bucket_cnt, hash_param, eq, alloc},  | 
2814  |  |                           phmap::make_index_sequence<num_tables>{}) | 
2815  |  |     {} | 
2816  |  |  | 
2817  |  |     template <std::size_t... i>  | 
2818  |  |     parallel_hash_set(typename Inner::Params const &p,  | 
2819  |  |                       phmap::index_sequence<i...>) : sets_{((void)i, p)...} | 
2820  |  |     {} | 
2821  |  | #else  | 
2822  |  |     explicit parallel_hash_set(size_t bucket_cnt,   | 
2823  |  |                                const hasher& hash_param    = hasher(),  | 
2824  |  |                                const key_equal& eq         = key_equal(),  | 
2825  |  |                                const allocator_type& alloc = allocator_type()) { | 
2826  |  |         for (auto& inner : sets_)  | 
2827  |  |             inner.set_ = EmbeddedSet(bucket_cnt / N, hash_param, eq, alloc);  | 
2828  |  |     }  | 
2829  |  | #endif  | 
2830  |  |  | 
2831  |  |     parallel_hash_set(size_t bucket_cnt,   | 
2832  |  |                       const hasher& hash_param,  | 
2833  |  |                       const allocator_type& alloc)  | 
2834  |  |         : parallel_hash_set(bucket_cnt, hash_param, key_equal(), alloc) {} | 
2835  |  |  | 
2836  |  |     parallel_hash_set(size_t bucket_cnt, const allocator_type& alloc)  | 
2837  |  |         : parallel_hash_set(bucket_cnt, hasher(), key_equal(), alloc) {} | 
2838  |  |  | 
2839  |  |     explicit parallel_hash_set(const allocator_type& alloc)  | 
2840  |  |         : parallel_hash_set(0, hasher(), key_equal(), alloc) {} | 
2841  |  |  | 
2842  |  |     template <class InputIter>  | 
2843  |  |     parallel_hash_set(InputIter first, InputIter last, size_t bucket_cnt = 0,  | 
2844  |  |                       const hasher& hash_param = hasher(), const key_equal& eq = key_equal(),  | 
2845  |  |                       const allocator_type& alloc = allocator_type())  | 
2846  |  |         : parallel_hash_set(bucket_cnt, hash_param, eq, alloc) { | 
2847  |  |         insert(first, last);  | 
2848  |  |     }  | 
2849  |  |  | 
2850  |  |     template <class InputIter>  | 
2851  |  |     parallel_hash_set(InputIter first, InputIter last, size_t bucket_cnt,  | 
2852  |  |                       const hasher& hash_param, const allocator_type& alloc)  | 
2853  |  |         : parallel_hash_set(first, last, bucket_cnt, hash_param, key_equal(), alloc) {} | 
2854  |  |  | 
2855  |  |     template <class InputIter>  | 
2856  |  |     parallel_hash_set(InputIter first, InputIter last, size_t bucket_cnt,  | 
2857  |  |                       const allocator_type& alloc)  | 
2858  |  |         : parallel_hash_set(first, last, bucket_cnt, hasher(), key_equal(), alloc) {} | 
2859  |  |  | 
2860  |  |     template <class InputIter>  | 
2861  |  |     parallel_hash_set(InputIter first, InputIter last, const allocator_type& alloc)  | 
2862  |  |         : parallel_hash_set(first, last, 0, hasher(), key_equal(), alloc) {} | 
2863  |  |  | 
2864  |  |     // Instead of accepting std::initializer_list<value_type> as the first  | 
2865  |  |     // argument like std::unordered_set<value_type> does, we have two overloads  | 
2866  |  |     // that accept std::initializer_list<T> and std::initializer_list<init_type>.  | 
2867  |  |     // This is advantageous for performance.  | 
2868  |  |     //  | 
2869  |  |     //   // Turns {"abc", "def"} into std::initializer_list<std::string>, then copies | 
2870  |  |     //   // the strings into the set.  | 
2871  |  |     //   std::unordered_set<std::string> s = {"abc", "def"}; | 
2872  |  |     //  | 
2873  |  |     //   // Turns {"abc", "def"} into std::initializer_list<const char*>, then | 
2874  |  |     //   // copies the strings into the set.  | 
2875  |  |     //   phmap::flat_hash_set<std::string> s = {"abc", "def"}; | 
2876  |  |     //  | 
2877  |  |     // The same trick is used in insert().  | 
2878  |  |     //  | 
2879  |  |     // The enabler is necessary to prevent this constructor from triggering where  | 
2880  |  |     // the copy constructor is meant to be called.  | 
2881  |  |     //  | 
2882  |  |     //   phmap::flat_hash_set<int> a, b{a}; | 
2883  |  |     //  | 
2884  |  |     // RequiresNotInit<T> is a workaround for gcc prior to 7.1.  | 
2885  |  |     // --------------------------------------------------------------------  | 
2886  |  |     template <class T, RequiresNotInit<T> = 0, RequiresInsertable<T> = 0>  | 
2887  |  |     parallel_hash_set(std::initializer_list<T> init, size_t bucket_cnt = 0,  | 
2888  |  |                       const hasher& hash_param = hasher(), const key_equal& eq = key_equal(),  | 
2889  |  |                       const allocator_type& alloc = allocator_type())  | 
2890  |  |         : parallel_hash_set(init.begin(), init.end(), bucket_cnt, hash_param, eq, alloc) {} | 
2891  |  |  | 
2892  |  |     parallel_hash_set(std::initializer_list<init_type> init, size_t bucket_cnt = 0,  | 
2893  |  |                       const hasher& hash_param = hasher(), const key_equal& eq = key_equal(),  | 
2894  |  |                       const allocator_type& alloc = allocator_type())  | 
2895  |  |         : parallel_hash_set(init.begin(), init.end(), bucket_cnt, hash_param, eq, alloc) {} | 
2896  |  |  | 
2897  |  |     template <class T, RequiresNotInit<T> = 0, RequiresInsertable<T> = 0>  | 
2898  |  |     parallel_hash_set(std::initializer_list<T> init, size_t bucket_cnt,  | 
2899  |  |                       const hasher& hash_param, const allocator_type& alloc)  | 
2900  |  |         : parallel_hash_set(init, bucket_cnt, hash_param, key_equal(), alloc) {} | 
2901  |  |  | 
2902  |  |     parallel_hash_set(std::initializer_list<init_type> init, size_t bucket_cnt,  | 
2903  |  |                       const hasher& hash_param, const allocator_type& alloc)  | 
2904  |  |         : parallel_hash_set(init, bucket_cnt, hash_param, key_equal(), alloc) {} | 
2905  |  |  | 
2906  |  |     template <class T, RequiresNotInit<T> = 0, RequiresInsertable<T> = 0>  | 
2907  |  |     parallel_hash_set(std::initializer_list<T> init, size_t bucket_cnt,  | 
2908  |  |                       const allocator_type& alloc)  | 
2909  |  |         : parallel_hash_set(init, bucket_cnt, hasher(), key_equal(), alloc) {} | 
2910  |  |  | 
2911  |  |     parallel_hash_set(std::initializer_list<init_type> init, size_t bucket_cnt,  | 
2912  |  |                       const allocator_type& alloc)  | 
2913  |  |         : parallel_hash_set(init, bucket_cnt, hasher(), key_equal(), alloc) {} | 
2914  |  |  | 
2915  |  |     template <class T, RequiresNotInit<T> = 0, RequiresInsertable<T> = 0>  | 
2916  |  |     parallel_hash_set(std::initializer_list<T> init, const allocator_type& alloc)  | 
2917  |  |         : parallel_hash_set(init, 0, hasher(), key_equal(), alloc) {} | 
2918  |  |     | 
2919  |  |     parallel_hash_set(std::initializer_list<init_type> init,  | 
2920  |  |                       const allocator_type& alloc)  | 
2921  |  |         : parallel_hash_set(init, 0, hasher(), key_equal(), alloc) {} | 
2922  |  |  | 
2923  |  |     parallel_hash_set(const parallel_hash_set& that)  | 
2924  |  |         : parallel_hash_set(that, AllocTraits::select_on_container_copy_construction(  | 
2925  |  |                                 that.alloc_ref())) {} | 
2926  |  |  | 
2927  |  |     parallel_hash_set(const parallel_hash_set& that, const allocator_type& a)  | 
2928  |  |         : parallel_hash_set(0, that.hash_ref(), that.eq_ref(), a) { | 
2929  |  |         for (size_t i=0; i<num_tables; ++i)  | 
2930  |  |             sets_[i].set_ = { that.sets_[i].set_, a }; | 
2931  |  |     }  | 
2932  |  |     | 
2933  |  |     parallel_hash_set(parallel_hash_set&& that) noexcept(  | 
2934  |  |         std::is_nothrow_copy_constructible<hasher>::value&&  | 
2935  |  |         std::is_nothrow_copy_constructible<key_equal>::value&&  | 
2936  |  |         std::is_nothrow_copy_constructible<allocator_type>::value)  | 
2937  |  |         : parallel_hash_set(std::move(that), that.alloc_ref()) { | 
2938  |  |     }  | 
2939  |  |  | 
2940  |  |     parallel_hash_set(parallel_hash_set&& that, const allocator_type& a)  | 
2941  |  |     { | 
2942  |  |         for (size_t i=0; i<num_tables; ++i)  | 
2943  |  |             sets_[i].set_ = { std::move(that.sets_[i]).set_, a }; | 
2944  |  |     }  | 
2945  |  |  | 
2946  |  |     parallel_hash_set& operator=(const parallel_hash_set& that) { | 
2947  |  |         for (size_t i=0; i<num_tables; ++i)  | 
2948  |  |             sets_[i].set_ = that.sets_[i].set_;  | 
2949  |  |         return *this;  | 
2950  |  |     }  | 
2951  |  |  | 
2952  |  |     parallel_hash_set& operator=(parallel_hash_set&& that) noexcept(  | 
2953  |  |         phmap::allocator_traits<allocator_type>::is_always_equal::value &&  | 
2954  |  |         std::is_nothrow_move_assignable<hasher>::value &&  | 
2955  |  |         std::is_nothrow_move_assignable<key_equal>::value) { | 
2956  |  |         for (size_t i=0; i<num_tables; ++i)  | 
2957  |  |             sets_[i].set_ = std::move(that.sets_[i].set_);  | 
2958  |  |         return *this;  | 
2959  |  |     }  | 
2960  |  |  | 
2961  |  |     ~parallel_hash_set() {} | 
2962  |  |  | 
2963  |  |     iterator begin() { | 
2964  |  |         auto it = iterator(&sets_[0], &sets_[0] + num_tables, sets_[0].set_.begin());  | 
2965  |  |         it.skip_empty();  | 
2966  |  |         return it;  | 
2967  |  |     }  | 
2968  |  |  | 
2969  |  |     iterator       end()          { return iterator(); } | 
2970  |  |     const_iterator begin()  const { return const_cast<parallel_hash_set *>(this)->begin(); } | 
2971  |  |     const_iterator end()    const { return const_cast<parallel_hash_set *>(this)->end(); } | 
2972  |  |     const_iterator cbegin() const { return begin(); } | 
2973  |  |     const_iterator cend()   const { return end(); } | 
2974  |  |  | 
2975  |  |     bool empty() const { return !size(); } | 
2976  |  |  | 
2977  |  |     size_t size() const {  | 
2978  |  |         size_t sz = 0;  | 
2979  |  |         for (const auto& inner : sets_)  | 
2980  |  |             sz += inner.set_.size();  | 
2981  |  |         return sz;   | 
2982  |  |     }  | 
2983  |  |     | 
2984  |  |     size_t capacity() const {  | 
2985  |  |         size_t c = 0;  | 
2986  |  |         for (const auto& inner : sets_)  | 
2987  |  |             c += inner.set_.capacity();  | 
2988  |  |         return c;   | 
2989  |  |     }  | 
2990  |  |  | 
2991  |  |     size_t max_size() const { return (std::numeric_limits<size_t>::max)(); } | 
2992  |  |  | 
2993  |  |     PHMAP_ATTRIBUTE_REINITIALIZES void clear() { | 
2994  |  |         for (auto& inner : sets_)  | 
2995  |  |         { | 
2996  |  |             UniqueLock m(inner);  | 
2997  |  |             inner.set_.clear();  | 
2998  |  |         }  | 
2999  |  |     }  | 
3000  |  |  | 
3001  |  |     // extension - clears only soecified submap  | 
3002  |  |     // ----------------------------------------  | 
3003  |  |     void clear(std::size_t submap_index) { | 
3004  |  |         Inner& inner = sets_[submap_index];  | 
3005  |  |         UniqueLock m(inner);  | 
3006  |  |         inner.set_.clear();  | 
3007  |  |     }  | 
3008  |  |  | 
3009  |  |     // This overload kicks in when the argument is an rvalue of insertable and  | 
3010  |  |     // decomposable type other than init_type.  | 
3011  |  |     //  | 
3012  |  |     //   flat_hash_map<std::string, int> m;  | 
3013  |  |     //   m.insert(std::make_pair("abc", 42)); | 
3014  |  |     // --------------------------------------------------------------------  | 
3015  |  |     template <class T, RequiresInsertable<T> = 0,  | 
3016  |  |               typename std::enable_if<IsDecomposable<T>::value, int>::type = 0,  | 
3017  |  |               T* = nullptr>  | 
3018  |  |     std::pair<iterator, bool> insert(T&& value) { | 
3019  |  |         return emplace(std::forward<T>(value));  | 
3020  |  |     }  | 
3021  |  |  | 
3022  |  |     // This overload kicks in when the argument is a bitfield or an lvalue of  | 
3023  |  |     // insertable and decomposable type.  | 
3024  |  |     //  | 
3025  |  |     //   union { int n : 1; }; | 
3026  |  |     //   flat_hash_set<int> s;  | 
3027  |  |     //   s.insert(n);  | 
3028  |  |     //  | 
3029  |  |     //   flat_hash_set<std::string> s;  | 
3030  |  |     //   const char* p = "hello";  | 
3031  |  |     //   s.insert(p);  | 
3032  |  |     //  | 
3033  |  |     // TODO(romanp): Once we stop supporting gcc 5.1 and below, replace  | 
3034  |  |     // RequiresInsertable<T> with RequiresInsertable<const T&>.  | 
3035  |  |     // We are hitting this bug: https://godbolt.org/g/1Vht4f.  | 
3036  |  |     // --------------------------------------------------------------------  | 
3037  |  |     template <  | 
3038  |  |         class T, RequiresInsertable<T> = 0,  | 
3039  |  |         typename std::enable_if<IsDecomposable<const T&>::value, int>::type = 0>  | 
3040  |  |     std::pair<iterator, bool> insert(const T& value) { | 
3041  |  |         return emplace(value);  | 
3042  |  |     }  | 
3043  |  |  | 
3044  |  |     // This overload kicks in when the argument is an rvalue of init_type. Its  | 
3045  |  |     // purpose is to handle brace-init-list arguments.  | 
3046  |  |     //  | 
3047  |  |     //   flat_hash_set<std::pair<std::string, int>> s;  | 
3048  |  |     //   s.insert({"abc", 42}); | 
3049  |  |     // --------------------------------------------------------------------  | 
3050  |  |     std::pair<iterator, bool> insert(init_type&& value) { | 
3051  |  |         return emplace(std::move(value));  | 
3052  |  |     }  | 
3053  |  |  | 
3054  |  |     template <class T, RequiresInsertable<T> = 0,  | 
3055  |  |               typename std::enable_if<IsDecomposable<T>::value, int>::type = 0,  | 
3056  |  |               T* = nullptr>  | 
3057  |  |     iterator insert(const_iterator, T&& value) { | 
3058  |  |         return insert(std::forward<T>(value)).first;  | 
3059  |  |     }  | 
3060  |  |  | 
3061  |  |     // TODO(romanp): Once we stop supporting gcc 5.1 and below, replace  | 
3062  |  |     // RequiresInsertable<T> with RequiresInsertable<const T&>.  | 
3063  |  |     // We are hitting this bug: https://godbolt.org/g/1Vht4f.  | 
3064  |  |     // --------------------------------------------------------------------  | 
3065  |  |     template <  | 
3066  |  |         class T, RequiresInsertable<T> = 0,  | 
3067  |  |         typename std::enable_if<IsDecomposable<const T&>::value, int>::type = 0>  | 
3068  |  |     iterator insert(const_iterator, const T& value) { | 
3069  |  |         return insert(value).first;  | 
3070  |  |     }  | 
3071  |  |  | 
3072  |  |     iterator insert(const_iterator, init_type&& value) { | 
3073  |  |         return insert(std::move(value)).first;  | 
3074  |  |     }  | 
3075  |  |  | 
3076  |  |     template <class InputIt>  | 
3077  |  |     void insert(InputIt first, InputIt last) { | 
3078  |  |         for (; first != last; ++first) insert(*first);  | 
3079  |  |     }  | 
3080  |  |  | 
3081  |  |     template <class T, RequiresNotInit<T> = 0, RequiresInsertable<const T&> = 0>  | 
3082  |  |     void insert(std::initializer_list<T> ilist) { | 
3083  |  |         insert(ilist.begin(), ilist.end());  | 
3084  |  |     }  | 
3085  |  |  | 
3086  |  |     void insert(std::initializer_list<init_type> ilist) { | 
3087  |  |         insert(ilist.begin(), ilist.end());  | 
3088  |  |     }  | 
3089  |  |  | 
3090  |  |     insert_return_type insert(node_type&& node) { | 
3091  |  |         if (!node)   | 
3092  |  |             return {end(), false, node_type()}; | 
3093  |  |         auto& key      = node.key();  | 
3094  |  |         size_t hashval = this->hash(key);  | 
3095  |  |         Inner& inner   = sets_[subidx(hashval)];  | 
3096  |  |         auto&  set     = inner.set_;  | 
3097  |  |  | 
3098  |  |         UniqueLock m(inner);  | 
3099  |  |         auto   res  = set.insert(std::move(node), hashval);  | 
3100  |  |         return { make_iterator(&inner, res.position), | 
3101  |  |                  res.inserted,  | 
3102  |  |                  res.inserted ? node_type() : std::move(res.node) };  | 
3103  |  |     }  | 
3104  |  |  | 
3105  |  |     iterator insert(const_iterator, node_type&& node) { | 
3106  |  |         return insert(std::move(node)).first;  | 
3107  |  |     }  | 
3108  |  |  | 
3109  |  |     struct ReturnKey_   | 
3110  |  |     { | 
3111  |  |         template <class Key, class... Args>  | 
3112  |  |         Key operator()(Key&& k, const Args&...) const { | 
3113  |  |             return std::forward<Key>(k);  | 
3114  |  |         }  | 
3115  |  |     };  | 
3116  |  |  | 
3117  |  |     // --------------------------------------------------------------------  | 
3118  |  |     // phmap extension: emplace_with_hash  | 
3119  |  |     // ----------------------------------  | 
3120  |  |     // same as emplace, but hashval is provided  | 
3121  |  |     // --------------------------------------------------------------------  | 
3122  |  |     struct EmplaceDecomposableHashval   | 
3123  |  |     { | 
3124  |  |         template <class K, class... Args>  | 
3125  |  |         std::pair<iterator, bool> operator()(const K& key, Args&&... args) const { | 
3126  |  |             return s.emplace_decomposable_with_hash(key, hashval, std::forward<Args>(args)...);  | 
3127  |  |         }  | 
3128  |  |         parallel_hash_set& s;  | 
3129  |  |         size_t hashval;  | 
3130  |  |     };  | 
3131  |  |  | 
3132  |  |     // This overload kicks in if we can deduce the key from args. This enables us  | 
3133  |  |     // to avoid constructing value_type if an entry with the same key already  | 
3134  |  |     // exists.  | 
3135  |  |     //  | 
3136  |  |     // For example:  | 
3137  |  |     //  | 
3138  |  |     //   flat_hash_map<std::string, std::string> m = {{"abc", "def"}}; | 
3139  |  |     //   // Creates no std::string copies and makes no heap allocations.  | 
3140  |  |     //   m.emplace("abc", "xyz"); | 
3141  |  |     // --------------------------------------------------------------------  | 
3142  |  |     template <class... Args, typename std::enable_if<IsDecomposable<Args...>::value, int>::type = 0>  | 
3143  |  |     std::pair<iterator, bool> emplace_with_hash(size_t hashval, Args&&... args) { | 
3144  |  |         return PolicyTraits::apply(EmplaceDecomposableHashval{*this, hashval}, | 
3145  |  |                                    std::forward<Args>(args)...);  | 
3146  |  |     }  | 
3147  |  |  | 
3148  |  |     // This overload kicks in if we cannot deduce the key from args. It constructs  | 
3149  |  |     // value_type unconditionally and then either moves it into the table or  | 
3150  |  |     // destroys.  | 
3151  |  |     // --------------------------------------------------------------------  | 
3152  |  |     template <class... Args, typename std::enable_if<!IsDecomposable<Args...>::value, int>::type = 0>  | 
3153  |  |     std::pair<iterator, bool> emplace_with_hash(size_t hashval, Args&&... args) { | 
3154  |  |         typename phmap::aligned_storage<sizeof(slot_type), alignof(slot_type)>::type raw;  | 
3155  |  |         slot_type* slot = reinterpret_cast<slot_type*>(&raw);  | 
3156  |  |  | 
3157  |  |         PolicyTraits::construct(&alloc_ref(), slot, std::forward<Args>(args)...);  | 
3158  |  |         const auto& elem = PolicyTraits::element(slot);  | 
3159  |  |         Inner& inner    = sets_[subidx(hashval)];  | 
3160  |  |         auto&  set      = inner.set_;  | 
3161  |  |         UniqueLock m(inner);  | 
3162  |  |         typename EmbeddedSet::template InsertSlotWithHash<true> f { inner, std::move(*slot), hashval }; | 
3163  |  |         return make_rv(PolicyTraits::apply(f, elem));  | 
3164  |  |     }  | 
3165  |  |  | 
3166  |  |     template <class... Args>  | 
3167  |  |     iterator emplace_hint_with_hash(size_t hashval, const_iterator, Args&&... args) { | 
3168  |  |         return emplace_with_hash(hashval, std::forward<Args>(args)...).first;  | 
3169  |  |     }  | 
3170  |  |  | 
3171  |  |     // --------------------------------------------------------------------  | 
3172  |  |     // end of phmap expension  | 
3173  |  |     // --------------------------------------------------------------------  | 
3174  |  |  | 
3175  |  |     template <class K, class... Args>  | 
3176  |  |     std::pair<iterator, bool> emplace_decomposable_with_hash(const K& key, size_t hashval, Args&&... args)  | 
3177  |  |     { | 
3178  |  |         Inner& inner   = sets_[subidx(hashval)];  | 
3179  |  |         auto&  set     = inner.set_;  | 
3180  |  |         UniqueLock m(inner);  | 
3181  |  |           | 
3182  |  |         size_t offset = set._find_key(key, hashval);  | 
3183  |  |         if (offset == (size_t)-1) { | 
3184  |  |             offset = set.prepare_insert(hashval);  | 
3185  |  |             set.emplace_at(offset, std::forward<Args>(args)...);  | 
3186  |  |             set.set_ctrl(offset, H2(hashval));  | 
3187  |  |             return make_rv(&inner, {set.iterator_at(offset), true}); | 
3188  |  |         }  | 
3189  |  |         return make_rv(&inner, {set.iterator_at(offset), false}); | 
3190  |  |     }  | 
3191  |  |  | 
3192  |  |     template <class K, class... Args>  | 
3193  |  |     std::pair<iterator, bool> emplace_decomposable(const K& key, Args&&... args)  | 
3194  |  |     { | 
3195  |  |         return emplace_decomposable_with_hash(key, this->hash(key), std::forward<Args>(args)...);  | 
3196  |  |     }  | 
3197  |  |  | 
3198  |  |     struct EmplaceDecomposable   | 
3199  |  |     { | 
3200  |  |         template <class K, class... Args>  | 
3201  |  |         std::pair<iterator, bool> operator()(const K& key, Args&&... args) const { | 
3202  |  |             return s.emplace_decomposable(key, std::forward<Args>(args)...);  | 
3203  |  |         }  | 
3204  |  |         parallel_hash_set& s;  | 
3205  |  |     };  | 
3206  |  |  | 
3207  |  |     // This overload kicks in if we can deduce the key from args. This enables us  | 
3208  |  |     // to avoid constructing value_type if an entry with the same key already  | 
3209  |  |     // exists.  | 
3210  |  |     //  | 
3211  |  |     // For example:  | 
3212  |  |     //  | 
3213  |  |     //   flat_hash_map<std::string, std::string> m = {{"abc", "def"}}; | 
3214  |  |     //   // Creates no std::string copies and makes no heap allocations.  | 
3215  |  |     //   m.emplace("abc", "xyz"); | 
3216  |  |     // --------------------------------------------------------------------  | 
3217  |  |     template <class... Args, typename std::enable_if<IsDecomposable<Args...>::value, int>::type = 0>  | 
3218  |  |     std::pair<iterator, bool> emplace(Args&&... args) { | 
3219  |  |         return PolicyTraits::apply(EmplaceDecomposable{*this}, std::forward<Args>(args)...); | 
3220  |  |     }  | 
3221  |  |  | 
3222  |  |     // This overload kicks in if we cannot deduce the key from args. It constructs  | 
3223  |  |     // value_type unconditionally and then either moves it into the table or  | 
3224  |  |     // destroys.  | 
3225  |  |     // --------------------------------------------------------------------  | 
3226  |  |     template <class... Args, typename std::enable_if<!IsDecomposable<Args...>::value, int>::type = 0>  | 
3227  |  |     std::pair<iterator, bool> emplace(Args&&... args) { | 
3228  |  |         typename phmap::aligned_storage<sizeof(slot_type), alignof(slot_type)>::type raw;  | 
3229  |  |         slot_type* slot = reinterpret_cast<slot_type*>(&raw);  | 
3230  |  |         size_t hashval  = this->hash(PolicyTraits::key(slot));  | 
3231  |  |  | 
3232  |  |         PolicyTraits::construct(&alloc_ref(), slot, std::forward<Args>(args)...);  | 
3233  |  |         const auto& elem = PolicyTraits::element(slot);  | 
3234  |  |         Inner& inner     = sets_[subidx(hashval)];  | 
3235  |  |         auto&  set       = inner.set_;  | 
3236  |  |         UniqueLock m(inner);  | 
3237  |  |         typename EmbeddedSet::template InsertSlotWithHash<true> f { inner, std::move(*slot), hashval }; | 
3238  |  |         return make_rv(PolicyTraits::apply(f, elem));  | 
3239  |  |     }  | 
3240  |  |  | 
3241  |  |     template <class... Args>  | 
3242  |  |     iterator emplace_hint(const_iterator, Args&&... args) { | 
3243  |  |         return emplace(std::forward<Args>(args)...).first;  | 
3244  |  |     }  | 
3245  |  |  | 
3246  |  |     iterator make_iterator(Inner* inner, const EmbeddedIterator it)  | 
3247  |  |     { | 
3248  |  |         if (it == inner->set_.end())  | 
3249  |  |             return iterator();  | 
3250  |  |         return iterator(inner, &sets_[0] + num_tables, it);  | 
3251  |  |     }  | 
3252  |  |  | 
3253  |  |     std::pair<iterator, bool> make_rv(Inner* inner,   | 
3254  |  |                                       const std::pair<EmbeddedIterator, bool>& res)  | 
3255  |  |     { | 
3256  |  |         return {iterator(inner, &sets_[0] + num_tables, res.first), res.second}; | 
3257  |  |     }  | 
3258  |  |  | 
3259  |  |     // lazy_emplace  | 
3260  |  |     // ------------  | 
3261  |  |     template <class K = key_type, class F>  | 
3262  |  |     iterator lazy_emplace_with_hash(const key_arg<K>& key, size_t hashval, F&& f) { | 
3263  |  |         Inner& inner = sets_[subidx(hashval)];  | 
3264  |  |         auto&  set   = inner.set_;  | 
3265  |  |         UniqueLock m(inner);  | 
3266  |  |         size_t offset = set._find_key(key, hashval);  | 
3267  |  |         if (offset == (size_t)-1) { | 
3268  |  |             offset = set.prepare_insert(hashval);  | 
3269  |  |             set.lazy_emplace_at(offset, std::forward<F>(f));  | 
3270  |  |             set.set_ctrl(offset, H2(hashval));  | 
3271  |  |         }  | 
3272  |  |         return make_iterator(&inner, set.iterator_at(offset));  | 
3273  |  |     }  | 
3274  |  |  | 
3275  |  |     template <class K = key_type, class F>  | 
3276  |  |     iterator lazy_emplace(const key_arg<K>& key, F&& f) { | 
3277  |  |         return lazy_emplace_with_hash(key, this->hash(key), std::forward<F>(f));  | 
3278  |  |     }  | 
3279  |  |       | 
3280  |  |     // emplace_single  | 
3281  |  |     // --------------  | 
3282  |  |     template <class K = key_type, class F>  | 
3283  |  |     void emplace_single_with_hash(const key_arg<K>& key, size_t hashval, F&& f) { | 
3284  |  |         Inner& inner = sets_[subidx(hashval)];  | 
3285  |  |         auto&  set   = inner.set_;  | 
3286  |  |         UniqueLock m(inner);  | 
3287  |  |         set.emplace_single_with_hash(key, hashval, std::forward<F>(f));  | 
3288  |  |     }  | 
3289  |  |  | 
3290  |  |     template <class K = key_type, class F>  | 
3291  |  |     void emplace_single(const key_arg<K>& key, F&& f) { | 
3292  |  |         emplace_single_with_hash<K, F>(key, this->hash(key), std::forward<F>(f));  | 
3293  |  |     }  | 
3294  |  |  | 
3295  |  |     // if set contains key, lambda is called with the value_type (under read lock protection),  | 
3296  |  |     // and if_contains returns true. This is a const API and lambda should not modify the value  | 
3297  |  |     // -----------------------------------------------------------------------------------------  | 
3298  |  |     template <class K = key_type, class F>  | 
3299  |  |     bool if_contains(const key_arg<K>& key, F&& f) const { | 
3300  |  |         return const_cast<parallel_hash_set*>(this)->template   | 
3301  |  |             modify_if_impl<K, F, SharedLock>(key, std::forward<F>(f));  | 
3302  |  |     }  | 
3303  |  |  | 
3304  |  |     // if set contains key, lambda is called with the value_type  without read lock protection,  | 
3305  |  |     // and if_contains_unsafe returns true. This is a const API and lambda should not modify the value  | 
3306  |  |     // This should be used only if we know that no other thread may be mutating the set at the time.  | 
3307  |  |     // -----------------------------------------------------------------------------------------  | 
3308  |  |     template <class K = key_type, class F>  | 
3309  |  |     bool if_contains_unsafe(const key_arg<K>& key, F&& f) const { | 
3310  |  |         return const_cast<parallel_hash_set*>(this)->template   | 
3311  |  |             modify_if_impl<K, F, LockableBaseImpl<phmap::NullMutex>::DoNothing>(key, std::forward<F>(f));  | 
3312  |  |     }  | 
3313  |  |  | 
3314  |  |     // if map contains key, lambda is called with the value_type  (under write lock protection),  | 
3315  |  |     // and modify_if returns true. This is a non-const API and lambda is allowed to modify the mapped value  | 
3316  |  |     // ----------------------------------------------------------------------------------------------------  | 
3317  |  |     template <class K = key_type, class F>  | 
3318  |  |     bool modify_if(const key_arg<K>& key, F&& f) { | 
3319  |  |         return modify_if_impl<K, F, UniqueLock>(key, std::forward<F>(f));  | 
3320  |  |     }  | 
3321  |  |  | 
3322  |  |     // -----------------------------------------------------------------------------------------  | 
3323  |  |     template <class K = key_type, class F, class L>  | 
3324  |  |     bool modify_if_impl(const key_arg<K>& key, F&& f) { | 
3325  |  | #if __cplusplus >= 201703L  | 
3326  |  |         static_assert(std::is_invocable<F, value_type&>::value);  | 
3327  |  | #endif  | 
3328  |  |         L m;  | 
3329  |  |         auto ptr = this->template find_ptr<K, L>(key, this->hash(key), m);  | 
3330  |  |         if (ptr == nullptr)  | 
3331  |  |             return false;  | 
3332  |  |         std::forward<F>(f)(*ptr);  | 
3333  |  |         return true;  | 
3334  |  |     }  | 
3335  |  |  | 
3336  |  |     // if map contains key, lambda is called with the mapped value  (under write lock protection).  | 
3337  |  |     // If the lambda returns true, the key is subsequently erased from the map (the write lock  | 
3338  |  |     // is only released after erase).  | 
3339  |  |     // returns true if key was erased, false otherwise.  | 
3340  |  |     // ----------------------------------------------------------------------------------------------------  | 
3341  |  |     template <class K = key_type, class F>  | 
3342  |  |     bool erase_if(const key_arg<K>& key, F&& f) { | 
3343  |  |         return !!erase_if_impl<K, F, ReadWriteLock>(key, std::forward<F>(f));  | 
3344  |  |     }  | 
3345  |  |  | 
3346  |  |     template <class K = key_type, class F, class L>  | 
3347  |  |     size_type erase_if_impl(const key_arg<K>& key, F&& f) { | 
3348  |  | #if __cplusplus >= 201703L  | 
3349  |  |         static_assert(std::is_invocable<F, value_type&>::value);  | 
3350  |  | #endif  | 
3351  |  |         auto hashval = this->hash(key);  | 
3352  |  |         Inner& inner = sets_[subidx(hashval)];  | 
3353  |  |         auto& set = inner.set_;  | 
3354  |  |         L m(inner);  | 
3355  |  |         auto it = set.find(key, hashval);  | 
3356  |  |         if (it == set.end())  | 
3357  |  |             return 0;  | 
3358  |  |         if (m.switch_to_unique()) { | 
3359  |  |             // we did an unlock/lock, need to call `find()` again  | 
3360  |  |             it = set.find(key, hashval);  | 
3361  |  |             if (it == set.end())  | 
3362  |  |                 return 0;  | 
3363  |  |         }  | 
3364  |  |         if (std::forward<F>(f)(const_cast<value_type &>(*it)))  | 
3365  |  |         { | 
3366  |  |             set._erase(it);  | 
3367  |  |             return 1;  | 
3368  |  |         }  | 
3369  |  |         return 0;  | 
3370  |  |     }  | 
3371  |  |  | 
3372  |  |     // if map already  contains key, the first lambda is called with the mapped value (under   | 
3373  |  |     // write lock protection) and can update the mapped value.  | 
3374  |  |     // if map does not contains key, the second lambda is called and it should invoke the   | 
3375  |  |     // passed constructor to construct the value  | 
3376  |  |     // returns true if key was not already present, false otherwise.  | 
3377  |  |     // ---------------------------------------------------------------------------------------  | 
3378  |  |     template <class K = key_type, class FExists, class FEmplace>  | 
3379  |  |     bool lazy_emplace_l(const key_arg<K>& key, FExists&& fExists, FEmplace&& fEmplace) { | 
3380  |  |         size_t hashval = this->hash(key);  | 
3381  |  |         UniqueLock m;  | 
3382  |  |         auto res = this->find_or_prepare_insert_with_hash(hashval, key, m);  | 
3383  |  |         Inner* inner = std::get<0>(res);  | 
3384  |  |         if (std::get<2>(res)) { | 
3385  |  |             // key not found. call fEmplace lambda which should invoke passed constructor  | 
3386  |  |             inner->set_.lazy_emplace_at(std::get<1>(res), std::forward<FEmplace>(fEmplace));  | 
3387  |  |             inner->set_.set_ctrl(std::get<1>(res), H2(hashval));  | 
3388  |  |         } else { | 
3389  |  |             // key found. Call fExists lambda. In case of the set, non "key" part of value_type can be changed  | 
3390  |  |             auto it = this->iterator_at(inner, inner->set_.iterator_at(std::get<1>(res)));  | 
3391  |  |             std::forward<FExists>(fExists)(const_cast<value_type &>(*it));   | 
3392  |  |         }  | 
3393  |  |         return std::get<2>(res);  | 
3394  |  |     }  | 
3395  |  |  | 
3396  |  |     // Extension API: support iterating over all values  | 
3397  |  |     //  | 
3398  |  |     // flat_hash_set<std::string> s;  | 
3399  |  |     // s.insert(...);  | 
3400  |  |     // s.for_each([](auto const & key) { | 
3401  |  |     //    // Safely iterates over all the keys  | 
3402  |  |     // });  | 
3403  |  |     template <class F>  | 
3404  |  |     void for_each(F&& fCallback) const { | 
3405  |  |         for (auto const& inner : sets_) { | 
3406  |  |             SharedLock m(const_cast<Inner&>(inner));  | 
3407  |  |             std::for_each(inner.set_.begin(), inner.set_.end(), fCallback);  | 
3408  |  |         }  | 
3409  |  |     }  | 
3410  |  |  | 
3411  |  |     // this version allows to modify the values  | 
3412  |  |     template <class F>  | 
3413  |  |     void for_each_m(F&& fCallback) { | 
3414  |  |         for (auto& inner : sets_) { | 
3415  |  |             UniqueLock m(inner);  | 
3416  |  |             std::for_each(inner.set_.begin(), inner.set_.end(), fCallback);  | 
3417  |  |         }  | 
3418  |  |     }  | 
3419  |  |  | 
3420  |  | #if __cplusplus >= 201703L  | 
3421  |  |     template <class ExecutionPolicy, class F>  | 
3422  |  |     void for_each(ExecutionPolicy&& policy, F&& fCallback) const { | 
3423  |  |         std::for_each(  | 
3424  |  |             std::forward<ExecutionPolicy>(policy), sets_.begin(), sets_.end(),  | 
3425  |  |             [&](auto const& inner) { | 
3426  |  |                 SharedLock m(const_cast<Inner&>(inner));  | 
3427  |  |                 std::for_each(inner.set_.begin(), inner.set_.end(), fCallback);  | 
3428  |  |             }  | 
3429  |  |         );  | 
3430  |  |     }  | 
3431  |  |  | 
3432  |  |     template <class ExecutionPolicy, class F>  | 
3433  |  |     void for_each_m(ExecutionPolicy&& policy, F&& fCallback) { | 
3434  |  |         std::for_each(  | 
3435  |  |             std::forward<ExecutionPolicy>(policy), sets_.begin(), sets_.end(),  | 
3436  |  |             [&](auto& inner) { | 
3437  |  |                 UniqueLock m(inner);  | 
3438  |  |                 std::for_each(inner.set_.begin(), inner.set_.end(), fCallback);  | 
3439  |  |             }  | 
3440  |  |         );  | 
3441  |  |     }  | 
3442  |  | #endif  | 
3443  |  |  | 
3444  |  |     // Extension API: access internal submaps by index  | 
3445  |  |     // under lock protection  | 
3446  |  |     // ex: m.with_submap(i, [&](const Map::EmbeddedSet& set) { | 
3447  |  |     //        for (auto& p : set) { ...; }}); | 
3448  |  |     // -------------------------------------------------  | 
3449  |  |     template <class F>  | 
3450  |  |     void with_submap(size_t idx, F&& fCallback) const { | 
3451  |  |         const Inner& inner     = sets_[idx];  | 
3452  |  |         const auto&  set = inner.set_;  | 
3453  |  |         SharedLock m(const_cast<Inner&>(inner));  | 
3454  |  |         fCallback(set);  | 
3455  |  |     }  | 
3456  |  |  | 
3457  |  |     template <class F>  | 
3458  |  |     void with_submap_m(size_t idx, F&& fCallback) { | 
3459  |  |         Inner& inner   = sets_[idx];  | 
3460  |  |         auto&  set     = inner.set_;  | 
3461  |  |         UniqueLock m(inner);  | 
3462  |  |         fCallback(set);  | 
3463  |  |     }  | 
3464  |  |  | 
3465  |  |     // unsafe, for internal use only  | 
3466  |  |     Inner& get_inner(size_t idx) { | 
3467  |  |         return  sets_[idx];  | 
3468  |  |     }  | 
3469  |  |  | 
3470  |  |     const Inner& get_inner(size_t idx) const { | 
3471  |  |         return  sets_[idx];  | 
3472  |  |     }  | 
3473  |  |  | 
3474  |  |     // Extension API: support for heterogeneous keys.  | 
3475  |  |     //  | 
3476  |  |     //   std::unordered_set<std::string> s;  | 
3477  |  |     //   // Turns "abc" into std::string.  | 
3478  |  |     //   s.erase("abc"); | 
3479  |  |     //  | 
3480  |  |     //   flat_hash_set<std::string> s;  | 
3481  |  |     //   // Uses "abc" directly without copying it into std::string.  | 
3482  |  |     //   s.erase("abc"); | 
3483  |  |     //  | 
3484  |  |     // --------------------------------------------------------------------  | 
3485  |  |     template <class K = key_type>  | 
3486  |  |     size_type erase(const key_arg<K>& key) { | 
3487  |  |         auto always_erase =  [](const value_type&){ return true; }; | 
3488  |  |         return erase_if_impl<K, decltype(always_erase), ReadWriteLock>(key, std::move(always_erase));  | 
3489  |  |     }  | 
3490  |  |  | 
3491  |  |     // --------------------------------------------------------------------  | 
3492  |  |     iterator erase(const_iterator cit) { return erase(cit.iter_); } | 
3493  |  |  | 
3494  |  |     // Erases the element pointed to by `it`.  Unlike `std::unordered_set::erase`,  | 
3495  |  |     // this method returns void to reduce algorithmic complexity to O(1).  In  | 
3496  |  |     // order to erase while iterating across a map, use the following idiom (which  | 
3497  |  |     // also works for standard containers):  | 
3498  |  |     //  | 
3499  |  |     // for (auto it = m.begin(), end = m.end(); it != end;) { | 
3500  |  |     //   if (<pred>) { | 
3501  |  |     //     m._erase(it++);  | 
3502  |  |     //   } else { | 
3503  |  |     //     ++it;  | 
3504  |  |     //   }  | 
3505  |  |     // }  | 
3506  |  |     //  | 
3507  |  |     // Do not use erase APIs taking iterators when accessing the map concurrently  | 
3508  |  |     // --------------------------------------------------------------------  | 
3509  |  |     void _erase(iterator it) { | 
3510  |  |         Inner* inner = it.inner_;  | 
3511  |  |         assert(inner != nullptr);  | 
3512  |  |         auto&  set   = inner->set_;  | 
3513  |  |         // UniqueLock m(*inner); // don't lock here   | 
3514  |  |           | 
3515  |  |         set._erase(it.it_);  | 
3516  |  |     }  | 
3517  |  |     void _erase(const_iterator cit) { _erase(cit.iter_); } | 
3518  |  |  | 
3519  |  |     // This overload is necessary because otherwise erase<K>(const K&) would be  | 
3520  |  |     // a better match if non-const iterator is passed as an argument.  | 
3521  |  |     // Do not use erase APIs taking iterators when accessing the map concurrently  | 
3522  |  |     // --------------------------------------------------------------------  | 
3523  |  |     iterator erase(iterator it) { _erase(it++); return it; } | 
3524  |  |  | 
3525  |  |     iterator erase(const_iterator first, const_iterator last) { | 
3526  |  |         while (first != last) { | 
3527  |  |             _erase(first++);  | 
3528  |  |         }  | 
3529  |  |         return last.iter_;  | 
3530  |  |     }  | 
3531  |  |  | 
3532  |  |     // Moves elements from `src` into `this`.  | 
3533  |  |     // If the element already exists in `this`, it is left unmodified in `src`.  | 
3534  |  |     // Do not use erase APIs taking iterators when accessing the map concurrently  | 
3535  |  |     // --------------------------------------------------------------------  | 
3536  |  |     template <typename E = Eq>  | 
3537  |  |     void merge(parallel_hash_set<N, RefSet, Mtx_, Policy, Hash, E, Alloc>& src) {  // NOLINT | 
3538  |  |         assert(this != &src);  | 
3539  |  |         if (this != &src)  | 
3540  |  |         { | 
3541  |  |             for (size_t i=0; i<num_tables; ++i)  | 
3542  |  |             { | 
3543  |  |                 typename Lockable::UniqueLocks l(sets_[i], src.sets_[i]);  | 
3544  |  |                 sets_[i].set_.merge(src.sets_[i].set_);  | 
3545  |  |             }  | 
3546  |  |         }  | 
3547  |  |     }  | 
3548  |  |  | 
3549  |  |     template <typename E = Eq>  | 
3550  |  |     void merge(parallel_hash_set<N, RefSet, Mtx_, Policy, Hash, E, Alloc>&& src) { | 
3551  |  |         merge(src);  | 
3552  |  |     }  | 
3553  |  |  | 
3554  |  |     node_type extract(const_iterator position) { | 
3555  |  |         return position.iter_.inner_->set_.extract(EmbeddedConstIterator(position.iter_.it_));  | 
3556  |  |     }  | 
3557  |  |  | 
3558  |  |     template <  | 
3559  |  |         class K = key_type,  | 
3560  |  |         typename std::enable_if<!std::is_same<K, iterator>::value, int>::type = 0>  | 
3561  |  |     node_type extract(const key_arg<K>& key) { | 
3562  |  |         UniqueLock m;  | 
3563  |  |         auto it = this->template find<K, UniqueLock>(key, this->hash(key), m);  | 
3564  |  |         return it == end() ? node_type() : extract(const_iterator{it}); | 
3565  |  |     }  | 
3566  |  |  | 
3567  |  |     template<class Mtx2_>  | 
3568  |  |     void swap(parallel_hash_set<N, RefSet, Mtx2_, Policy, Hash, Eq, Alloc>& that)  | 
3569  |  |         noexcept(IsNoThrowSwappable<EmbeddedSet>() &&  | 
3570  |  |                  (!AllocTraits::propagate_on_container_swap::value ||  | 
3571  |  |                   IsNoThrowSwappable<allocator_type>(typename AllocTraits::propagate_on_container_swap{}))) | 
3572  |  |     { | 
3573  |  |         using std::swap;  | 
3574  |  |         using Lockable2 = phmap::LockableImpl<Mtx2_>;  | 
3575  |  |            | 
3576  |  |         for (size_t i=0; i<num_tables; ++i)  | 
3577  |  |         { | 
3578  |  |             typename Lockable::UniqueLock l(sets_[i]);  | 
3579  |  |             typename Lockable2::UniqueLock l2(that.get_inner(i));  | 
3580  |  |             swap(sets_[i].set_, that.get_inner(i).set_);  | 
3581  |  |         }  | 
3582  |  |     }  | 
3583  |  |  | 
3584  |  |     void rehash(size_t n) { | 
3585  |  |         size_t nn = n / num_tables;  | 
3586  |  |         for (auto& inner : sets_)  | 
3587  |  |         { | 
3588  |  |             UniqueLock m(inner);  | 
3589  |  |             inner.set_.rehash(nn);  | 
3590  |  |         }  | 
3591  |  |     }  | 
3592  |  |  | 
3593  |  |     void reserve(size_t n)   | 
3594  |  |     { | 
3595  |  |         size_t target = GrowthToLowerboundCapacity(n);  | 
3596  |  |         size_t normalized = num_tables * NormalizeCapacity(n / num_tables);  | 
3597  |  |         rehash(normalized > target ? normalized : target);   | 
3598  |  |     }  | 
3599  |  |  | 
3600  |  |     // Extension API: support for heterogeneous keys.  | 
3601  |  |     //  | 
3602  |  |     //   std::unordered_set<std::string> s;  | 
3603  |  |     //   // Turns "abc" into std::string.  | 
3604  |  |     //   s.count("abc"); | 
3605  |  |     //  | 
3606  |  |     //   ch_set<std::string> s;  | 
3607  |  |     //   // Uses "abc" directly without copying it into std::string.  | 
3608  |  |     //   s.count("abc"); | 
3609  |  |     // --------------------------------------------------------------------  | 
3610  |  |     template <class K = key_type>  | 
3611  |  |     size_t count(const key_arg<K>& key) const { | 
3612  |  |         return find(key) == end() ? 0 : 1;  | 
3613  |  |     }  | 
3614  |  |  | 
3615  |  |     // Issues CPU prefetch instructions for the memory needed to find or insert  | 
3616  |  |     // a key.  Like all lookup functions, this support heterogeneous keys.  | 
3617  |  |     //  | 
3618  |  |     // NOTE: This is a very low level operation and should not be used without  | 
3619  |  |     // specific benchmarks indicating its importance.  | 
3620  |  |     // --------------------------------------------------------------------  | 
3621  |  |     void prefetch_hash(size_t hashval) const { | 
3622  |  |         const Inner& inner = sets_[subidx(hashval)];  | 
3623  |  |         const auto&  set   = inner.set_;  | 
3624  |  |         SharedLock m(const_cast<Inner&>(inner));  | 
3625  |  |         set.prefetch_hash(hashval);  | 
3626  |  |     }  | 
3627  |  |  | 
3628  |  |     template <class K = key_type>  | 
3629  |  |     void prefetch(const key_arg<K>& key) const { | 
3630  |  |         prefetch_hash(this->hash(key));  | 
3631  |  |     }  | 
3632  |  |  | 
3633  |  |     // The API of find() has two extensions.  | 
3634  |  |     //  | 
3635  |  |     // 1. The hash can be passed by the user. It must be equal to the hash of the  | 
3636  |  |     // key.  | 
3637  |  |     //  | 
3638  |  |     // 2. The type of the key argument doesn't have to be key_type. This is so  | 
3639  |  |     // called heterogeneous key support.  | 
3640  |  |     // --------------------------------------------------------------------  | 
3641  |  |     template <class K = key_type>  | 
3642  |  |     iterator find(const key_arg<K>& key, size_t hashval) { | 
3643  |  |         SharedLock m;  | 
3644  |  |         return find(key, hashval, m);  | 
3645  |  |     }  | 
3646  |  |  | 
3647  |  |     template <class K = key_type>  | 
3648  |  |     iterator find(const key_arg<K>& key) { | 
3649  |  |         return find(key, this->hash(key));  | 
3650  |  |     }  | 
3651  |  |  | 
3652  |  |     template <class K = key_type>  | 
3653  |  |     const_iterator find(const key_arg<K>& key, size_t hashval) const { | 
3654  |  |         return const_cast<parallel_hash_set*>(this)->find(key, hashval);  | 
3655  |  |     }  | 
3656  |  |  | 
3657  |  |     template <class K = key_type>  | 
3658  |  |     const_iterator find(const key_arg<K>& key) const { | 
3659  |  |         return find(key, this->hash(key));  | 
3660  |  |     }  | 
3661  |  |  | 
3662  |  |     template <class K = key_type>  | 
3663  |  |     bool contains(const key_arg<K>& key) const { | 
3664  |  |         return find(key) != end();  | 
3665  |  |     }  | 
3666  |  |  | 
3667  |  |     template <class K = key_type>  | 
3668  |  |     bool contains(const key_arg<K>& key, size_t hashval) const { | 
3669  |  |         return find(key, hashval) != end();  | 
3670  |  |     }  | 
3671  |  |  | 
3672  |  |     template <class K = key_type>  | 
3673  |  |     std::pair<iterator, iterator> equal_range(const key_arg<K>& key) { | 
3674  |  |         auto it = find(key);  | 
3675  |  |         if (it != end()) return {it, std::next(it)}; | 
3676  |  |         return {it, it}; | 
3677  |  |     }  | 
3678  |  |  | 
3679  |  |     template <class K = key_type>  | 
3680  |  |     std::pair<const_iterator, const_iterator> equal_range(  | 
3681  |  |         const key_arg<K>& key) const { | 
3682  |  |         auto it = find(key);  | 
3683  |  |         if (it != end()) return {it, std::next(it)}; | 
3684  |  |         return {it, it}; | 
3685  |  |     }  | 
3686  |  |  | 
3687  |  |     size_t bucket_count() const { | 
3688  |  |         size_t sz = 0;  | 
3689  |  |         for (const auto& inner : sets_)  | 
3690  |  |         { | 
3691  |  |             SharedLock m(const_cast<Inner&>(inner));  | 
3692  |  |             sz += inner.set_.bucket_count();  | 
3693  |  |         }  | 
3694  |  |         return sz;   | 
3695  |  |     }  | 
3696  |  |  | 
3697  |  |     float load_factor() const { | 
3698  |  |         size_t _capacity = bucket_count();  | 
3699  |  |         return _capacity ? static_cast<float>(static_cast<double>(size()) / _capacity) : 0;  | 
3700  |  |     }  | 
3701  |  |  | 
3702  |  |     float max_load_factor() const { return 1.0f; } | 
3703  |  |     void max_load_factor(float) { | 
3704  |  |         // Does nothing.  | 
3705  |  |     }  | 
3706  |  |  | 
3707  |  |     hasher hash_function() const { return hash_ref(); }  // warning: doesn't match internal hash - use hash() member function | 
3708  |  |     key_equal key_eq() const { return eq_ref(); } | 
3709  |  |     allocator_type get_allocator() const { return alloc_ref(); } | 
3710  |  |  | 
3711  |  |     friend bool operator==(const parallel_hash_set& a, const parallel_hash_set& b) { | 
3712  |  |         return std::equal(a.sets_.begin(), a.sets_.end(), b.sets_.begin());  | 
3713  |  |     }  | 
3714  |  |  | 
3715  |  |     friend bool operator!=(const parallel_hash_set& a, const parallel_hash_set& b) { | 
3716  |  |         return !(a == b);  | 
3717  |  |     }  | 
3718  |  |  | 
3719  |  |     template<class Mtx2_>  | 
3720  |  |     friend void swap(parallel_hash_set& a,  | 
3721  |  |                      parallel_hash_set<N, RefSet, Mtx2_, Policy, Hash, Eq, Alloc>& b)  | 
3722  |  |         noexcept(noexcept(a.swap(b)))  | 
3723  |  |     { | 
3724  |  |         a.swap(b);  | 
3725  |  |     }  | 
3726  |  |  | 
3727  |  |     template <class K>  | 
3728  |  |     size_t hash(const K& key) const { | 
3729  |  |         return HashElement{hash_ref()}(key); | 
3730  |  |     }  | 
3731  |  |  | 
3732  |  | #if !defined(PHMAP_NON_DETERMINISTIC)  | 
3733  |  |     template<typename OutputArchive>  | 
3734  |  |     bool phmap_dump(OutputArchive& ar) const;  | 
3735  |  |  | 
3736  |  |     template<typename InputArchive>  | 
3737  |  |     bool phmap_load(InputArchive& ar);  | 
3738  |  | #endif  | 
3739  |  |  | 
3740  |  | private:  | 
3741  |  |     template <class Container, typename Enabler>  | 
3742  |  |     friend struct phmap::priv::hashtable_debug_internal::HashtableDebugAccess;  | 
3743  |  |  | 
3744  |  |     struct FindElement   | 
3745  |  |     { | 
3746  |  |         template <class K, class... Args>  | 
3747  |  |         const_iterator operator()(const K& key, Args&&...) const { | 
3748  |  |             return s.find(key);  | 
3749  |  |         }  | 
3750  |  |         const parallel_hash_set& s;  | 
3751  |  |     };  | 
3752  |  |  | 
3753  |  |     struct HashElement   | 
3754  |  |     { | 
3755  |  |         template <class K, class... Args>  | 
3756  |  |         size_t operator()(const K& key, Args&&...) const { | 
3757  |  | #if PHMAP_DISABLE_MIX  | 
3758  |  |             return h(key);  | 
3759  |  | #else  | 
3760  |  |             return phmap_mix<sizeof(size_t)>()(h(key));  | 
3761  |  | #endif  | 
3762  |  |         }  | 
3763  |  |         const hasher& h;  | 
3764  |  |     };  | 
3765  |  |  | 
3766  |  |     template <class K1>  | 
3767  |  |     struct EqualElement   | 
3768  |  |     { | 
3769  |  |         template <class K2, class... Args>  | 
3770  |  |         bool operator()(const K2& lhs, Args&&...) const { | 
3771  |  |             return eq(lhs, rhs);  | 
3772  |  |         }  | 
3773  |  |         const K1& rhs;  | 
3774  |  |         const key_equal& eq;  | 
3775  |  |     };  | 
3776  |  |  | 
3777  |  |     // "erases" the object from the container, except that it doesn't actually  | 
3778  |  |     // destroy the object. It only updates all the metadata of the class.  | 
3779  |  |     // This can be used in conjunction with Policy::transfer to move the object to  | 
3780  |  |     // another place.  | 
3781  |  |     // --------------------------------------------------------------------  | 
3782  |  |     void erase_meta_only(const_iterator cit) { | 
3783  |  |         auto &it = cit.iter_;  | 
3784  |  |         assert(it.set_ != nullptr);  | 
3785  |  |         it.set_.erase_meta_only(const_iterator(it.it_));  | 
3786  |  |     }  | 
3787  |  |  | 
3788  |  |     void drop_deletes_without_resize() PHMAP_ATTRIBUTE_NOINLINE { | 
3789  |  |         for (auto& inner : sets_)  | 
3790  |  |         { | 
3791  |  |             UniqueLock m(inner);  | 
3792  |  |             inner.set_.drop_deletes_without_resize();  | 
3793  |  |         }  | 
3794  |  |     }  | 
3795  |  |  | 
3796  |  |     bool has_element(const value_type& elem) const { | 
3797  |  |         size_t hashval = PolicyTraits::apply(HashElement{hash_ref()}, elem); | 
3798  |  |         Inner& inner   = sets_[subidx(hashval)];  | 
3799  |  |         auto&  set     = inner.set_;  | 
3800  |  |         SharedLock m(const_cast<Inner&>(inner));  | 
3801  |  |         return set.has_element(elem, hashval);  | 
3802  |  |     }  | 
3803  |  |  | 
3804  |  |     // TODO(alkis): Optimize this assuming *this and that don't overlap.  | 
3805  |  |     // --------------------------------------------------------------------  | 
3806  |  |     template<class Mtx2_>  | 
3807  |  |     parallel_hash_set& move_assign(parallel_hash_set<N, RefSet, Mtx2_, Policy, Hash, Eq, Alloc>&& that, std::true_type) { | 
3808  |  |         parallel_hash_set<N, RefSet, Mtx2_, Policy, Hash, Eq, Alloc> tmp(std::move(that));  | 
3809  |  |         swap(tmp);  | 
3810  |  |         return *this;  | 
3811  |  |     }  | 
3812  |  |  | 
3813  |  |     template<class Mtx2_>  | 
3814  |  |     parallel_hash_set& move_assign(parallel_hash_set<N, RefSet, Mtx2_, Policy, Hash, Eq, Alloc>&& that, std::false_type) { | 
3815  |  |         parallel_hash_set<N, RefSet, Mtx2_, Policy, Hash, Eq, Alloc> tmp(std::move(that), alloc_ref());  | 
3816  |  |         swap(tmp);  | 
3817  |  |         return *this;  | 
3818  |  |     }  | 
3819  |  |  | 
3820  |  | protected:  | 
3821  |  |     template <class K = key_type, class L = SharedLock>  | 
3822  |  |     pointer find_ptr(const key_arg<K>& key, size_t hashval, L& mutexlock)  | 
3823  |  |     { | 
3824  |  |         Inner& inner = sets_[subidx(hashval)];  | 
3825  |  |         auto& set = inner.set_;  | 
3826  |  |         mutexlock = std::move(L(inner));  | 
3827  |  |         return set.find_ptr(key, hashval);  | 
3828  |  |     }  | 
3829  |  |  | 
3830  |  |     template <class K = key_type, class L = SharedLock>  | 
3831  |  |     iterator find(const key_arg<K>& key, size_t hashval, L& mutexlock) { | 
3832  |  |         Inner& inner = sets_[subidx(hashval)];  | 
3833  |  |         auto& set = inner.set_;  | 
3834  |  |         mutexlock = std::move(L(inner));  | 
3835  |  |         return make_iterator(&inner, set.find(key, hashval));  | 
3836  |  |     }  | 
3837  |  |  | 
3838  |  |     template <class K>  | 
3839  |  |     std::tuple<Inner*, size_t, bool>   | 
3840  |  |     find_or_prepare_insert_with_hash(size_t hashval, const K& key, UniqueLock &mutexlock) { | 
3841  |  |         Inner& inner = sets_[subidx(hashval)];  | 
3842  |  |         auto&  set   = inner.set_;  | 
3843  |  |         mutexlock    = std::move(UniqueLock(inner));  | 
3844  |  |         size_t offset = set._find_key(key, hashval);  | 
3845  |  |         if (offset == (size_t)-1) { | 
3846  |  |             offset = set.prepare_insert(hashval);  | 
3847  |  |             return std::make_tuple(&inner, offset, true);  | 
3848  |  |         }  | 
3849  |  |         return std::make_tuple(&inner, offset, false);  | 
3850  |  |     }  | 
3851  |  |  | 
3852  |  |     template <class K>  | 
3853  |  |     std::tuple<Inner*, size_t, bool>   | 
3854  |  |     find_or_prepare_insert(const K& key, UniqueLock &mutexlock) { | 
3855  |  |         return find_or_prepare_insert_with_hash<K>(this->hash(key), key, mutexlock);  | 
3856  |  |     }  | 
3857  |  |  | 
3858  |  |     iterator iterator_at(Inner *inner,   | 
3859  |  |                          const EmbeddedIterator& it) {  | 
3860  |  |         return {inner, &sets_[0] + num_tables, it};  | 
3861  |  |     }  | 
3862  |  |     const_iterator iterator_at(Inner *inner,   | 
3863  |  |                                const EmbeddedIterator& it) const {  | 
3864  |  |         return {inner, &sets_[0] + num_tables, it};  | 
3865  |  |     }  | 
3866  |  |  | 
3867  |  |     static size_t subidx(size_t hashval) { | 
3868  |  |         return ((hashval >> 8) ^ (hashval >> 16) ^ (hashval >> 24)) & mask;  | 
3869  |  |     }  | 
3870  |  |  | 
3871  |  |     static size_t subcnt() { | 
3872  |  |         return num_tables;  | 
3873  |  |     }  | 
3874  |  |  | 
3875  |  | private:  | 
3876  |  |     friend struct RawHashSetTestOnlyAccess;  | 
3877  |  |  | 
3878  |  |     size_t growth_left() {  | 
3879  |  |         size_t sz = 0;  | 
3880  |  |         for (const auto& set : sets_)  | 
3881  |  |             sz += set.growth_left();  | 
3882  |  |         return sz;   | 
3883  |  |     }  | 
3884  |  |  | 
3885  |  |     hasher&       hash_ref()        { return sets_[0].set_.hash_ref(); } | 
3886  |  |     const hasher& hash_ref() const  { return sets_[0].set_.hash_ref(); } | 
3887  |  |     key_equal&       eq_ref()       { return sets_[0].set_.eq_ref(); } | 
3888  |  |     const key_equal& eq_ref() const { return sets_[0].set_.eq_ref(); } | 
3889  |  |     allocator_type&  alloc_ref()    { return sets_[0].set_.alloc_ref(); } | 
3890  |  |     const allocator_type& alloc_ref() const {  | 
3891  |  |         return sets_[0].set_.alloc_ref();  | 
3892  |  |     }  | 
3893  |  |  | 
3894  |  | protected:       // protected in case users want to derive fromm this  | 
3895  |  |     std::array<Inner, num_tables> sets_;  | 
3896  |  | };  | 
3897  |  |  | 
3898  |  | // --------------------------------------------------------------------------  | 
3899  |  | // --------------------------------------------------------------------------  | 
3900  |  | template <size_t N,  | 
3901  |  |           template <class, class, class, class> class RefSet,  | 
3902  |  |           class Mtx_,  | 
3903  |  |           class Policy, class Hash, class Eq, class Alloc>  | 
3904  |  | class parallel_hash_map : public parallel_hash_set<N, RefSet, Mtx_, Policy, Hash, Eq, Alloc>   | 
3905  |  | { | 
3906  |  |     // P is Policy. It's passed as a template argument to support maps that have  | 
3907  |  |     // incomplete types as values, as in unordered_map<K, IncompleteType>.  | 
3908  |  |     // MappedReference<> may be a non-reference type.  | 
3909  |  |     template <class P>  | 
3910  |  |     using MappedReference = decltype(P::value(  | 
3911  |  |             std::addressof(std::declval<typename parallel_hash_map::reference>())));  | 
3912  |  |  | 
3913  |  |     // MappedConstReference<> may be a non-reference type.  | 
3914  |  |     template <class P>  | 
3915  |  |     using MappedConstReference = decltype(P::value(  | 
3916  |  |             std::addressof(std::declval<typename parallel_hash_map::const_reference>())));  | 
3917  |  |  | 
3918  |  |     using KeyArgImpl =  | 
3919  |  |         KeyArg<IsTransparent<Eq>::value && IsTransparent<Hash>::value>;  | 
3920  |  |  | 
3921  |  |     using Base = typename parallel_hash_map::parallel_hash_set;  | 
3922  |  |     using Lockable      = phmap::LockableImpl<Mtx_>;  | 
3923  |  |     using UniqueLock    = typename Lockable::UniqueLock;  | 
3924  |  |     using SharedLock    = typename Lockable::SharedLock;  | 
3925  |  |     using ReadWriteLock = typename Lockable::ReadWriteLock;  | 
3926  |  |  | 
3927  |  | public:  | 
3928  |  |     using key_type    = typename Policy::key_type;  | 
3929  |  |     using mapped_type = typename Policy::mapped_type;  | 
3930  |  |     using value_type  = typename Base::value_type;  | 
3931  |  |     template <class K>  | 
3932  |  |     using key_arg = typename KeyArgImpl::template type<K, key_type>;  | 
3933  |  |  | 
3934  |  |     static_assert(!std::is_reference<key_type>::value, "");  | 
3935  |  |     // TODO(alkis): remove this assertion and verify that reference mapped_type is  | 
3936  |  |     // supported.  | 
3937  |  |     static_assert(!std::is_reference<mapped_type>::value, "");  | 
3938  |  |  | 
3939  |  |     using iterator = typename parallel_hash_map::parallel_hash_set::iterator;  | 
3940  |  |     using const_iterator = typename parallel_hash_map::parallel_hash_set::const_iterator;  | 
3941  |  |  | 
3942  |  |     parallel_hash_map() {} | 
3943  |  |  | 
3944  |  | #ifdef __INTEL_COMPILER  | 
3945  |  |     using Base::parallel_hash_set;  | 
3946  |  | #else  | 
3947  |  |     using parallel_hash_map::parallel_hash_set::parallel_hash_set;  | 
3948  |  | #endif  | 
3949  |  |  | 
3950  |  |     // The last two template parameters ensure that both arguments are rvalues  | 
3951  |  |     // (lvalue arguments are handled by the overloads below). This is necessary  | 
3952  |  |     // for supporting bitfield arguments.  | 
3953  |  |     //  | 
3954  |  |     //   union { int n : 1; }; | 
3955  |  |     //   flat_hash_map<int, int> m;  | 
3956  |  |     //   m.insert_or_assign(n, n);  | 
3957  |  |     template <class K = key_type, class V = mapped_type, K* = nullptr,  | 
3958  |  |               V* = nullptr>  | 
3959  |  |     std::pair<iterator, bool> insert_or_assign(key_arg<K>&& k, V&& v) { | 
3960  |  |         return insert_or_assign_impl(std::forward<K>(k), std::forward<V>(v));  | 
3961  |  |     }  | 
3962  |  |  | 
3963  |  |     template <class K = key_type, class V = mapped_type, K* = nullptr>  | 
3964  |  |     std::pair<iterator, bool> insert_or_assign(key_arg<K>&& k, const V& v) { | 
3965  |  |         return insert_or_assign_impl(std::forward<K>(k), v);  | 
3966  |  |     }  | 
3967  |  |  | 
3968  |  |     template <class K = key_type, class V = mapped_type, V* = nullptr>  | 
3969  |  |     std::pair<iterator, bool> insert_or_assign(const key_arg<K>& k, V&& v) { | 
3970  |  |         return insert_or_assign_impl(k, std::forward<V>(v));  | 
3971  |  |     }  | 
3972  |  |  | 
3973  |  |     template <class K = key_type, class V = mapped_type>  | 
3974  |  |     std::pair<iterator, bool> insert_or_assign(const key_arg<K>& k, const V& v) { | 
3975  |  |         return insert_or_assign_impl(k, v);  | 
3976  |  |     }  | 
3977  |  |  | 
3978  |  |     template <class K = key_type, class V = mapped_type, K* = nullptr,  | 
3979  |  |               V* = nullptr>  | 
3980  |  |     iterator insert_or_assign(const_iterator, key_arg<K>&& k, V&& v) { | 
3981  |  |         return insert_or_assign(std::forward<K>(k), std::forward<V>(v)).first;  | 
3982  |  |     }  | 
3983  |  |  | 
3984  |  |     template <class K = key_type, class V = mapped_type, K* = nullptr>  | 
3985  |  |     iterator insert_or_assign(const_iterator, key_arg<K>&& k, const V& v) { | 
3986  |  |         return insert_or_assign(std::forward<K>(k), v).first;  | 
3987  |  |     }  | 
3988  |  |  | 
3989  |  |     template <class K = key_type, class V = mapped_type, V* = nullptr>  | 
3990  |  |     iterator insert_or_assign(const_iterator, const key_arg<K>& k, V&& v) { | 
3991  |  |         return insert_or_assign(k, std::forward<V>(v)).first;  | 
3992  |  |     }  | 
3993  |  |  | 
3994  |  |     template <class K = key_type, class V = mapped_type>  | 
3995  |  |     iterator insert_or_assign(const_iterator, const key_arg<K>& k, const V& v) { | 
3996  |  |         return insert_or_assign(k, v).first;  | 
3997  |  |     }  | 
3998  |  |  | 
3999  |  |     template <class K = key_type, class... Args,  | 
4000  |  |               typename std::enable_if<  | 
4001  |  |                   !std::is_convertible<K, const_iterator>::value, int>::type = 0,  | 
4002  |  |               K* = nullptr>  | 
4003  |  |     std::pair<iterator, bool> try_emplace(key_arg<K>&& k, Args&&... args) { | 
4004  |  |         return try_emplace_impl(std::forward<K>(k), std::forward<Args>(args)...);  | 
4005  |  |     }  | 
4006  |  |  | 
4007  |  |     template <class K = key_type, class... Args,  | 
4008  |  |               typename std::enable_if<  | 
4009  |  |                   !std::is_convertible<K, const_iterator>::value, int>::type = 0>  | 
4010  |  |     std::pair<iterator, bool> try_emplace(const key_arg<K>& k, Args&&... args) { | 
4011  |  |         return try_emplace_impl(k, std::forward<Args>(args)...);  | 
4012  |  |     }  | 
4013  |  |  | 
4014  |  |     template <class K = key_type, class... Args, K* = nullptr>  | 
4015  |  |     iterator try_emplace(const_iterator, key_arg<K>&& k, Args&&... args) { | 
4016  |  |         return try_emplace(std::forward<K>(k), std::forward<Args>(args)...).first;  | 
4017  |  |     }  | 
4018  |  |  | 
4019  |  |     template <class K = key_type, class... Args>  | 
4020  |  |     iterator try_emplace(const_iterator, const key_arg<K>& k, Args&&... args) { | 
4021  |  |         return try_emplace(k, std::forward<Args>(args)...).first;  | 
4022  |  |     }  | 
4023  |  |  | 
4024  |  |     template <class K = key_type, class P = Policy>  | 
4025  |  |     MappedReference<P> at(const key_arg<K>& key) { | 
4026  |  |         auto it = this->find(key);  | 
4027  |  |         if (it == this->end())   | 
4028  |  |             phmap::base_internal::ThrowStdOutOfRange("phmap at(): lookup non-existent key"); | 
4029  |  |         return Policy::value(&*it);  | 
4030  |  |     }  | 
4031  |  |  | 
4032  |  |     template <class K = key_type, class P = Policy>  | 
4033  |  |     MappedConstReference<P> at(const key_arg<K>& key) const { | 
4034  |  |         auto it = this->find(key);  | 
4035  |  |         if (it == this->end())   | 
4036  |  |             phmap::base_internal::ThrowStdOutOfRange("phmap at(): lookup non-existent key"); | 
4037  |  |         return Policy::value(&*it);  | 
4038  |  |     }  | 
4039  |  |  | 
4040  |  |     // ----------- phmap extensions --------------------------  | 
4041  |  |  | 
4042  |  |     template <class K = key_type, class... Args,  | 
4043  |  |               typename std::enable_if<  | 
4044  |  |                   !std::is_convertible<K, const_iterator>::value, int>::type = 0,  | 
4045  |  |               K* = nullptr>  | 
4046  |  |     std::pair<iterator, bool> try_emplace_with_hash(size_t hashval, key_arg<K>&& k, Args&&... args) { | 
4047  |  |         return try_emplace_impl_with_hash(hashval, std::forward<K>(k), std::forward<Args>(args)...);  | 
4048  |  |     }  | 
4049  |  |  | 
4050  |  |     template <class K = key_type, class... Args,  | 
4051  |  |               typename std::enable_if<  | 
4052  |  |                   !std::is_convertible<K, const_iterator>::value, int>::type = 0>  | 
4053  |  |     std::pair<iterator, bool> try_emplace_with_hash(size_t hashval, const key_arg<K>& k, Args&&... args) { | 
4054  |  |         return try_emplace_impl_with_hash(hashval, k, std::forward<Args>(args)...);  | 
4055  |  |     }  | 
4056  |  |  | 
4057  |  |     template <class K = key_type, class... Args, K* = nullptr>  | 
4058  |  |     iterator try_emplace_with_hash(size_t hashval, const_iterator, key_arg<K>&& k, Args&&... args) { | 
4059  |  |         return try_emplace_with_hash(hashval, std::forward<K>(k), std::forward<Args>(args)...).first;  | 
4060  |  |     }  | 
4061  |  |  | 
4062  |  |     template <class K = key_type, class... Args>  | 
4063  |  |     iterator try_emplace_with_hash(size_t hashval, const_iterator, const key_arg<K>& k, Args&&... args) { | 
4064  |  |         return try_emplace_with_hash(hashval, k, std::forward<Args>(args)...).first;  | 
4065  |  |     }  | 
4066  |  |  | 
4067  |  |     // if map does not contains key, it is inserted and the mapped value is value-constructed   | 
4068  |  |     // with the provided arguments (if any), as with try_emplace.   | 
4069  |  |     // if map already  contains key, then the lambda is called with the mapped value (under   | 
4070  |  |     // write lock protection) and can update the mapped value.  | 
4071  |  |     // returns true if key was not already present, false otherwise.  | 
4072  |  |     // ---------------------------------------------------------------------------------------  | 
4073  |  |     template <class K = key_type, class F, class... Args>  | 
4074  |  |     bool try_emplace_l(K&& k, F&& f, Args&&... args) { | 
4075  |  |         size_t hashval = this->hash(k);  | 
4076  |  |         UniqueLock m;  | 
4077  |  |         auto res = this->find_or_prepare_insert_with_hash(hashval, k, m);  | 
4078  |  |         typename Base::Inner *inner = std::get<0>(res);  | 
4079  |  |         if (std::get<2>(res)) { | 
4080  |  |             inner->set_.emplace_at(std::get<1>(res), std::piecewise_construct,  | 
4081  |  |                                    std::forward_as_tuple(std::forward<K>(k)),  | 
4082  |  |                                    std::forward_as_tuple(std::forward<Args>(args)...));  | 
4083  |  |             inner->set_.set_ctrl(std::get<1>(res), H2(hashval));  | 
4084  |  |         } else { | 
4085  |  |             auto it = this->iterator_at(inner, inner->set_.iterator_at(std::get<1>(res)));  | 
4086  |  |             // call lambda. in case of the set, non "key" part of value_type can be changed  | 
4087  |  |             std::forward<F>(f)(const_cast<value_type &>(*it));  | 
4088  |  |         }  | 
4089  |  |         return std::get<2>(res);  | 
4090  |  |     }  | 
4091  |  |  | 
4092  |  |     // returns {pointer, bool} instead of {iterator, bool} per try_emplace. | 
4093  |  |     // useful for node-based containers, since the pointer is not invalidated by concurrent insert etc.  | 
4094  |  |     template <class K = key_type, class... Args>  | 
4095  |  |     std::pair<typename parallel_hash_map::parallel_hash_set::pointer, bool> try_emplace_p(K&& k, Args&&... args) { | 
4096  |  |         size_t hashval = this->hash(k);  | 
4097  |  |         UniqueLock m;  | 
4098  |  |         auto res = this->find_or_prepare_insert_with_hash(hashval, k, m);  | 
4099  |  |         typename Base::Inner *inner = std::get<0>(res);  | 
4100  |  |         if (std::get<2>(res)) { | 
4101  |  |             inner->set_.emplace_at(std::get<1>(res), std::piecewise_construct,  | 
4102  |  |                                    std::forward_as_tuple(std::forward<K>(k)),  | 
4103  |  |                                    std::forward_as_tuple(std::forward<Args>(args)...));  | 
4104  |  |             inner->set_.set_ctrl(std::get<1>(res), H2(hashval));  | 
4105  |  |         }  | 
4106  |  |         auto it = this->iterator_at(inner, inner->set_.iterator_at(std::get<1>(res)));  | 
4107  |  |         return {&*it, std::get<2>(res)}; | 
4108  |  |     }  | 
4109  |  |  | 
4110  |  |     // ----------- end of phmap extensions --------------------------  | 
4111  |  |  | 
4112  |  |     template <class K = key_type, class P = Policy, K* = nullptr>  | 
4113  |  |     MappedReference<P> operator[](key_arg<K>&& key) { | 
4114  |  |         return Policy::value(&*try_emplace(std::forward<K>(key)).first);  | 
4115  |  |     }  | 
4116  |  |  | 
4117  |  |     template <class K = key_type, class P = Policy>  | 
4118  |  |     MappedReference<P> operator[](const key_arg<K>& key) { | 
4119  |  |         return Policy::value(&*try_emplace(key).first);  | 
4120  |  |     }  | 
4121  |  |  | 
4122  |  | private:  | 
4123  |  |  | 
4124  |  |     template <class K, class V>  | 
4125  |  |     std::pair<iterator, bool> insert_or_assign_impl(K&& k, V&& v) { | 
4126  |  |         size_t hashval = this->hash(k);  | 
4127  |  |         UniqueLock m;  | 
4128  |  |         auto res = this->find_or_prepare_insert_with_hash(hashval, k, m);  | 
4129  |  |         typename Base::Inner *inner = std::get<0>(res);  | 
4130  |  |         if (std::get<2>(res)) { | 
4131  |  |             inner->set_.emplace_at(std::get<1>(res), std::forward<K>(k), std::forward<V>(v));  | 
4132  |  |             inner->set_.set_ctrl(std::get<1>(res), H2(hashval));  | 
4133  |  |         } else  | 
4134  |  |             Policy::value(&*inner->set_.iterator_at(std::get<1>(res))) = std::forward<V>(v);  | 
4135  |  |         return {this->iterator_at(inner, inner->set_.iterator_at(std::get<1>(res))),  | 
4136  |  |                 std::get<2>(res)};  | 
4137  |  |     }  | 
4138  |  |  | 
4139  |  |     template <class K = key_type, class... Args>  | 
4140  |  |     std::pair<iterator, bool> try_emplace_impl(K&& k, Args&&... args) { | 
4141  |  |         return try_emplace_impl_with_hash(this->hash(k), std::forward<K>(k),  | 
4142  |  |                                           std::forward<Args>(args)...);  | 
4143  |  |     }  | 
4144  |  |  | 
4145  |  |     template <class K = key_type, class... Args>  | 
4146  |  |     std::pair<iterator, bool> try_emplace_impl_with_hash(size_t hashval, K&& k, Args&&... args) { | 
4147  |  |         UniqueLock m;  | 
4148  |  |         auto res = this->find_or_prepare_insert_with_hash(hashval, k, m);  | 
4149  |  |         typename Base::Inner *inner = std::get<0>(res);  | 
4150  |  |         if (std::get<2>(res)) { | 
4151  |  |             inner->set_.emplace_at(std::get<1>(res), std::piecewise_construct,  | 
4152  |  |                                    std::forward_as_tuple(std::forward<K>(k)),  | 
4153  |  |                                    std::forward_as_tuple(std::forward<Args>(args)...));  | 
4154  |  |             inner->set_.set_ctrl(std::get<1>(res), H2(hashval));  | 
4155  |  |         }  | 
4156  |  |         return {this->iterator_at(inner, inner->set_.iterator_at(std::get<1>(res))),  | 
4157  |  |                 std::get<2>(res)};  | 
4158  |  |     }  | 
4159  |  |  | 
4160  |  |       | 
4161  |  | };  | 
4162  |  |  | 
4163  |  |  | 
4164  |  | // Constructs T into uninitialized storage pointed by `ptr` using the args  | 
4165  |  | // specified in the tuple.  | 
4166  |  | // ----------------------------------------------------------------------------  | 
4167  |  | template <class Alloc, class T, class Tuple>  | 
4168  |  | void ConstructFromTuple(Alloc* alloc, T* ptr, Tuple&& t) { | 
4169  |  |     memory_internal::ConstructFromTupleImpl(  | 
4170  |  |         alloc, ptr, std::forward<Tuple>(t),  | 
4171  |  |         phmap::make_index_sequence<  | 
4172  |  |         std::tuple_size<typename std::decay<Tuple>::type>::value>());  | 
4173  |  | }  | 
4174  |  |  | 
4175  |  | // Constructs T using the args specified in the tuple and calls F with the  | 
4176  |  | // constructed value.  | 
4177  |  | // ----------------------------------------------------------------------------  | 
4178  |  | template <class T, class Tuple, class F>  | 
4179  |  | decltype(std::declval<F>()(std::declval<T>())) WithConstructed(  | 
4180  |  |     Tuple&& t, F&& f) { | 
4181  |  |     return memory_internal::WithConstructedImpl<T>(  | 
4182  |  |         std::forward<Tuple>(t),  | 
4183  |  |         phmap::make_index_sequence<  | 
4184  |  |         std::tuple_size<typename std::decay<Tuple>::type>::value>(),  | 
4185  |  |         std::forward<F>(f));  | 
4186  |  | }  | 
4187  |  |  | 
4188  |  | // ----------------------------------------------------------------------------  | 
4189  |  | // Given arguments of an std::pair's consructor, PairArgs() returns a pair of  | 
4190  |  | // tuples with references to the passed arguments. The tuples contain  | 
4191  |  | // constructor arguments for the first and the second elements of the pair.  | 
4192  |  | //  | 
4193  |  | // The following two snippets are equivalent.  | 
4194  |  | //  | 
4195  |  | // 1. std::pair<F, S> p(args...);  | 
4196  |  | //  | 
4197  |  | // 2. auto a = PairArgs(args...);  | 
4198  |  | //    std::pair<F, S> p(std::piecewise_construct,  | 
4199  |  | //                      std::move(p.first), std::move(p.second));  | 
4200  |  | // ----------------------------------------------------------------------------  | 
4201  | 0  | inline std::pair<std::tuple<>, std::tuple<>> PairArgs() { return {}; } | 
4202  |  |  | 
4203  |  | template <class F, class S>  | 
4204  | 26.2M  | std::pair<std::tuple<F&&>, std::tuple<S&&>> PairArgs(F&& f, S&& s) { | 
4205  | 26.2M  |   return {std::piecewise_construct, std::forward_as_tuple(std::forward<F>(f)), | 
4206  | 26.2M  |           std::forward_as_tuple(std::forward<S>(s))};  | 
4207  | 26.2M  | } std::__1::pair<std::__1::tuple<unsigned int const&>, std::__1::tuple<int const&> > phmap::priv::PairArgs<unsigned int const&, int const&>(unsigned int const&, int const&) Line  | Count  | Source  |  4204  | 14.9M  | std::pair<std::tuple<F&&>, std::tuple<S&&>> PairArgs(F&& f, S&& s) { |  4205  | 14.9M  |   return {std::piecewise_construct, std::forward_as_tuple(std::forward<F>(f)), |  4206  | 14.9M  |           std::forward_as_tuple(std::forward<S>(s))};  |  4207  | 14.9M  | }  |  
 std::__1::pair<std::__1::tuple<unsigned int const&&>, std::__1::tuple<int&&> > phmap::priv::PairArgs<unsigned int const, int>(unsigned int const&&, int&&) Line  | Count  | Source  |  4204  | 11.3M  | std::pair<std::tuple<F&&>, std::tuple<S&&>> PairArgs(F&& f, S&& s) { |  4205  | 11.3M  |   return {std::piecewise_construct, std::forward_as_tuple(std::forward<F>(f)), |  4206  | 11.3M  |           std::forward_as_tuple(std::forward<S>(s))};  |  4207  | 11.3M  | }  |  
  | 
4208  |  |  | 
4209  |  | template <class F, class S>  | 
4210  |  | std::pair<std::tuple<const F&>, std::tuple<const S&>> PairArgs(  | 
4211  | 14.9M  |     const std::pair<F, S>& p) { | 
4212  | 14.9M  |     return PairArgs(p.first, p.second);  | 
4213  | 14.9M  | }  | 
4214  |  |  | 
4215  |  | template <class F, class S>  | 
4216  | 11.3M  | std::pair<std::tuple<F&&>, std::tuple<S&&>> PairArgs(std::pair<F, S>&& p) { | 
4217  | 11.3M  |     return PairArgs(std::forward<F>(p.first), std::forward<S>(p.second));  | 
4218  | 11.3M  | }  | 
4219  |  |  | 
4220  |  | template <class F, class S>  | 
4221  |  | auto PairArgs(std::piecewise_construct_t, F&& f, S&& s)  | 
4222  |  |     -> decltype(std::make_pair(memory_internal::TupleRef(std::forward<F>(f)),  | 
4223  |  |                                memory_internal::TupleRef(std::forward<S>(s)))) { | 
4224  |  |     return std::make_pair(memory_internal::TupleRef(std::forward<F>(f)),  | 
4225  |  |                           memory_internal::TupleRef(std::forward<S>(s)));  | 
4226  |  | }  | 
4227  |  |  | 
4228  |  | // A helper function for implementing apply() in map policies.  | 
4229  |  | // ----------------------------------------------------------------------------  | 
4230  |  | template <class F, class... Args>  | 
4231  |  | auto DecomposePair(F&& f, Args&&... args)  | 
4232  |  |     -> decltype(memory_internal::DecomposePairImpl(  | 
4233  | 26.2M  |         std::forward<F>(f), PairArgs(std::forward<Args>(args)...))) { | 
4234  | 26.2M  |     return memory_internal::DecomposePairImpl(  | 
4235  | 26.2M  |         std::forward<F>(f), PairArgs(std::forward<Args>(args)...));  | 
4236  | 26.2M  | } _ZN5phmap4priv13DecomposePairINS0_12raw_hash_setINS0_17FlatHashMapPolicyIjiEENS_4HashIjEENS_7EqualToIjEENSt3__19allocatorINS9_4pairIKjiEEEEE19EmplaceDecomposableEJSD_EEEDTclsr15memory_internalE17DecomposePairImplclsr3stdE7forwardIT_Efp_Ecl8PairArgsspclsr3stdE7forwardIT0_Efp0_EEEEOSH_DpOSI_ Line  | Count  | Source  |  4233  | 11.3M  |         std::forward<F>(f), PairArgs(std::forward<Args>(args)...))) { |  4234  | 11.3M  |     return memory_internal::DecomposePairImpl(  |  4235  | 11.3M  |         std::forward<F>(f), PairArgs(std::forward<Args>(args)...));  |  4236  | 11.3M  | }  |  
 _ZN5phmap4priv13DecomposePairINS0_12raw_hash_setINS0_17FlatHashMapPolicyIjiEENS_4HashIjEENS_7EqualToIjEENSt3__19allocatorINS9_4pairIKjiEEEEE12EqualElementIjEEJRSD_EEEDTclsr15memory_internalE17DecomposePairImplclsr3stdE7forwardIT_Efp_Ecl8PairArgsspclsr3stdE7forwardIT0_Efp0_EEEEOSJ_DpOSK_ Line  | Count  | Source  |  4233  | 13.4M  |         std::forward<F>(f), PairArgs(std::forward<Args>(args)...))) { |  4234  | 13.4M  |     return memory_internal::DecomposePairImpl(  |  4235  | 13.4M  |         std::forward<F>(f), PairArgs(std::forward<Args>(args)...));  |  4236  | 13.4M  | }  |  
 _ZN5phmap4priv13DecomposePairINS0_12raw_hash_setINS0_17FlatHashMapPolicyIjiEENS_4HashIjEENS_7EqualToIjEENSt3__19allocatorINS9_4pairIKjiEEEEE11HashElementEJRSD_EEEDTclsr15memory_internalE17DecomposePairImplclsr3stdE7forwardIT_Efp_Ecl8PairArgsspclsr3stdE7forwardIT0_Efp0_EEEEOSI_DpOSJ_ Line  | Count  | Source  |  4233  | 984k  |         std::forward<F>(f), PairArgs(std::forward<Args>(args)...))) { |  4234  | 984k  |     return memory_internal::DecomposePairImpl(  |  4235  | 984k  |         std::forward<F>(f), PairArgs(std::forward<Args>(args)...));  |  4236  | 984k  | }  |  
 _ZN5phmap4priv13DecomposePairINS0_12raw_hash_setINS0_17FlatHashMapPolicyIjiEENS_4HashIjEENS_7EqualToIjEENSt3__19allocatorINS9_4pairIKjiEEEEE11HashElementEJRKSD_EEEDTclsr15memory_internalE17DecomposePairImplclsr3stdE7forwardIT_Efp_Ecl8PairArgsspclsr3stdE7forwardIT0_Efp0_EEEEOSJ_DpOSK_ Line  | Count  | Source  |  4233  | 522k  |         std::forward<F>(f), PairArgs(std::forward<Args>(args)...))) { |  4234  | 522k  |     return memory_internal::DecomposePairImpl(  |  4235  | 522k  |         std::forward<F>(f), PairArgs(std::forward<Args>(args)...));  |  4236  | 522k  | }  |  
  | 
4237  |  |  | 
4238  |  | // A helper function for implementing apply() in set policies.  | 
4239  |  | // ----------------------------------------------------------------------------  | 
4240  |  | template <class F, class Arg>  | 
4241  |  | decltype(std::declval<F>()(std::declval<const Arg&>(), std::declval<Arg>()))  | 
4242  |  | DecomposeValue(F&& f, Arg&& arg) { | 
4243  |  |     const auto& key = arg;  | 
4244  |  |     return std::forward<F>(f)(key, std::forward<Arg>(arg));  | 
4245  |  | }  | 
4246  |  |  | 
4247  |  |  | 
4248  |  | // --------------------------------------------------------------------------  | 
4249  |  | // Policy: a policy defines how to perform different operations on  | 
4250  |  | // the slots of the hashtable (see hash_policy_traits.h for the full interface  | 
4251  |  | // of policy).  | 
4252  |  | //  | 
4253  |  | // Hash: a (possibly polymorphic) functor that hashes keys of the hashtable. The  | 
4254  |  | // functor should accept a key and return size_t as hash. For best performance  | 
4255  |  | // it is important that the hash function provides high entropy across all bits  | 
4256  |  | // of the hash.  | 
4257  |  | //  | 
4258  |  | // Eq: a (possibly polymorphic) functor that compares two keys for equality. It  | 
4259  |  | // should accept two (of possibly different type) keys and return a bool: true  | 
4260  |  | // if they are equal, false if they are not. If two keys compare equal, then  | 
4261  |  | // their hash values as defined by Hash MUST be equal.  | 
4262  |  | //  | 
4263  |  | // Allocator: an Allocator [https://devdocs.io/cpp/concept/allocator] with which  | 
4264  |  | // the storage of the hashtable will be allocated and the elements will be  | 
4265  |  | // constructed and destroyed.  | 
4266  |  | // --------------------------------------------------------------------------  | 
4267  |  | template <class T>  | 
4268  |  | struct FlatHashSetPolicy   | 
4269  |  | { | 
4270  |  |     using slot_type = T;  | 
4271  |  |     using key_type = T;  | 
4272  |  |     using init_type = T;  | 
4273  |  |     using constant_iterators = std::true_type;  | 
4274  |  |     using is_flat = std::true_type;  | 
4275  |  |  | 
4276  |  |     template <class Allocator, class... Args>  | 
4277  |  |     static void construct(Allocator* alloc, slot_type* slot, Args&&... args) { | 
4278  |  |         phmap::allocator_traits<Allocator>::construct(*alloc, slot,  | 
4279  |  |                                                       std::forward<Args>(args)...);  | 
4280  |  |     }  | 
4281  |  |  | 
4282  |  |     template <class Allocator>  | 
4283  |  |     static void destroy(Allocator* alloc, slot_type* slot) { | 
4284  |  |         phmap::allocator_traits<Allocator>::destroy(*alloc, slot);  | 
4285  |  |     }  | 
4286  |  |  | 
4287  |  |     template <class Allocator>  | 
4288  |  |     static void transfer(Allocator* alloc, slot_type* new_slot,  | 
4289  |  |                          slot_type* old_slot) { | 
4290  |  |         construct(alloc, new_slot, std::move(*old_slot));  | 
4291  |  |         destroy(alloc, old_slot);  | 
4292  |  |     }  | 
4293  |  |  | 
4294  |  |     static T& element(slot_type* slot) { return *slot; } | 
4295  |  |  | 
4296  |  |     template <class F, class... Args>  | 
4297  |  |     static decltype(phmap::priv::DecomposeValue(  | 
4298  |  |                         std::declval<F>(), std::declval<Args>()...))  | 
4299  |  |     apply(F&& f, Args&&... args) { | 
4300  |  |         return phmap::priv::DecomposeValue(  | 
4301  |  |             std::forward<F>(f), std::forward<Args>(args)...);  | 
4302  |  |     }  | 
4303  |  |  | 
4304  |  |     static size_t space_used(const T*) { return 0; } | 
4305  |  | };  | 
4306  |  |  | 
4307  |  | // --------------------------------------------------------------------------  | 
4308  |  | // --------------------------------------------------------------------------  | 
4309  |  | template <class K, class V>  | 
4310  |  | struct FlatHashMapPolicy   | 
4311  |  | { | 
4312  |  |     using slot_policy = priv::map_slot_policy<K, V>;  | 
4313  |  |     using slot_type = typename slot_policy::slot_type;  | 
4314  |  |     using key_type = K;  | 
4315  |  |     using mapped_type = V;  | 
4316  |  |     using init_type = std::pair</*non const*/ key_type, mapped_type>;  | 
4317  |  |     using is_flat = std::true_type;  | 
4318  |  |  | 
4319  |  |     template <class Allocator, class... Args>  | 
4320  | 538k  |     static void construct(Allocator* alloc, slot_type* slot, Args&&... args) { | 
4321  | 538k  |         slot_policy::construct(alloc, slot, std::forward<Args>(args)...);  | 
4322  | 538k  |     }  | 
4323  |  |  | 
4324  |  |     template <class Allocator>  | 
4325  | 0  |     static void destroy(Allocator* alloc, slot_type* slot) { | 
4326  | 0  |         slot_policy::destroy(alloc, slot);  | 
4327  | 0  |     }  | 
4328  |  |  | 
4329  |  |     template <class Allocator>  | 
4330  |  |     static void transfer(Allocator* alloc, slot_type* new_slot,  | 
4331  | 984k  |                          slot_type* old_slot) { | 
4332  | 984k  |         slot_policy::transfer(alloc, new_slot, old_slot);  | 
4333  | 984k  |     }  | 
4334  |  |  | 
4335  |  |     template <class F, class... Args>  | 
4336  |  |     static decltype(phmap::priv::DecomposePair(  | 
4337  |  |                         std::declval<F>(), std::declval<Args>()...))  | 
4338  | 26.2M  |     apply(F&& f, Args&&... args) { | 
4339  | 26.2M  |         return phmap::priv::DecomposePair(std::forward<F>(f),  | 
4340  | 26.2M  |                                                         std::forward<Args>(args)...);  | 
4341  | 26.2M  |     } _ZN5phmap4priv17FlatHashMapPolicyIjiE5applyINS0_12raw_hash_setIS2_NS_4HashIjEENS_7EqualToIjEENSt3__19allocatorINS9_4pairIKjiEEEEE19EmplaceDecomposableEJSD_EEEDTclsr5phmap4privE13DecomposePairclsr3stdE7declvalIT_EEspclsr3stdE7declvalIT0_EEEEOSH_DpOSI_ Line  | Count  | Source  |  4338  | 11.3M  |     apply(F&& f, Args&&... args) { |  4339  | 11.3M  |         return phmap::priv::DecomposePair(std::forward<F>(f),  |  4340  | 11.3M  |                                                         std::forward<Args>(args)...);  |  4341  | 11.3M  |     }  |  
 _ZN5phmap4priv17FlatHashMapPolicyIjiE5applyINS0_12raw_hash_setIS2_NS_4HashIjEENS_7EqualToIjEENSt3__19allocatorINS9_4pairIKjiEEEEE12EqualElementIjEEJRSD_EEEDTclsr5phmap4privE13DecomposePairclsr3stdE7declvalIT_EEspclsr3stdE7declvalIT0_EEEEOSJ_DpOSK_ Line  | Count  | Source  |  4338  | 13.4M  |     apply(F&& f, Args&&... args) { |  4339  | 13.4M  |         return phmap::priv::DecomposePair(std::forward<F>(f),  |  4340  | 13.4M  |                                                         std::forward<Args>(args)...);  |  4341  | 13.4M  |     }  |  
 _ZN5phmap4priv17FlatHashMapPolicyIjiE5applyINS0_12raw_hash_setIS2_NS_4HashIjEENS_7EqualToIjEENSt3__19allocatorINS9_4pairIKjiEEEEE11HashElementEJRSD_EEEDTclsr5phmap4privE13DecomposePairclsr3stdE7declvalIT_EEspclsr3stdE7declvalIT0_EEEEOSI_DpOSJ_ Line  | Count  | Source  |  4338  | 984k  |     apply(F&& f, Args&&... args) { |  4339  | 984k  |         return phmap::priv::DecomposePair(std::forward<F>(f),  |  4340  | 984k  |                                                         std::forward<Args>(args)...);  |  4341  | 984k  |     }  |  
 _ZN5phmap4priv17FlatHashMapPolicyIjiE5applyINS0_12raw_hash_setIS2_NS_4HashIjEENS_7EqualToIjEENSt3__19allocatorINS9_4pairIKjiEEEEE11HashElementEJRKSD_EEEDTclsr5phmap4privE13DecomposePairclsr3stdE7declvalIT_EEspclsr3stdE7declvalIT0_EEEEOSJ_DpOSK_ Line  | Count  | Source  |  4338  | 522k  |     apply(F&& f, Args&&... args) { |  4339  | 522k  |         return phmap::priv::DecomposePair(std::forward<F>(f),  |  4340  | 522k  |                                                         std::forward<Args>(args)...);  |  4341  | 522k  |     }  |  
  | 
4342  |  |  | 
4343  |  |     static size_t space_used(const slot_type*) { return 0; } | 
4344  |  |  | 
4345  | 15.4M  |     static std::pair<const K, V>& element(slot_type* slot) { return slot->value; }phmap::priv::FlatHashMapPolicy<unsigned int, int>::element(phmap::priv::map_slot_type<unsigned int, int>*) Line  | Count  | Source  |  4345  | 15.4M  |     static std::pair<const K, V>& element(slot_type* slot) { return slot->value; } |  
 Unexecuted instantiation: phmap::priv::FlatHashMapPolicy<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::element(phmap::priv::map_slot_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >*)  | 
4346  |  |  | 
4347  |  |     static V& value(std::pair<const K, V>* kv) { return kv->second; } | 
4348  |  |     static const V& value(const std::pair<const K, V>* kv) { return kv->second; } | 
4349  |  | };  | 
4350  |  |  | 
4351  |  | template <class Reference, class Policy>  | 
4352  |  | struct node_hash_policy { | 
4353  |  |     static_assert(std::is_lvalue_reference<Reference>::value, "");  | 
4354  |  |  | 
4355  |  |     using slot_type = typename std::remove_cv<  | 
4356  |  |         typename std::remove_reference<Reference>::type>::type*;  | 
4357  |  |  | 
4358  |  |     template <class Alloc, class... Args>  | 
4359  |  |     static void construct(Alloc* alloc, slot_type* slot, Args&&... args) { | 
4360  |  |         *slot = Policy::new_element(alloc, std::forward<Args>(args)...);  | 
4361  |  |     }  | 
4362  |  |  | 
4363  |  |     template <class Alloc>  | 
4364  |  |     static void destroy(Alloc* alloc, slot_type* slot) { | 
4365  |  |         Policy::delete_element(alloc, *slot);  | 
4366  |  |     }  | 
4367  |  |  | 
4368  |  |     template <class Alloc>  | 
4369  |  |     static void transfer(Alloc*, slot_type* new_slot, slot_type* old_slot) { | 
4370  |  |         *new_slot = *old_slot;  | 
4371  |  |     }  | 
4372  |  |  | 
4373  |  |     static size_t space_used(const slot_type* slot) { | 
4374  |  |         if (slot == nullptr) return Policy::element_space_used(nullptr);  | 
4375  |  |         return Policy::element_space_used(*slot);  | 
4376  |  |     }  | 
4377  |  |  | 
4378  |  |     static Reference element(slot_type* slot) { return **slot; } | 
4379  |  |  | 
4380  |  |     template <class T, class P = Policy>  | 
4381  |  |     static auto value(T* elem) -> decltype(P::value(elem)) { | 
4382  |  |         return P::value(elem);  | 
4383  |  |     }  | 
4384  |  |  | 
4385  |  |     template <class... Ts, class P = Policy>  | 
4386  |  |     static auto apply(Ts&&... ts) -> decltype(P::apply(std::forward<Ts>(ts)...)) { | 
4387  |  |         return P::apply(std::forward<Ts>(ts)...);  | 
4388  |  |     }  | 
4389  |  | };  | 
4390  |  |  | 
4391  |  | // --------------------------------------------------------------------------  | 
4392  |  | // --------------------------------------------------------------------------  | 
4393  |  | template <class T>  | 
4394  |  | struct NodeHashSetPolicy  | 
4395  |  |     : phmap::priv::node_hash_policy<T&, NodeHashSetPolicy<T>>   | 
4396  |  | { | 
4397  |  |     using key_type = T;  | 
4398  |  |     using init_type = T;  | 
4399  |  |     using constant_iterators = std::true_type;  | 
4400  |  |     using is_flat = std::false_type;  | 
4401  |  |  | 
4402  |  |     template <class Allocator, class... Args>  | 
4403  |  |         static T* new_element(Allocator* alloc, Args&&... args) { | 
4404  |  |         using ValueAlloc =  | 
4405  |  |             typename phmap::allocator_traits<Allocator>::template rebind_alloc<T>;  | 
4406  |  |         ValueAlloc value_alloc(*alloc);  | 
4407  |  |         T* res = phmap::allocator_traits<ValueAlloc>::allocate(value_alloc, 1);  | 
4408  |  |         phmap::allocator_traits<ValueAlloc>::construct(value_alloc, res,  | 
4409  |  |                                                        std::forward<Args>(args)...);  | 
4410  |  |         return res;  | 
4411  |  |     }  | 
4412  |  |  | 
4413  |  |     template <class Allocator>  | 
4414  |  |         static void delete_element(Allocator* alloc, T* elem) { | 
4415  |  |         using ValueAlloc =  | 
4416  |  |             typename phmap::allocator_traits<Allocator>::template rebind_alloc<T>;  | 
4417  |  |         ValueAlloc value_alloc(*alloc);  | 
4418  |  |         phmap::allocator_traits<ValueAlloc>::destroy(value_alloc, elem);  | 
4419  |  |         phmap::allocator_traits<ValueAlloc>::deallocate(value_alloc, elem, 1);  | 
4420  |  |     }  | 
4421  |  |  | 
4422  |  |     template <class F, class... Args>  | 
4423  |  |         static decltype(phmap::priv::DecomposeValue(  | 
4424  |  |                             std::declval<F>(), std::declval<Args>()...))  | 
4425  |  |         apply(F&& f, Args&&... args) { | 
4426  |  |         return phmap::priv::DecomposeValue(  | 
4427  |  |             std::forward<F>(f), std::forward<Args>(args)...);  | 
4428  |  |     }  | 
4429  |  |  | 
4430  |  |     static size_t element_space_used(const T*) { return sizeof(T); } | 
4431  |  | };  | 
4432  |  |  | 
4433  |  | // --------------------------------------------------------------------------  | 
4434  |  | // --------------------------------------------------------------------------  | 
4435  |  | template <class Key, class Value>  | 
4436  |  | class NodeHashMapPolicy  | 
4437  |  |     : public phmap::priv::node_hash_policy<  | 
4438  |  |           std::pair<const Key, Value>&, NodeHashMapPolicy<Key, Value>>   | 
4439  |  | { | 
4440  |  |     using value_type = std::pair<const Key, Value>;  | 
4441  |  |  | 
4442  |  | public:  | 
4443  |  |     using key_type = Key;  | 
4444  |  |     using mapped_type = Value;  | 
4445  |  |     using init_type = std::pair</*non const*/ key_type, mapped_type>;  | 
4446  |  |     using is_flat = std::false_type;  | 
4447  |  |  | 
4448  |  |     template <class Allocator, class... Args>  | 
4449  |  |         static value_type* new_element(Allocator* alloc, Args&&... args) { | 
4450  |  |         using PairAlloc = typename phmap::allocator_traits<  | 
4451  |  |             Allocator>::template rebind_alloc<value_type>;  | 
4452  |  |         PairAlloc pair_alloc(*alloc);  | 
4453  |  |         value_type* res =  | 
4454  |  |             phmap::allocator_traits<PairAlloc>::allocate(pair_alloc, 1);  | 
4455  |  |         phmap::allocator_traits<PairAlloc>::construct(pair_alloc, res,  | 
4456  |  |                                                       std::forward<Args>(args)...);  | 
4457  |  |         return res;  | 
4458  |  |     }  | 
4459  |  |  | 
4460  |  |     template <class Allocator>  | 
4461  |  |         static void delete_element(Allocator* alloc, value_type* pair) { | 
4462  |  |         using PairAlloc = typename phmap::allocator_traits<  | 
4463  |  |             Allocator>::template rebind_alloc<value_type>;  | 
4464  |  |         PairAlloc pair_alloc(*alloc);  | 
4465  |  |         phmap::allocator_traits<PairAlloc>::destroy(pair_alloc, pair);  | 
4466  |  |         phmap::allocator_traits<PairAlloc>::deallocate(pair_alloc, pair, 1);  | 
4467  |  |     }  | 
4468  |  |  | 
4469  |  |     template <class F, class... Args>  | 
4470  |  |         static decltype(phmap::priv::DecomposePair(  | 
4471  |  |                             std::declval<F>(), std::declval<Args>()...))  | 
4472  |  |         apply(F&& f, Args&&... args) { | 
4473  |  |         return phmap::priv::DecomposePair(std::forward<F>(f),  | 
4474  |  |                                                         std::forward<Args>(args)...);  | 
4475  |  |     }  | 
4476  |  |  | 
4477  |  |     static size_t element_space_used(const value_type*) { | 
4478  |  |         return sizeof(value_type);  | 
4479  |  |     }  | 
4480  |  |  | 
4481  |  |     static Value& value(value_type* elem) { return elem->second; } | 
4482  |  |     static const Value& value(const value_type* elem) { return elem->second; } | 
4483  |  | };  | 
4484  |  |  | 
4485  |  |  | 
4486  |  | // --------------------------------------------------------------------------  | 
4487  |  | //  hash_default  | 
4488  |  | // --------------------------------------------------------------------------  | 
4489  |  |  | 
4490  |  | #if PHMAP_HAVE_STD_STRING_VIEW  | 
4491  |  |  | 
4492  |  | // Supports heterogeneous lookup for basic_string<T>-like elements.  | 
4493  |  | template<class CharT>   | 
4494  |  | struct StringHashEqT  | 
4495  |  | { | 
4496  |  |     struct Hash   | 
4497  |  |     { | 
4498  |  |         using is_transparent = void;  | 
4499  |  |           | 
4500  |  |         size_t operator()(std::basic_string_view<CharT> v) const { | 
4501  |  |             std::string_view bv{ | 
4502  |  |                 reinterpret_cast<const char*>(v.data()), v.size() * sizeof(CharT)};  | 
4503  |  |             return std::hash<std::string_view>()(bv);  | 
4504  |  |         }  | 
4505  |  |     };  | 
4506  |  |  | 
4507  |  |     struct Eq { | 
4508  |  |         using is_transparent = void;  | 
4509  |  |  | 
4510  |  |         bool operator()(std::basic_string_view<CharT> lhs,  | 
4511  |  |                         std::basic_string_view<CharT> rhs) const { | 
4512  |  |             return lhs == rhs;  | 
4513  |  |         }  | 
4514  |  |     };  | 
4515  |  | };  | 
4516  |  |  | 
4517  |  | template <>  | 
4518  |  | struct HashEq<std::string> : StringHashEqT<char> {}; | 
4519  |  |  | 
4520  |  | template <>  | 
4521  |  | struct HashEq<std::string_view> : StringHashEqT<char> {}; | 
4522  |  |  | 
4523  |  | // char16_t  | 
4524  |  | template <>  | 
4525  |  | struct HashEq<std::u16string> : StringHashEqT<char16_t> {}; | 
4526  |  |  | 
4527  |  | template <>  | 
4528  |  | struct HashEq<std::u16string_view> : StringHashEqT<char16_t> {}; | 
4529  |  |  | 
4530  |  | // wchar_t  | 
4531  |  | template <>  | 
4532  |  | struct HashEq<std::wstring> : StringHashEqT<wchar_t> {}; | 
4533  |  |  | 
4534  |  | template <>  | 
4535  |  | struct HashEq<std::wstring_view> : StringHashEqT<wchar_t> {}; | 
4536  |  |  | 
4537  |  | #endif  | 
4538  |  |  | 
4539  |  | // Supports heterogeneous lookup for pointers and smart pointers.  | 
4540  |  | // -------------------------------------------------------------  | 
4541  |  | template <class T>  | 
4542  |  | struct HashEq<T*>   | 
4543  |  | { | 
4544  |  |     struct Hash { | 
4545  |  |         using is_transparent = void;  | 
4546  |  |         template <class U>  | 
4547  |  |         size_t operator()(const U& ptr) const { | 
4548  |  |             // we want phmap::Hash<T*> and not phmap::Hash<const T*>  | 
4549  |  |             // so "struct std::hash<T*> " override works  | 
4550  |  |             return phmap::Hash<T*>{}((T*)(uintptr_t)HashEq::ToPtr(ptr)); | 
4551  |  |         }  | 
4552  |  |     };  | 
4553  |  |  | 
4554  |  |     struct Eq { | 
4555  |  |         using is_transparent = void;  | 
4556  |  |         template <class A, class B>  | 
4557  |  |         bool operator()(const A& a, const B& b) const { | 
4558  |  |             return HashEq::ToPtr(a) == HashEq::ToPtr(b);  | 
4559  |  |         }  | 
4560  |  |     };  | 
4561  |  |  | 
4562  |  | private:  | 
4563  |  |     static const T* ToPtr(const T* ptr) { return ptr; } | 
4564  |  |  | 
4565  |  |     template <class U, class D>  | 
4566  |  |     static const T* ToPtr(const std::unique_ptr<U, D>& ptr) { | 
4567  |  |         return ptr.get();  | 
4568  |  |     }  | 
4569  |  |  | 
4570  |  |     template <class U>  | 
4571  |  |     static const T* ToPtr(const std::shared_ptr<U>& ptr) { | 
4572  |  |         return ptr.get();  | 
4573  |  |     }  | 
4574  |  | };  | 
4575  |  |  | 
4576  |  | template <class T, class D>  | 
4577  |  | struct HashEq<std::unique_ptr<T, D>> : HashEq<T*> {}; | 
4578  |  |  | 
4579  |  | template <class T>  | 
4580  |  | struct HashEq<std::shared_ptr<T>> : HashEq<T*> {}; | 
4581  |  |  | 
4582  |  | namespace hashtable_debug_internal { | 
4583  |  |  | 
4584  |  | // --------------------------------------------------------------------------  | 
4585  |  | // --------------------------------------------------------------------------  | 
4586  |  |  | 
4587  |  | template<typename, typename = void >  | 
4588  |  | struct has_member_type_raw_hash_set : std::false_type  | 
4589  |  | {}; | 
4590  |  | template<typename T>  | 
4591  |  | struct has_member_type_raw_hash_set<T, phmap::void_t<typename T::raw_hash_set>> : std::true_type  | 
4592  |  | {}; | 
4593  |  |  | 
4594  |  | template <typename Set>  | 
4595  |  | struct HashtableDebugAccess<Set, typename std::enable_if<has_member_type_raw_hash_set<Set>::value>::type>  | 
4596  |  | { | 
4597  |  |     using Traits = typename Set::PolicyTraits;  | 
4598  |  |     using Slot = typename Traits::slot_type;  | 
4599  |  |  | 
4600  |  |     static size_t GetNumProbes(const Set& set,  | 
4601  |  |                                const typename Set::key_type& key) { | 
4602  |  |         if (!set.ctrl_)  | 
4603  |  |             return 0;  | 
4604  |  |         size_t num_probes = 0;  | 
4605  |  |         size_t hashval = set.hash(key);   | 
4606  |  |         auto seq = set.probe(hashval);  | 
4607  |  |         while (true) { | 
4608  |  |             priv::Group g{set.ctrl_ + seq.offset()}; | 
4609  |  |             for (uint32_t i : g.Match((h2_t)priv::H2(hashval))) { | 
4610  |  |                 if (Traits::apply(  | 
4611  |  |                         typename Set::template EqualElement<typename Set::key_type>{ | 
4612  |  |                             key, set.eq_ref()},  | 
4613  |  |                         Traits::element(set.slots_ + seq.offset((size_t)i))))  | 
4614  |  |                     return num_probes;  | 
4615  |  |                 ++num_probes;  | 
4616  |  |             }  | 
4617  |  |             if (g.MatchEmpty()) return num_probes;  | 
4618  |  |             seq.next();  | 
4619  |  |             ++num_probes;  | 
4620  |  |         }  | 
4621  |  |     }  | 
4622  |  |  | 
4623  |  |     static size_t AllocatedByteSize(const Set& c) { | 
4624  |  |         size_t capacity = c.capacity_;  | 
4625  |  |         if (capacity == 0) return 0;  | 
4626  |  |         auto layout = Set::MakeLayout(capacity);  | 
4627  |  |         size_t m = layout.AllocSize();  | 
4628  |  |  | 
4629  |  |         size_t per_slot = Traits::space_used(static_cast<const Slot*>(nullptr));  | 
4630  |  |         if (per_slot != ~size_t{}) { | 
4631  |  |             m += per_slot * c.size();  | 
4632  |  |         } else { | 
4633  |  |             for (size_t i = 0; i != capacity; ++i) { | 
4634  |  |                 if (priv::IsFull(c.ctrl_[i])) { | 
4635  |  |                     m += Traits::space_used(c.slots_ + i);  | 
4636  |  |                 }  | 
4637  |  |             }  | 
4638  |  |         }  | 
4639  |  |         return m;  | 
4640  |  |     }  | 
4641  |  |  | 
4642  |  |     static size_t LowerBoundAllocatedByteSize(size_t size) { | 
4643  |  |         size_t capacity = GrowthToLowerboundCapacity(size);  | 
4644  |  |         if (capacity == 0) return 0;  | 
4645  |  |         auto layout = Set::MakeLayout(NormalizeCapacity(capacity));  | 
4646  |  |         size_t m = layout.AllocSize();  | 
4647  |  |         size_t per_slot = Traits::space_used(static_cast<const Slot*>(nullptr));  | 
4648  |  |         if (per_slot != ~size_t{}) { | 
4649  |  |             m += per_slot * size;  | 
4650  |  |         }  | 
4651  |  |         return m;  | 
4652  |  |     }  | 
4653  |  | };  | 
4654  |  |  | 
4655  |  |  | 
4656  |  | template<typename, typename = void >  | 
4657  |  | struct has_member_type_EmbeddedSet : std::false_type  | 
4658  |  | {}; | 
4659  |  | template<typename T>  | 
4660  |  | struct has_member_type_EmbeddedSet<T, phmap::void_t<typename T::EmbeddedSet>> : std::true_type  | 
4661  |  | {}; | 
4662  |  |  | 
4663  |  | template <typename Set>  | 
4664  |  | struct HashtableDebugAccess<Set, typename std::enable_if<has_member_type_EmbeddedSet<Set>::value>::type> { | 
4665  |  |     using Traits = typename Set::PolicyTraits;  | 
4666  |  |     using Slot = typename Traits::slot_type;  | 
4667  |  |     using EmbeddedSet = typename Set::EmbeddedSet;  | 
4668  |  |  | 
4669  |  |     static size_t GetNumProbes(const Set& set, const typename Set::key_type& key) { | 
4670  |  |         size_t hashval = set.hash(key);  | 
4671  |  |         auto& inner = set.sets_[set.subidx(hashval)];  | 
4672  |  |         auto& inner_set = inner.set_;  | 
4673  |  |         return HashtableDebugAccess<EmbeddedSet>::GetNumProbes(inner_set, key);  | 
4674  |  |     }  | 
4675  |  | };  | 
4676  |  |  | 
4677  |  | }  // namespace hashtable_debug_internal  | 
4678  |  | }  // namespace priv  | 
4679  |  |  | 
4680  |  | // -----------------------------------------------------------------------------  | 
4681  |  | // phmap::flat_hash_set  | 
4682  |  | // -----------------------------------------------------------------------------  | 
4683  |  | // An `phmap::flat_hash_set<T>` is an unordered associative container which has  | 
4684  |  | // been optimized for both speed and memory footprint in most common use cases.  | 
4685  |  | // Its interface is similar to that of `std::unordered_set<T>` with the  | 
4686  |  | // following notable differences:  | 
4687  |  | //  | 
4688  |  | // * Supports heterogeneous lookup, through `find()`, `operator[]()` and  | 
4689  |  | //   `insert()`, provided that the set is provided a compatible heterogeneous  | 
4690  |  | //   hashing function and equality operator.  | 
4691  |  | // * Invalidates any references and pointers to elements within the table after  | 
4692  |  | //   `rehash()`.  | 
4693  |  | // * Contains a `capacity()` member function indicating the number of element  | 
4694  |  | //   slots (open, deleted, and empty) within the hash set.  | 
4695  |  | // * Returns `void` from the `_erase(iterator)` overload.  | 
4696  |  | // -----------------------------------------------------------------------------  | 
4697  |  | template <class T, class Hash, class Eq, class Alloc> // default values in phmap_fwd_decl.h  | 
4698  |  | class flat_hash_set  | 
4699  |  |     : public phmap::priv::raw_hash_set<  | 
4700  |  |           phmap::priv::FlatHashSetPolicy<T>, Hash, Eq, Alloc>   | 
4701  |  | { | 
4702  |  |     using Base = typename flat_hash_set::raw_hash_set;  | 
4703  |  |  | 
4704  |  | public:  | 
4705  |  |     flat_hash_set() {} | 
4706  |  | #ifdef __INTEL_COMPILER  | 
4707  |  |     using Base::raw_hash_set;  | 
4708  |  | #else  | 
4709  |  |     using Base::Base;  | 
4710  |  | #endif  | 
4711  |  |     using Base::begin;  | 
4712  |  |     using Base::cbegin;  | 
4713  |  |     using Base::cend;  | 
4714  |  |     using Base::end;  | 
4715  |  |     using Base::capacity;  | 
4716  |  |     using Base::empty;  | 
4717  |  |     using Base::max_size;  | 
4718  |  |     using Base::size;  | 
4719  |  |     using Base::clear; // may shrink - To avoid shrinking `erase(begin(), end())`  | 
4720  |  |     using Base::erase;  | 
4721  |  |     using Base::insert;  | 
4722  |  |     using Base::emplace;  | 
4723  |  |     using Base::emplace_hint;   | 
4724  |  |     using Base::extract;  | 
4725  |  |     using Base::merge;  | 
4726  |  |     using Base::swap;  | 
4727  |  |     using Base::rehash;  | 
4728  |  |     using Base::reserve;  | 
4729  |  |     using Base::contains;  | 
4730  |  |     using Base::count;  | 
4731  |  |     using Base::equal_range;  | 
4732  |  |     using Base::find;  | 
4733  |  |     using Base::bucket_count;  | 
4734  |  |     using Base::load_factor;  | 
4735  |  |     using Base::max_load_factor;  | 
4736  |  |     using Base::get_allocator;  | 
4737  |  |     using Base::hash_function;  | 
4738  |  |     using Base::hash;  | 
4739  |  |     using Base::key_eq;  | 
4740  |  | };  | 
4741  |  |  | 
4742  |  | // -----------------------------------------------------------------------------  | 
4743  |  | // phmap::flat_hash_map  | 
4744  |  | // -----------------------------------------------------------------------------  | 
4745  |  | //  | 
4746  |  | // An `phmap::flat_hash_map<K, V>` is an unordered associative container which  | 
4747  |  | // has been optimized for both speed and memory footprint in most common use  | 
4748  |  | // cases. Its interface is similar to that of `std::unordered_map<K, V>` with  | 
4749  |  | // the following notable differences:  | 
4750  |  | //  | 
4751  |  | // * Supports heterogeneous lookup, through `find()`, `operator[]()` and  | 
4752  |  | //   `insert()`, provided that the map is provided a compatible heterogeneous  | 
4753  |  | //   hashing function and equality operator.  | 
4754  |  | // * Invalidates any references and pointers to elements within the table after  | 
4755  |  | //   `rehash()`.  | 
4756  |  | // * Contains a `capacity()` member function indicating the number of element  | 
4757  |  | //   slots (open, deleted, and empty) within the hash map.  | 
4758  |  | // * Returns `void` from the `_erase(iterator)` overload.  | 
4759  |  | // -----------------------------------------------------------------------------  | 
4760  |  | template <class K, class V, class Hash, class Eq, class Alloc> // default values in phmap_fwd_decl.h  | 
4761  |  | class flat_hash_map : public phmap::priv::raw_hash_map<  | 
4762  |  |                           phmap::priv::FlatHashMapPolicy<K, V>,  | 
4763  |  |                           Hash, Eq, Alloc> { | 
4764  |  |     using Base = typename flat_hash_map::raw_hash_map;  | 
4765  |  |  | 
4766  |  | public:  | 
4767  | 1.78k  |     flat_hash_map() {}phmap::flat_hash_map<unsigned int, int, phmap::Hash<unsigned int>, phmap::EqualTo<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, int> > >::flat_hash_map() Line  | Count  | Source  |  4767  | 1.19k  |     flat_hash_map() {} |  
 phmap::flat_hash_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, phmap::priv::StringHashEqT<char>::Hash, phmap::priv::StringHashEqT<char>::Eq, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >::flat_hash_map() Line  | Count  | Source  |  4767  | 595  |     flat_hash_map() {} |  
  | 
4768  |  | #ifdef __INTEL_COMPILER  | 
4769  |  |     using Base::raw_hash_map;  | 
4770  |  | #else  | 
4771  |  |     using Base::Base;  | 
4772  |  | #endif  | 
4773  |  |     using Base::begin;  | 
4774  |  |     using Base::cbegin;  | 
4775  |  |     using Base::cend;  | 
4776  |  |     using Base::end;  | 
4777  |  |     using Base::capacity;  | 
4778  |  |     using Base::empty;  | 
4779  |  |     using Base::max_size;  | 
4780  |  |     using Base::size;  | 
4781  |  |     using Base::clear;  | 
4782  |  |     using Base::erase;  | 
4783  |  |     using Base::insert;  | 
4784  |  |     using Base::insert_or_assign;  | 
4785  |  |     using Base::emplace;  | 
4786  |  |     using Base::emplace_hint;  | 
4787  |  |     using Base::try_emplace;  | 
4788  |  |     using Base::extract;  | 
4789  |  |     using Base::merge;  | 
4790  |  |     using Base::swap;  | 
4791  |  |     using Base::rehash;  | 
4792  |  |     using Base::reserve;  | 
4793  |  |     using Base::at;  | 
4794  |  |     using Base::contains;  | 
4795  |  |     using Base::count;  | 
4796  |  |     using Base::equal_range;  | 
4797  |  |     using Base::find;  | 
4798  |  |     using Base::operator[];  | 
4799  |  |     using Base::bucket_count;  | 
4800  |  |     using Base::load_factor;  | 
4801  |  |     using Base::max_load_factor;  | 
4802  |  |     using Base::get_allocator;  | 
4803  |  |     using Base::hash_function;  | 
4804  |  |     using Base::hash;  | 
4805  |  |     using Base::key_eq;  | 
4806  |  | };  | 
4807  |  |  | 
4808  |  | // -----------------------------------------------------------------------------  | 
4809  |  | // phmap::node_hash_set  | 
4810  |  | // -----------------------------------------------------------------------------  | 
4811  |  | // An `phmap::node_hash_set<T>` is an unordered associative container which  | 
4812  |  | // has been optimized for both speed and memory footprint in most common use  | 
4813  |  | // cases. Its interface is similar to that of `std::unordered_set<T>` with the  | 
4814  |  | // following notable differences:  | 
4815  |  | //  | 
4816  |  | // * Supports heterogeneous lookup, through `find()`, `operator[]()` and  | 
4817  |  | //   `insert()`, provided that the map is provided a compatible heterogeneous  | 
4818  |  | //   hashing function and equality operator.  | 
4819  |  | // * Contains a `capacity()` member function indicating the number of element  | 
4820  |  | //   slots (open, deleted, and empty) within the hash set.  | 
4821  |  | // * Returns `void` from the `_erase(iterator)` overload.  | 
4822  |  | // -----------------------------------------------------------------------------  | 
4823  |  | template <class T, class Hash, class Eq, class Alloc> // default values in phmap_fwd_decl.h  | 
4824  |  | class node_hash_set  | 
4825  |  |     : public phmap::priv::raw_hash_set<  | 
4826  |  |           phmap::priv::NodeHashSetPolicy<T>, Hash, Eq, Alloc>   | 
4827  |  | { | 
4828  |  |     using Base = typename node_hash_set::raw_hash_set;  | 
4829  |  |  | 
4830  |  | public:  | 
4831  |  |     node_hash_set() {} | 
4832  |  | #ifdef __INTEL_COMPILER  | 
4833  |  |     using Base::raw_hash_set;  | 
4834  |  | #else  | 
4835  |  |     using Base::Base;  | 
4836  |  | #endif  | 
4837  |  |     using Base::begin;  | 
4838  |  |     using Base::cbegin;  | 
4839  |  |     using Base::cend;  | 
4840  |  |     using Base::end;  | 
4841  |  |     using Base::capacity;  | 
4842  |  |     using Base::empty;  | 
4843  |  |     using Base::max_size;  | 
4844  |  |     using Base::size;  | 
4845  |  |     using Base::clear;  | 
4846  |  |     using Base::erase;  | 
4847  |  |     using Base::insert;  | 
4848  |  |     using Base::emplace;  | 
4849  |  |     using Base::emplace_hint;  | 
4850  |  |     using Base::emplace_with_hash;  | 
4851  |  |     using Base::emplace_hint_with_hash;  | 
4852  |  |     using Base::extract;  | 
4853  |  |     using Base::merge;  | 
4854  |  |     using Base::swap;  | 
4855  |  |     using Base::rehash;  | 
4856  |  |     using Base::reserve;  | 
4857  |  |     using Base::contains;  | 
4858  |  |     using Base::count;  | 
4859  |  |     using Base::equal_range;  | 
4860  |  |     using Base::find;  | 
4861  |  |     using Base::bucket_count;  | 
4862  |  |     using Base::load_factor;  | 
4863  |  |     using Base::max_load_factor;  | 
4864  |  |     using Base::get_allocator;  | 
4865  |  |     using Base::hash_function;  | 
4866  |  |     using Base::hash;  | 
4867  |  |     using Base::key_eq;  | 
4868  |  |     typename Base::hasher hash_funct() { return this->hash_function(); } | 
4869  |  |     void resize(typename Base::size_type hint) { this->rehash(hint); } | 
4870  |  | };  | 
4871  |  |  | 
4872  |  | // -----------------------------------------------------------------------------  | 
4873  |  | // phmap::node_hash_map  | 
4874  |  | // -----------------------------------------------------------------------------  | 
4875  |  | //  | 
4876  |  | // An `phmap::node_hash_map<K, V>` is an unordered associative container which  | 
4877  |  | // has been optimized for both speed and memory footprint in most common use  | 
4878  |  | // cases. Its interface is similar to that of `std::unordered_map<K, V>` with  | 
4879  |  | // the following notable differences:  | 
4880  |  | //  | 
4881  |  | // * Supports heterogeneous lookup, through `find()`, `operator[]()` and  | 
4882  |  | //   `insert()`, provided that the map is provided a compatible heterogeneous  | 
4883  |  | //   hashing function and equality operator.  | 
4884  |  | // * Contains a `capacity()` member function indicating the number of element  | 
4885  |  | //   slots (open, deleted, and empty) within the hash map.  | 
4886  |  | // * Returns `void` from the `_erase(iterator)` overload.  | 
4887  |  | // -----------------------------------------------------------------------------  | 
4888  |  | template <class Key, class Value, class Hash, class Eq, class Alloc>  // default values in phmap_fwd_decl.h  | 
4889  |  | class node_hash_map  | 
4890  |  |     : public phmap::priv::raw_hash_map<  | 
4891  |  |           phmap::priv::NodeHashMapPolicy<Key, Value>, Hash, Eq,  | 
4892  |  |           Alloc>   | 
4893  |  | { | 
4894  |  |     using Base = typename node_hash_map::raw_hash_map;  | 
4895  |  |  | 
4896  |  | public:  | 
4897  |  |     node_hash_map() {} | 
4898  |  | #ifdef __INTEL_COMPILER  | 
4899  |  |     using Base::raw_hash_map;  | 
4900  |  | #else  | 
4901  |  |     using Base::Base;  | 
4902  |  | #endif  | 
4903  |  |     using Base::begin;  | 
4904  |  |     using Base::cbegin;  | 
4905  |  |     using Base::cend;  | 
4906  |  |     using Base::end;  | 
4907  |  |     using Base::capacity;  | 
4908  |  |     using Base::empty;  | 
4909  |  |     using Base::max_size;  | 
4910  |  |     using Base::size;  | 
4911  |  |     using Base::clear;  | 
4912  |  |     using Base::erase;  | 
4913  |  |     using Base::insert;  | 
4914  |  |     using Base::insert_or_assign;  | 
4915  |  |     using Base::emplace;  | 
4916  |  |     using Base::emplace_hint;  | 
4917  |  |     using Base::try_emplace;  | 
4918  |  |     using Base::extract;  | 
4919  |  |     using Base::merge;  | 
4920  |  |     using Base::swap;  | 
4921  |  |     using Base::rehash;  | 
4922  |  |     using Base::reserve;  | 
4923  |  |     using Base::at;  | 
4924  |  |     using Base::contains;  | 
4925  |  |     using Base::count;  | 
4926  |  |     using Base::equal_range;  | 
4927  |  |     using Base::find;  | 
4928  |  |     using Base::operator[];  | 
4929  |  |     using Base::bucket_count;  | 
4930  |  |     using Base::load_factor;  | 
4931  |  |     using Base::max_load_factor;  | 
4932  |  |     using Base::get_allocator;  | 
4933  |  |     using Base::hash_function;  | 
4934  |  |     using Base::hash;  | 
4935  |  |     using Base::key_eq;  | 
4936  |  |     typename Base::hasher hash_funct() { return this->hash_function(); } | 
4937  |  |     void resize(typename Base::size_type hint) { this->rehash(hint); } | 
4938  |  | };  | 
4939  |  |  | 
4940  |  | // -----------------------------------------------------------------------------  | 
4941  |  | // phmap::parallel_flat_hash_set  | 
4942  |  | // -----------------------------------------------------------------------------  | 
4943  |  | template <class T, class Hash, class Eq, class Alloc, size_t N, class Mtx_> // default values in phmap_fwd_decl.h  | 
4944  |  | class parallel_flat_hash_set  | 
4945  |  |     : public phmap::priv::parallel_hash_set<  | 
4946  |  |          N, phmap::priv::raw_hash_set, Mtx_,  | 
4947  |  |          phmap::priv::FlatHashSetPolicy<T>,   | 
4948  |  |          Hash, Eq, Alloc>   | 
4949  |  | { | 
4950  |  |     using Base = typename parallel_flat_hash_set::parallel_hash_set;  | 
4951  |  |  | 
4952  |  | public:  | 
4953  |  |     parallel_flat_hash_set() {} | 
4954  |  | #ifdef __INTEL_COMPILER  | 
4955  |  |     using Base::parallel_hash_set;  | 
4956  |  | #else  | 
4957  |  |     using Base::Base;  | 
4958  |  | #endif  | 
4959  |  |     using Base::hash;  | 
4960  |  |     using Base::subidx;  | 
4961  |  |     using Base::subcnt;  | 
4962  |  |     using Base::begin;  | 
4963  |  |     using Base::cbegin;  | 
4964  |  |     using Base::cend;  | 
4965  |  |     using Base::end;  | 
4966  |  |     using Base::capacity;  | 
4967  |  |     using Base::empty;  | 
4968  |  |     using Base::max_size;  | 
4969  |  |     using Base::size;  | 
4970  |  |     using Base::clear;  | 
4971  |  |     using Base::erase;  | 
4972  |  |     using Base::insert;  | 
4973  |  |     using Base::emplace;  | 
4974  |  |     using Base::emplace_hint;  | 
4975  |  |     using Base::emplace_with_hash;  | 
4976  |  |     using Base::emplace_hint_with_hash;  | 
4977  |  |     using Base::extract;  | 
4978  |  |     using Base::merge;  | 
4979  |  |     using Base::swap;  | 
4980  |  |     using Base::rehash;  | 
4981  |  |     using Base::reserve;  | 
4982  |  |     using Base::contains;  | 
4983  |  |     using Base::count;  | 
4984  |  |     using Base::equal_range;  | 
4985  |  |     using Base::find;  | 
4986  |  |     using Base::bucket_count;  | 
4987  |  |     using Base::load_factor;  | 
4988  |  |     using Base::max_load_factor;  | 
4989  |  |     using Base::get_allocator;  | 
4990  |  |     using Base::hash_function;  | 
4991  |  |     using Base::key_eq;  | 
4992  |  | };  | 
4993  |  |  | 
4994  |  | // -----------------------------------------------------------------------------  | 
4995  |  | // phmap::parallel_flat_hash_map - default values in phmap_fwd_decl.h  | 
4996  |  | // -----------------------------------------------------------------------------  | 
4997  |  | template <class K, class V, class Hash, class Eq, class Alloc, size_t N, class Mtx_>  | 
4998  |  | class parallel_flat_hash_map : public phmap::priv::parallel_hash_map<  | 
4999  |  |                 N, phmap::priv::raw_hash_set, Mtx_,  | 
5000  |  |                 phmap::priv::FlatHashMapPolicy<K, V>,  | 
5001  |  |                 Hash, Eq, Alloc>   | 
5002  |  | { | 
5003  |  |     using Base = typename parallel_flat_hash_map::parallel_hash_map;  | 
5004  |  |  | 
5005  |  | public:  | 
5006  |  |     parallel_flat_hash_map() {} | 
5007  |  | #ifdef __INTEL_COMPILER  | 
5008  |  |     using Base::parallel_hash_map;  | 
5009  |  | #else  | 
5010  |  |     using Base::Base;  | 
5011  |  | #endif  | 
5012  |  |     using Base::hash;  | 
5013  |  |     using Base::subidx;  | 
5014  |  |     using Base::subcnt;  | 
5015  |  |     using Base::begin;  | 
5016  |  |     using Base::cbegin;  | 
5017  |  |     using Base::cend;  | 
5018  |  |     using Base::end;  | 
5019  |  |     using Base::capacity;  | 
5020  |  |     using Base::empty;  | 
5021  |  |     using Base::max_size;  | 
5022  |  |     using Base::size;  | 
5023  |  |     using Base::clear;  | 
5024  |  |     using Base::erase;  | 
5025  |  |     using Base::insert;  | 
5026  |  |     using Base::insert_or_assign;  | 
5027  |  |     using Base::emplace;  | 
5028  |  |     using Base::emplace_hint;  | 
5029  |  |     using Base::try_emplace;  | 
5030  |  |     using Base::emplace_with_hash;  | 
5031  |  |     using Base::emplace_hint_with_hash;  | 
5032  |  |     using Base::try_emplace_with_hash;  | 
5033  |  |     using Base::extract;  | 
5034  |  |     using Base::merge;  | 
5035  |  |     using Base::swap;  | 
5036  |  |     using Base::rehash;  | 
5037  |  |     using Base::reserve;  | 
5038  |  |     using Base::at;  | 
5039  |  |     using Base::contains;  | 
5040  |  |     using Base::count;  | 
5041  |  |     using Base::equal_range;  | 
5042  |  |     using Base::find;  | 
5043  |  |     using Base::operator[];  | 
5044  |  |     using Base::bucket_count;  | 
5045  |  |     using Base::load_factor;  | 
5046  |  |     using Base::max_load_factor;  | 
5047  |  |     using Base::get_allocator;  | 
5048  |  |     using Base::hash_function;  | 
5049  |  |     using Base::key_eq;  | 
5050  |  | };  | 
5051  |  |  | 
5052  |  | // -----------------------------------------------------------------------------  | 
5053  |  | // phmap::parallel_node_hash_set  | 
5054  |  | // -----------------------------------------------------------------------------  | 
5055  |  | template <class T, class Hash, class Eq, class Alloc, size_t N, class Mtx_>  | 
5056  |  | class parallel_node_hash_set  | 
5057  |  |     : public phmap::priv::parallel_hash_set<  | 
5058  |  |              N, phmap::priv::raw_hash_set, Mtx_,  | 
5059  |  |              phmap::priv::NodeHashSetPolicy<T>, Hash, Eq, Alloc>   | 
5060  |  | { | 
5061  |  |     using Base = typename parallel_node_hash_set::parallel_hash_set;  | 
5062  |  |  | 
5063  |  | public:  | 
5064  |  |     parallel_node_hash_set() {} | 
5065  |  | #ifdef __INTEL_COMPILER  | 
5066  |  |     using Base::parallel_hash_set;  | 
5067  |  | #else  | 
5068  |  |     using Base::Base;  | 
5069  |  | #endif  | 
5070  |  |     using Base::hash;  | 
5071  |  |     using Base::subidx;  | 
5072  |  |     using Base::subcnt;  | 
5073  |  |     using Base::begin;  | 
5074  |  |     using Base::cbegin;  | 
5075  |  |     using Base::cend;  | 
5076  |  |     using Base::end;  | 
5077  |  |     using Base::capacity;  | 
5078  |  |     using Base::empty;  | 
5079  |  |     using Base::max_size;  | 
5080  |  |     using Base::size;  | 
5081  |  |     using Base::clear;  | 
5082  |  |     using Base::erase;  | 
5083  |  |     using Base::insert;  | 
5084  |  |     using Base::emplace;  | 
5085  |  |     using Base::emplace_hint;  | 
5086  |  |     using Base::emplace_with_hash;  | 
5087  |  |     using Base::emplace_hint_with_hash;  | 
5088  |  |     using Base::extract;  | 
5089  |  |     using Base::merge;  | 
5090  |  |     using Base::swap;  | 
5091  |  |     using Base::rehash;  | 
5092  |  |     using Base::reserve;  | 
5093  |  |     using Base::contains;  | 
5094  |  |     using Base::count;  | 
5095  |  |     using Base::equal_range;  | 
5096  |  |     using Base::find;  | 
5097  |  |     using Base::bucket_count;  | 
5098  |  |     using Base::load_factor;  | 
5099  |  |     using Base::max_load_factor;  | 
5100  |  |     using Base::get_allocator;  | 
5101  |  |     using Base::hash_function;  | 
5102  |  |     using Base::key_eq;  | 
5103  |  |     typename Base::hasher hash_funct() { return this->hash_function(); } | 
5104  |  |     void resize(typename Base::size_type hint) { this->rehash(hint); } | 
5105  |  | };  | 
5106  |  |  | 
5107  |  | // -----------------------------------------------------------------------------  | 
5108  |  | // phmap::parallel_node_hash_map  | 
5109  |  | // -----------------------------------------------------------------------------  | 
5110  |  | template <class Key, class Value, class Hash, class Eq, class Alloc, size_t N, class Mtx_>  | 
5111  |  | class parallel_node_hash_map  | 
5112  |  |     : public phmap::priv::parallel_hash_map<  | 
5113  |  |           N, phmap::priv::raw_hash_set, Mtx_,  | 
5114  |  |           phmap::priv::NodeHashMapPolicy<Key, Value>, Hash, Eq,  | 
5115  |  |           Alloc>   | 
5116  |  | { | 
5117  |  |     using Base = typename parallel_node_hash_map::parallel_hash_map;  | 
5118  |  |  | 
5119  |  | public:  | 
5120  |  |     parallel_node_hash_map() {} | 
5121  |  | #ifdef __INTEL_COMPILER  | 
5122  |  |     using Base::parallel_hash_map;  | 
5123  |  | #else  | 
5124  |  |     using Base::Base;  | 
5125  |  | #endif  | 
5126  |  |     using Base::hash;  | 
5127  |  |     using Base::subidx;  | 
5128  |  |     using Base::subcnt;  | 
5129  |  |     using Base::begin;  | 
5130  |  |     using Base::cbegin;  | 
5131  |  |     using Base::cend;  | 
5132  |  |     using Base::end;  | 
5133  |  |     using Base::capacity;  | 
5134  |  |     using Base::empty;  | 
5135  |  |     using Base::max_size;  | 
5136  |  |     using Base::size;  | 
5137  |  |     using Base::clear;  | 
5138  |  |     using Base::erase;  | 
5139  |  |     using Base::insert;  | 
5140  |  |     using Base::insert_or_assign;  | 
5141  |  |     using Base::emplace;  | 
5142  |  |     using Base::emplace_hint;  | 
5143  |  |     using Base::try_emplace;  | 
5144  |  |     using Base::emplace_with_hash;  | 
5145  |  |     using Base::emplace_hint_with_hash;  | 
5146  |  |     using Base::try_emplace_with_hash;  | 
5147  |  |     using Base::extract;  | 
5148  |  |     using Base::merge;  | 
5149  |  |     using Base::swap;  | 
5150  |  |     using Base::rehash;  | 
5151  |  |     using Base::reserve;  | 
5152  |  |     using Base::at;  | 
5153  |  |     using Base::contains;  | 
5154  |  |     using Base::count;  | 
5155  |  |     using Base::equal_range;  | 
5156  |  |     using Base::find;  | 
5157  |  |     using Base::operator[];  | 
5158  |  |     using Base::bucket_count;  | 
5159  |  |     using Base::load_factor;  | 
5160  |  |     using Base::max_load_factor;  | 
5161  |  |     using Base::get_allocator;  | 
5162  |  |     using Base::hash_function;  | 
5163  |  |     using Base::key_eq;  | 
5164  |  |     typename Base::hasher hash_funct() { return this->hash_function(); } | 
5165  |  |     void resize(typename Base::size_type hint) { this->rehash(hint); } | 
5166  |  | };  | 
5167  |  |  | 
5168  |  | }  // namespace phmap  | 
5169  |  |  | 
5170  |  |  | 
5171  |  | namespace phmap { | 
5172  |  |     namespace priv { | 
5173  |  |         template <class C, class Pred>   | 
5174  |  |         std::size_t erase_if(C &c, Pred pred) { | 
5175  |  |             auto old_size = c.size();  | 
5176  |  |             for (auto i = c.begin(), last = c.end(); i != last; ) { | 
5177  |  |                 if (pred(*i)) { | 
5178  |  |                     i = c.erase(i);  | 
5179  |  |                 } else { | 
5180  |  |                     ++i;  | 
5181  |  |                 }  | 
5182  |  |             }  | 
5183  |  |             return old_size - c.size();  | 
5184  |  |         }  | 
5185  |  |     } // priv  | 
5186  |  |  | 
5187  |  |     // ======== erase_if for phmap set containers ==================================  | 
5188  |  |     template <class T, class Hash, class Eq, class Alloc, class Pred>   | 
5189  |  |     std::size_t erase_if(phmap::flat_hash_set<T, Hash, Eq, Alloc>& c, Pred pred) { | 
5190  |  |         return phmap::priv::erase_if(c, std::move(pred));  | 
5191  |  |     }  | 
5192  |  |  | 
5193  |  |     template <class T, class Hash, class Eq, class Alloc, class Pred>   | 
5194  |  |     std::size_t erase_if(phmap::node_hash_set<T, Hash, Eq, Alloc>& c, Pred pred) { | 
5195  |  |         return phmap::priv::erase_if(c, std::move(pred));  | 
5196  |  |     }  | 
5197  |  |  | 
5198  |  |     template <class T, class Hash, class Eq, class Alloc, size_t N, class Mtx_, class Pred>   | 
5199  |  |     std::size_t erase_if(phmap::parallel_flat_hash_set<T, Hash, Eq, Alloc, N, Mtx_>& c, Pred pred) { | 
5200  |  |         return phmap::priv::erase_if(c, std::move(pred));  | 
5201  |  |     }  | 
5202  |  |  | 
5203  |  |     template <class T, class Hash, class Eq, class Alloc, size_t N, class Mtx_, class Pred>   | 
5204  |  |     std::size_t erase_if(phmap::parallel_node_hash_set<T, Hash, Eq, Alloc, N, Mtx_>& c, Pred pred) { | 
5205  |  |         return phmap::priv::erase_if(c, std::move(pred));  | 
5206  |  |     }  | 
5207  |  |  | 
5208  |  |     // ======== erase_if for phmap map containers ==================================  | 
5209  |  |     template <class K, class V, class Hash, class Eq, class Alloc, class Pred>   | 
5210  |  |     std::size_t erase_if(phmap::flat_hash_map<K, V, Hash, Eq, Alloc>& c, Pred pred) { | 
5211  |  |         return phmap::priv::erase_if(c, std::move(pred));  | 
5212  |  |     }  | 
5213  |  |  | 
5214  |  |     template <class K, class V, class Hash, class Eq, class Alloc, class Pred>   | 
5215  |  |     std::size_t erase_if(phmap::node_hash_map<K, V, Hash, Eq, Alloc>& c, Pred pred) { | 
5216  |  |         return phmap::priv::erase_if(c, std::move(pred));  | 
5217  |  |     }  | 
5218  |  |  | 
5219  |  |     template <class K, class V, class Hash, class Eq, class Alloc, size_t N, class Mtx_, class Pred>   | 
5220  |  |     std::size_t erase_if(phmap::parallel_flat_hash_map<K, V, Hash, Eq, Alloc, N, Mtx_>& c, Pred pred) { | 
5221  |  |         return phmap::priv::erase_if(c, std::move(pred));  | 
5222  |  |     }  | 
5223  |  |  | 
5224  |  |     template <class K, class V, class Hash, class Eq, class Alloc, size_t N, class Mtx_, class Pred>   | 
5225  |  |     std::size_t erase_if(phmap::parallel_node_hash_map<K, V, Hash, Eq, Alloc, N, Mtx_>& c, Pred pred) { | 
5226  |  |         return phmap::priv::erase_if(c, std::move(pred));  | 
5227  |  |     }  | 
5228  |  |  | 
5229  |  | } // phmap  | 
5230  |  |  | 
5231  |  | #ifdef _MSC_VER  | 
5232  |  |      #pragma warning(pop)    | 
5233  |  | #endif  | 
5234  |  |  | 
5235  |  |  | 
5236  |  | #endif // phmap_h_guard_  |