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-2018 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 
28 
29 namespace tbb
30 {
31 
32 namespace interface5 {
33 
34 // Template class for hash set traits
35 template<typename Key, typename Hash_compare, typename Allocator, bool Allow_multimapping>
37 {
38 protected:
39  typedef Key value_type;
40  typedef Key key_type;
41  typedef Hash_compare hash_compare;
42  typedef typename Allocator::template rebind<value_type>::other allocator_type;
43  enum { allow_multimapping = Allow_multimapping };
44 
47 
48  static const Key& get_key(const value_type& value) {
49  return value;
50  }
51 
52  hash_compare my_hash_compare; // the comparator predicate for keys
53 };
54 
55 template <typename Key, typename Hasher = tbb::tbb_hash<Key>, typename Key_equality = std::equal_to<Key>, typename Allocator = tbb::tbb_allocator<Key> >
56 class concurrent_unordered_set : public internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key, internal::hash_compare<Key, Hasher, Key_equality>, Allocator, false> >
57 {
58  // Base type definitions
59  typedef internal::hash_compare<Key, Hasher, Key_equality> hash_compare;
61  typedef internal::concurrent_unordered_base< traits_type > base_type;
62 #if __TBB_EXTRA_DEBUG
63 public:
64 #endif
66 public:
67  using base_type::insert;
68 
69  // Type definitions
70  typedef Key key_type;
71  typedef typename base_type::value_type value_type;
72  typedef Key mapped_type;
73  typedef Hasher hasher;
74  typedef Key_equality key_equal;
76 
77  typedef typename base_type::allocator_type allocator_type;
78  typedef typename base_type::pointer pointer;
79  typedef typename base_type::const_pointer const_pointer;
80  typedef typename base_type::reference reference;
81  typedef typename base_type::const_reference const_reference;
82 
83  typedef typename base_type::size_type size_type;
84  typedef typename base_type::difference_type difference_type;
85 
86  typedef typename base_type::iterator iterator;
87  typedef typename base_type::const_iterator const_iterator;
88  typedef typename base_type::iterator local_iterator;
89  typedef typename base_type::const_iterator const_local_iterator;
90 
91  // Construction/destruction/copying
92  explicit concurrent_unordered_set(size_type n_of_buckets = base_type::initial_bucket_number, const hasher& a_hasher = hasher(),
93  const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
94  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
95  {}
96 
98  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
99  {}
100 
101  concurrent_unordered_set(size_type n_of_buckets, const hasher& a_hasher, const allocator_type& a)
102  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
103  {}
104 
106  {}
107 
108  template <typename Iterator>
109  concurrent_unordered_set(Iterator first, Iterator last, size_type n_of_buckets = base_type::initial_bucket_number,
110  const hasher& a_hasher = hasher(), const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
111  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
112  {
113  insert(first, last);
114  }
115 
116  template <typename Iterator>
117  concurrent_unordered_set(Iterator first, Iterator last, size_type n_of_buckets, const allocator_type& a)
118  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
119  {
120  insert(first, last);
121  }
122 
123  template <typename Iterator>
124  concurrent_unordered_set(Iterator first, Iterator last, size_type n_of_buckets, const hasher& a_hasher, const allocator_type& a)
125  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
126  {
127  insert(first, last);
128  }
129 
130 #if __TBB_INITIALIZER_LISTS_PRESENT
131  concurrent_unordered_set(std::initializer_list<value_type> il, size_type n_of_buckets = base_type::initial_bucket_number, const hasher& a_hasher = hasher(),
133  const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
134  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
135  {
136  insert(il.begin(),il.end());
137  }
138 
139  concurrent_unordered_set(std::initializer_list<value_type> il, size_type n_of_buckets, const allocator_type& a)
140  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
141  {
142  insert(il.begin(), il.end());
143  }
144 
145  concurrent_unordered_set(std::initializer_list<value_type> il, size_type n_of_buckets, const hasher& a_hasher, const allocator_type& a)
146  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
147  {
148  insert(il.begin(), il.end());
149  }
150 
151 #endif //# __TBB_INITIALIZER_LISTS_PRESENT
152 
153 #if __TBB_CPP11_RVALUE_REF_PRESENT
154 #if !__TBB_IMPLICIT_MOVE_PRESENT
156  : base_type(table)
157  {}
158 
160  {
161  return static_cast<concurrent_unordered_set&>(base_type::operator=(table));
162  }
163 
165  : base_type(std::move(table))
166  {}
167 
169  {
170  return static_cast<concurrent_unordered_set&>(base_type::operator=(std::move(table)));
171  }
172 #endif
173 
175  : base_type(std::move(table), a)
176  {}
177 #endif //__TBB_CPP11_RVALUE_REF_PRESENT
178 
179  concurrent_unordered_set(const concurrent_unordered_set& table, const Allocator& a)
180  : base_type(table, a)
181  {}
182 
183 };
184 
185 template <typename Key, typename Hasher = tbb::tbb_hash<Key>, typename Key_equality = std::equal_to<Key>,
186  typename Allocator = tbb::tbb_allocator<Key> >
188  public internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key,
189  internal::hash_compare<Key, Hasher, Key_equality>, Allocator, true> >
190 {
191  // Base type definitions
192  typedef internal::hash_compare<Key, Hasher, Key_equality> hash_compare;
194  typedef internal::concurrent_unordered_base< traits_type > base_type;
195 #if __TBB_EXTRA_DEBUG
196 public:
197 #endif
199 public:
200  using base_type::insert;
201 
202  // Type definitions
203  typedef Key key_type;
204  typedef typename base_type::value_type value_type;
205  typedef Key mapped_type;
206  typedef Hasher hasher;
207  typedef Key_equality key_equal;
209 
210  typedef typename base_type::allocator_type allocator_type;
211  typedef typename base_type::pointer pointer;
212  typedef typename base_type::const_pointer const_pointer;
213  typedef typename base_type::reference reference;
214  typedef typename base_type::const_reference const_reference;
215 
216  typedef typename base_type::size_type size_type;
217  typedef typename base_type::difference_type difference_type;
218 
219  typedef typename base_type::iterator iterator;
220  typedef typename base_type::const_iterator const_iterator;
221  typedef typename base_type::iterator local_iterator;
222  typedef typename base_type::const_iterator const_local_iterator;
223 
224  // Construction/destruction/copying
225  explicit concurrent_unordered_multiset(size_type n_of_buckets = base_type::initial_bucket_number,
226  const hasher& a_hasher = hasher(), const key_equal& a_keyeq = key_equal(),
227  const allocator_type& a = allocator_type())
228  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
229  {}
230 
232  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
233  {}
234 
235  concurrent_unordered_multiset(size_type n_of_buckets, const hasher& a_hasher,
236  const allocator_type& a)
237  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
238  {}
239 
241  {}
242 
243  template <typename Iterator>
244  concurrent_unordered_multiset(Iterator first, Iterator last, size_type n_of_buckets = base_type::initial_bucket_number,
245  const hasher& a_hasher = hasher(), const key_equal& a_keyeq = key_equal(),
246  const allocator_type& a = allocator_type())
247  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
248  {
249  insert(first, last);
250  }
251 
252  template <typename Iterator>
253  concurrent_unordered_multiset(Iterator first, Iterator last, size_type n_of_buckets, const allocator_type& a)
254  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
255  {
256  insert(first, last);
257  }
258 
259  template <typename Iterator>
260  concurrent_unordered_multiset(Iterator first, Iterator last, size_type n_of_buckets, const hasher& a_hasher,
261  const allocator_type& a)
262  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
263  {
264  insert(first, last);
265  }
266 
267 #if __TBB_INITIALIZER_LISTS_PRESENT
268  concurrent_unordered_multiset(std::initializer_list<value_type> il, size_type n_of_buckets = base_type::initial_bucket_number,
270  const hasher& a_hasher = hasher(), const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
271  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
272  {
273  insert(il.begin(),il.end());
274  }
275 
276  concurrent_unordered_multiset(std::initializer_list<value_type> il, size_type n_of_buckets, const allocator_type& a)
277  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
278  {
279  insert(il.begin(), il.end());
280  }
281 
282  concurrent_unordered_multiset(std::initializer_list<value_type> il, size_type n_of_buckets, const hasher& a_hasher,
283  const allocator_type& a)
284  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
285  {
286  insert(il.begin(), il.end());
287  }
288 
289 #endif //# __TBB_INITIALIZER_LISTS_PRESENT
290 
291 #if __TBB_CPP11_RVALUE_REF_PRESENT
292 #if !__TBB_IMPLICIT_MOVE_PRESENT
294  : base_type(table)
295  {}
296 
298  {
299  return static_cast<concurrent_unordered_multiset&>(base_type::operator=(table));
300  }
301 
303  : base_type(std::move(table))
304  {}
305 
307  {
308  return static_cast<concurrent_unordered_multiset&>(base_type::operator=(std::move(table)));
309  }
310 #endif
311 
313  : base_type(std::move(table), a)
314  {
315  }
316 #endif //__TBB_CPP11_RVALUE_REF_PRESENT
317 
319  : base_type(table, a)
320  {}
321 };
322 } // namespace interface5
323 
324 using interface5::concurrent_unordered_set;
325 using interface5::concurrent_unordered_multiset;
326 
327 } // namespace tbb
328 
329 #endif// __TBB_concurrent_unordered_set_H
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_multiset(const concurrent_unordered_multiset &table, const Allocator &a)
concurrent_unordered_set(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)
auto last(Container &c) -> decltype(begin(c))
concurrent_unordered_multiset(std::initializer_list< value_type > il, size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
internal::hash_compare< Key, Hasher, Key_equality > hash_compare
concurrent_unordered_set(concurrent_unordered_set &&table, const Allocator &a)
__TBB_IMPLICIT_MOVE_PRESENT
concurrent_unordered_multiset(size_type n_of_buckets, const allocator_type &a)
concurrent_unordered_set(const concurrent_unordered_set &table, const Allocator &a)
auto first(Container &c) -> decltype(begin(c))
Class for determining type of std::allocator<T>::value_type.
Definition: tbb_stddef.h:454
internal::hash_compare< Key, Hasher, Key_equality > hash_compare
internal::concurrent_unordered_base< traits_type > base_type
concurrent_unordered_set(std::initializer_list< value_type > il, size_type n_of_buckets, const allocator_type &a)
concurrent_unordered_multiset(concurrent_unordered_multiset &&table, const Allocator &a)
__TBB_IMPLICIT_MOVE_PRESENT
concurrent_unordered_multiset(Iterator first, Iterator last, size_type n_of_buckets, const allocator_type &a)
internal::concurrent_unordered_base< traits_type > base_type
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:309
concurrent_unordered_set_traits< Key, hash_compare, Allocator, false > traits_type
concurrent_unordered_multiset(Iterator first, Iterator last, size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
The graph class.
concurrent_unordered_set(size_type n_of_buckets, const allocator_type &a)
concurrent_unordered_multiset(std::initializer_list< value_type > il, size_type n_of_buckets, const allocator_type &a)
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_multiset(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=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(std::initializer_list< value_type > il, size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
concurrent_unordered_set(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=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(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(Iterator first, Iterator last, size_type n_of_buckets, const allocator_type &a)
Allocator::template rebind< value_type >::other allocator_type
concurrent_unordered_set_traits< Key, hash_compare, Allocator, true > traits_type

Copyright © 2005-2018 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.