Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
concurrent_unordered_set.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2019 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16 
17 
18 
19 */
20 
21 /* Container implementations in this header are based on PPL implementations
22  provided by Microsoft. */
23 
24 #ifndef __TBB_concurrent_unordered_set_H
25 #define __TBB_concurrent_unordered_set_H
26 
29 
30 namespace tbb
31 {
32 
33 namespace interface5 {
34 
35 // Template class for hash set traits
36 template<typename Key, typename Hash_compare, typename Allocator, bool Allow_multimapping>
38 {
39 protected:
40  typedef Key value_type;
41  typedef Key key_type;
42  typedef Hash_compare hash_compare;
44 
45  enum { allow_multimapping = Allow_multimapping };
46 
48  concurrent_unordered_set_traits(const hash_compare& hc) : my_hash_compare(hc) {}
49 
50  static const Key& get_key(const value_type& value) {
51  return value;
52  }
53 
54  hash_compare my_hash_compare; // the comparator predicate for keys
55 };
56 
57 template <typename Key, typename Hasher = tbb::tbb_hash<Key>, typename Key_equality = std::equal_to<Key>, typename Allocator = tbb::tbb_allocator<Key> >
58 class concurrent_unordered_set : public internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key, internal::hash_compare<Key, Hasher, Key_equality>, Allocator, false> >
59 {
60  // Base type definitions
61  typedef internal::hash_compare<Key, Hasher, Key_equality> hash_compare;
63  typedef internal::concurrent_unordered_base< traits_type > base_type;
64 #if __TBB_EXTRA_DEBUG
65 public:
66 #endif
67  using traits_type::allow_multimapping;
68 public:
69  using base_type::insert;
70 
71  // Type definitions
72  typedef Key key_type;
73  typedef typename base_type::value_type value_type;
74  typedef Key mapped_type;
75  typedef Hasher hasher;
76  typedef Key_equality key_equal;
77  typedef hash_compare key_compare;
78 
79  typedef typename base_type::allocator_type allocator_type;
80  typedef typename base_type::pointer pointer;
81  typedef typename base_type::const_pointer const_pointer;
82  typedef typename base_type::reference reference;
83  typedef typename base_type::const_reference const_reference;
84 
85  typedef typename base_type::size_type size_type;
86  typedef typename base_type::difference_type difference_type;
87 
88  typedef typename base_type::iterator iterator;
89  typedef typename base_type::const_iterator const_iterator;
90  typedef typename base_type::iterator local_iterator;
91  typedef typename base_type::const_iterator const_local_iterator;
92 
93  // Construction/destruction/copying
94  explicit concurrent_unordered_set(size_type n_of_buckets = base_type::initial_bucket_number, const hasher& a_hasher = hasher(),
95  const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
96  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
97  {}
98 
99  concurrent_unordered_set(size_type n_of_buckets, const allocator_type& a)
100  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
101  {}
102 
103  concurrent_unordered_set(size_type n_of_buckets, const hasher& a_hasher, const allocator_type& a)
104  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
105  {}
106 
107  explicit concurrent_unordered_set(const Allocator& a) : base_type(base_type::initial_bucket_number, key_compare(), a)
108  {}
109 
110  template <typename Iterator>
111  concurrent_unordered_set(Iterator first, Iterator last, size_type n_of_buckets = base_type::initial_bucket_number,
112  const hasher& a_hasher = hasher(), const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
113  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
114  {
115  insert(first, last);
116  }
117 
118  template <typename Iterator>
119  concurrent_unordered_set(Iterator first, Iterator last, size_type n_of_buckets, const allocator_type& a)
120  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
121  {
122  insert(first, last);
123  }
124 
125  template <typename Iterator>
126  concurrent_unordered_set(Iterator first, Iterator last, size_type n_of_buckets, const hasher& a_hasher, const allocator_type& a)
127  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
128  {
129  insert(first, last);
130  }
131 
132 #if __TBB_INITIALIZER_LISTS_PRESENT
133  concurrent_unordered_set(std::initializer_list<value_type> il, size_type n_of_buckets = base_type::initial_bucket_number, const hasher& a_hasher = hasher(),
135  const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
136  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
137  {
138  insert(il.begin(),il.end());
139  }
140 
141  concurrent_unordered_set(std::initializer_list<value_type> il, size_type n_of_buckets, const allocator_type& a)
142  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
143  {
144  insert(il.begin(), il.end());
145  }
146 
147  concurrent_unordered_set(std::initializer_list<value_type> il, size_type n_of_buckets, const hasher& a_hasher, const allocator_type& a)
148  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
149  {
150  insert(il.begin(), il.end());
151  }
152 
153 #endif //# __TBB_INITIALIZER_LISTS_PRESENT
154 
155 #if __TBB_CPP11_RVALUE_REF_PRESENT
156 #if !__TBB_IMPLICIT_MOVE_PRESENT
158  : base_type(table)
159  {}
160 
161  concurrent_unordered_set& operator=(const concurrent_unordered_set& table)
162  {
163  return static_cast<concurrent_unordered_set&>(base_type::operator=(table));
164  }
165 
166  concurrent_unordered_set(concurrent_unordered_set&& table)
167  : base_type(std::move(table))
168  {}
169 
170  concurrent_unordered_set& operator=(concurrent_unordered_set&& table)
171  {
172  return static_cast<concurrent_unordered_set&>(base_type::operator=(std::move(table)));
173  }
174 #endif
175 
176  concurrent_unordered_set(concurrent_unordered_set&& table, const Allocator& a)
177  : base_type(std::move(table), a)
178  {}
179 #endif //__TBB_CPP11_RVALUE_REF_PRESENT
180 
181  concurrent_unordered_set(const concurrent_unordered_set& table, const Allocator& a)
182  : base_type(table, a)
183  {}
184 
185 };
186 
187 #if __TBB_CPP17_DEDUCTION_GUIDES_PRESENT
188 
189 namespace internal {
190 using namespace tbb::internal;
191 
192 template <template<typename...> typename Set, typename T, typename... Args>
193 using cu_set_t = Set <
194  T,
195  std::conditional_t< (sizeof...(Args)>0) && !is_allocator_v< pack_element_t<0, Args...> >,
196  pack_element_t<0, Args...>, tbb_hash<T> >,
197  std::conditional_t< (sizeof...(Args)>1) && !is_allocator_v< pack_element_t<1, Args...> >,
198  pack_element_t<1, Args...>, std::equal_to<T> >,
199  std::conditional_t< (sizeof...(Args)>0) && is_allocator_v< pack_element_t<sizeof...(Args)-1, Args...> >,
200  pack_element_t<sizeof...(Args)-1, Args...>, tbb_allocator<T> >
201 >;
202 }
203 
204 // Deduction guide for the constructor from two iterators
205 template<typename I>
207 -> internal::cu_set_t<concurrent_unordered_set, internal::iterator_value_t<I>>;
208 
209 // Deduction guide for the constructor from two iterators and hasher/equality/allocator
210 template<typename I, typename... Args>
211 concurrent_unordered_set(I, I, size_t, Args...)
212 -> internal::cu_set_t<concurrent_unordered_set, internal::iterator_value_t<I>, Args...>;
213 
214 // Deduction guide for the constructor from an initializer_list
215 template<typename T>
216 concurrent_unordered_set(std::initializer_list<T>)
217 -> internal::cu_set_t<concurrent_unordered_set, T>;
218 
219 // Deduction guide for the constructor from an initializer_list and hasher/equality/allocator
220 template<typename T, typename... Args>
221 concurrent_unordered_set(std::initializer_list<T>, size_t, Args...)
222 -> internal::cu_set_t<concurrent_unordered_set, T, Args...>;
223 
224 #endif /*__TBB_CPP17_DEDUCTION_GUIDES_PRESENT */
225 
226 template <typename Key, typename Hasher = tbb::tbb_hash<Key>, typename Key_equality = std::equal_to<Key>,
227  typename Allocator = tbb::tbb_allocator<Key> >
229  public internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key,
230  internal::hash_compare<Key, Hasher, Key_equality>, Allocator, true> >
231 {
232  // Base type definitions
233  typedef internal::hash_compare<Key, Hasher, Key_equality> hash_compare;
235  typedef internal::concurrent_unordered_base< traits_type > base_type;
236 #if __TBB_EXTRA_DEBUG
237 public:
238 #endif
239  using traits_type::allow_multimapping;
240 public:
241  using base_type::insert;
242 
243  // Type definitions
244  typedef Key key_type;
245  typedef typename base_type::value_type value_type;
246  typedef Key mapped_type;
247  typedef Hasher hasher;
248  typedef Key_equality key_equal;
249  typedef hash_compare key_compare;
250 
251  typedef typename base_type::allocator_type allocator_type;
252  typedef typename base_type::pointer pointer;
253  typedef typename base_type::const_pointer const_pointer;
254  typedef typename base_type::reference reference;
255  typedef typename base_type::const_reference const_reference;
256 
257  typedef typename base_type::size_type size_type;
258  typedef typename base_type::difference_type difference_type;
259 
260  typedef typename base_type::iterator iterator;
261  typedef typename base_type::const_iterator const_iterator;
262  typedef typename base_type::iterator local_iterator;
263  typedef typename base_type::const_iterator const_local_iterator;
264 
265  // Construction/destruction/copying
266  explicit concurrent_unordered_multiset(size_type n_of_buckets = base_type::initial_bucket_number,
267  const hasher& a_hasher = hasher(), const key_equal& a_keyeq = key_equal(),
268  const allocator_type& a = allocator_type())
269  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
270  {}
271 
272  concurrent_unordered_multiset(size_type n_of_buckets, const allocator_type& a)
273  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
274  {}
275 
276  concurrent_unordered_multiset(size_type n_of_buckets, const hasher& a_hasher,
277  const allocator_type& a)
278  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
279  {}
280 
281  explicit concurrent_unordered_multiset(const Allocator& a) : base_type(base_type::initial_bucket_number, key_compare(), a)
282  {}
283 
284  template <typename Iterator>
285  concurrent_unordered_multiset(Iterator first, Iterator last, size_type n_of_buckets = base_type::initial_bucket_number,
286  const hasher& a_hasher = hasher(), const key_equal& a_keyeq = key_equal(),
287  const allocator_type& a = allocator_type())
288  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
289  {
290  insert(first, last);
291  }
292 
293  template <typename Iterator>
294  concurrent_unordered_multiset(Iterator first, Iterator last, size_type n_of_buckets, const allocator_type& a)
295  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
296  {
297  insert(first, last);
298  }
299 
300  template <typename Iterator>
301  concurrent_unordered_multiset(Iterator first, Iterator last, size_type n_of_buckets, const hasher& a_hasher,
302  const allocator_type& a)
303  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
304  {
305  insert(first, last);
306  }
307 
308 #if __TBB_INITIALIZER_LISTS_PRESENT
309  concurrent_unordered_multiset(std::initializer_list<value_type> il, size_type n_of_buckets = base_type::initial_bucket_number,
311  const hasher& a_hasher = hasher(), const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
312  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
313  {
314  insert(il.begin(),il.end());
315  }
316 
317  concurrent_unordered_multiset(std::initializer_list<value_type> il, size_type n_of_buckets, const allocator_type& a)
318  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
319  {
320  insert(il.begin(), il.end());
321  }
322 
323  concurrent_unordered_multiset(std::initializer_list<value_type> il, size_type n_of_buckets, const hasher& a_hasher,
324  const allocator_type& a)
325  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
326  {
327  insert(il.begin(), il.end());
328  }
329 
330 #endif //# __TBB_INITIALIZER_LISTS_PRESENT
331 
332 #if __TBB_CPP11_RVALUE_REF_PRESENT
333 #if !__TBB_IMPLICIT_MOVE_PRESENT
335  : base_type(table)
336  {}
337 
338  concurrent_unordered_multiset& operator=(const concurrent_unordered_multiset& table)
339  {
340  return static_cast<concurrent_unordered_multiset&>(base_type::operator=(table));
341  }
342 
343  concurrent_unordered_multiset(concurrent_unordered_multiset&& table)
344  : base_type(std::move(table))
345  {}
346 
347  concurrent_unordered_multiset& operator=(concurrent_unordered_multiset&& table)
348  {
349  return static_cast<concurrent_unordered_multiset&>(base_type::operator=(std::move(table)));
350  }
351 #endif
352 
353  concurrent_unordered_multiset(concurrent_unordered_multiset&& table, const Allocator& a)
354  : base_type(std::move(table), a)
355  {
356  }
357 #endif //__TBB_CPP11_RVALUE_REF_PRESENT
358 
359  concurrent_unordered_multiset(const concurrent_unordered_multiset& table, const Allocator& a)
360  : base_type(table, a)
361  {}
362 };
363 
364 #if __TBB_CPP17_DEDUCTION_GUIDES_PRESENT
365 
366 // Deduction guide for the constructor from two iterators
367 template<typename I>
369 -> internal::cu_set_t<concurrent_unordered_multiset, internal::iterator_value_t<I>>;
370 
371 // Deduction guide for the constructor from two iterators and hasher/equality/allocator
372 template<typename I, typename... Args>
373 concurrent_unordered_multiset(I, I, size_t, Args...)
374 -> internal::cu_set_t<concurrent_unordered_multiset, internal::iterator_value_t<I>, Args...>;
375 
376 // Deduction guide for the constructor from an initializer_list
377 template<typename T>
378 concurrent_unordered_multiset(std::initializer_list<T>)
379 -> internal::cu_set_t<concurrent_unordered_multiset, T>;
380 
381 // Deduction guide for the constructor from an initializer_list and hasher/equality/allocator
382 template<typename T, typename... Args>
383 concurrent_unordered_multiset(std::initializer_list<T>, size_t, Args...)
384 -> internal::cu_set_t<concurrent_unordered_multiset, T, Args...>;
385 
386 #endif /* __TBB_CPP17_DEDUCTION_GUIDES_PRESENT */
387 } // namespace interface5
388 
391 
392 } // namespace tbb
393 
394 #endif// __TBB_concurrent_unordered_set_H
tbb::internal::allocator_rebind< Allocator, value_type >::type allocator_type
concurrent_unordered_set(Iterator first, Iterator last, size_type n_of_buckets=base_type::initial_bucket_number, const hasher &a_hasher=hasher(), const key_equal &a_keyeq=key_equal(), const allocator_type &a=allocator_type())
internal::hash_compare< Key, Hasher, Key_equality > hash_compare
concurrent_unordered_multiset(const concurrent_unordered_multiset &table, const Allocator &a)
concurrent_unordered_multiset(Iterator first, Iterator last, size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
static const Key & get_key(const value_type &value)
concurrent_unordered_set(Iterator first, Iterator last, size_type n_of_buckets, const allocator_type &a)
auto first(Container &c) -> decltype(begin(c))
internal::concurrent_unordered_base< traits_type > base_type
concurrent_unordered_set(size_type n_of_buckets=base_type::initial_bucket_number, const hasher &a_hasher=hasher(), const key_equal &a_keyeq=key_equal(), const allocator_type &a=allocator_type())
concurrent_unordered_set_traits< Key, hash_compare, Allocator, false > traits_type
concurrent_unordered_multiset(concurrent_unordered_multiset &&table, const Allocator &a)
__TBB_IMPLICIT_MOVE_PRESENT
concurrent_unordered_set(size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
auto last(Container &c) -> decltype(begin(c))
concurrent_unordered_set(concurrent_unordered_set &&table, const Allocator &a)
__TBB_IMPLICIT_MOVE_PRESENT
The graph class.
concurrent_unordered_set(std::initializer_list< value_type > il, size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
concurrent_unordered_multiset(Iterator first, Iterator last, size_type n_of_buckets, const allocator_type &a)
concurrent_unordered_set_traits< Key, hash_compare, Allocator, true > traits_type
concurrent_unordered_multiset(size_type n_of_buckets=base_type::initial_bucket_number, const hasher &a_hasher=hasher(), const key_equal &a_keyeq=key_equal(), const allocator_type &a=allocator_type())
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
concurrent_unordered_set(std::initializer_list< value_type > il, size_type n_of_buckets, const allocator_type &a)
concurrent_unordered_multiset(size_type n_of_buckets, const allocator_type &a)
allocator_traits< Alloc >::template rebind_alloc< T >::other type
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:309
internal::hash_compare< Key, Hasher, Key_equality > hash_compare
concurrent_unordered_multiset(size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
STL namespace.
concurrent_unordered_multiset(Iterator first, Iterator last, size_type n_of_buckets=base_type::initial_bucket_number, const hasher &a_hasher=hasher(), const key_equal &a_keyeq=key_equal(), const allocator_type &a=allocator_type())
concurrent_unordered_multiset(std::initializer_list< value_type > il, size_type n_of_buckets, const allocator_type &a)
concurrent_unordered_set(const concurrent_unordered_set &table, const Allocator &a)
Identifiers declared inside namespace internal should never be used directly by client code...
Definition: atomic.h:55
concurrent_unordered_multiset(std::initializer_list< value_type > il, size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
concurrent_unordered_set(Iterator first, Iterator last, size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
concurrent_unordered_set(size_type n_of_buckets, const allocator_type &a)
internal::concurrent_unordered_base< traits_type > base_type
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
Definition: tbb_allocator.h:62

Copyright © 2005-2019 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.