Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
concurrent_unordered_map.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_map_H
25 #define __TBB_concurrent_unordered_map_H
26 
28 
29 namespace tbb
30 {
31 
32 namespace interface5 {
33 
34 // Template class for hash map traits
35 template<typename Key, typename T, typename Hash_compare, typename Allocator, bool Allow_multimapping>
37 {
38 protected:
39  typedef std::pair<const Key, T> 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  template<class Type1, class Type2>
49  static const Key& get_key(const std::pair<Type1, Type2>& value) {
50  return (value.first);
51  }
52 
53  hash_compare my_hash_compare; // the comparator predicate for keys
54 };
55 
56 template <typename Key, typename T, typename Hasher = tbb::tbb_hash<Key>, typename Key_equality = std::equal_to<Key>,
57  typename Allocator = tbb::tbb_allocator<std::pair<const Key, T> > >
59  public internal::concurrent_unordered_base< concurrent_unordered_map_traits<Key, T,
60  internal::hash_compare<Key, Hasher, Key_equality>, Allocator, false> >
61 {
62  // Base type definitions
63  typedef internal::hash_compare<Key, Hasher, Key_equality> hash_compare;
65  typedef internal::concurrent_unordered_base< traits_type > base_type;
66 #if __TBB_EXTRA_DEBUG
67 public:
68 #endif
70 public:
71  using base_type::end;
72  using base_type::find;
73  using base_type::insert;
74 
75  // Type definitions
76  typedef Key key_type;
77  typedef typename base_type::value_type value_type;
78  typedef T mapped_type;
79  typedef Hasher hasher;
80  typedef Key_equality key_equal;
82 
83  typedef typename base_type::allocator_type allocator_type;
84  typedef typename base_type::pointer pointer;
85  typedef typename base_type::const_pointer const_pointer;
86  typedef typename base_type::reference reference;
87  typedef typename base_type::const_reference const_reference;
88 
89  typedef typename base_type::size_type size_type;
90  typedef typename base_type::difference_type difference_type;
91 
92  typedef typename base_type::iterator iterator;
93  typedef typename base_type::const_iterator const_iterator;
94  typedef typename base_type::iterator local_iterator;
95  typedef typename base_type::const_iterator const_local_iterator;
96 
97  // Construction/destruction/copying
98  explicit concurrent_unordered_map(size_type n_of_buckets = base_type::initial_bucket_number,
99  const hasher& a_hasher = hasher(), const key_equal& a_keyeq = key_equal(),
100  const allocator_type& a = allocator_type())
101  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
102  {}
103 
105  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
106  {}
107 
108  concurrent_unordered_map(size_type n_of_buckets, const hasher& a_hasher, const allocator_type& a)
109  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
110  {}
111 
113  {}
114 
115  template <typename Iterator>
116  concurrent_unordered_map(Iterator first, Iterator last, size_type n_of_buckets = base_type::initial_bucket_number,
117  const hasher& a_hasher = hasher(), const key_equal& a_keyeq = key_equal(),
118  const allocator_type& a = allocator_type())
119  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
120  {
121  insert(first, last);
122  }
123 
124  template <typename Iterator>
125  concurrent_unordered_map(Iterator first, Iterator last, size_type n_of_buckets, const allocator_type& a)
126  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
127  {
128  insert(first, last);
129  }
130 
131  template <typename Iterator>
132  concurrent_unordered_map(Iterator first, Iterator last, size_type n_of_buckets, const hasher& a_hasher,
133  const allocator_type& a)
134  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
135  {
136  insert(first, last);
137  }
138 
139 #if __TBB_INITIALIZER_LISTS_PRESENT
140  concurrent_unordered_map(std::initializer_list<value_type> il, size_type n_of_buckets = base_type::initial_bucket_number,
142  const hasher& a_hasher = hasher(), const key_equal& a_keyeq = key_equal(),
143  const allocator_type& a = allocator_type())
144  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
145  {
146  insert(il.begin(),il.end());
147  }
148 
149  concurrent_unordered_map(std::initializer_list<value_type> il, size_type n_of_buckets, const allocator_type& a)
150  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
151  {
152  insert(il.begin(), il.end());
153  }
154 
155  concurrent_unordered_map(std::initializer_list<value_type> il, size_type n_of_buckets, const hasher& a_hasher,
156  const allocator_type& a)
157  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
158  {
159  insert(il.begin(), il.end());
160  }
161 
162 #endif //# __TBB_INITIALIZER_LISTS_PRESENT
163 
164 #if __TBB_CPP11_RVALUE_REF_PRESENT
165 #if !__TBB_IMPLICIT_MOVE_PRESENT
167  : base_type(table)
168  {}
169 
171  {
172  return static_cast<concurrent_unordered_map&>(base_type::operator=(table));
173  }
174 
176  : base_type(std::move(table))
177  {}
178 
180  {
181  return static_cast<concurrent_unordered_map&>(base_type::operator=(std::move(table)));
182  }
183 #endif
184 
185  concurrent_unordered_map(concurrent_unordered_map&& table, const Allocator& a) : base_type(std::move(table), a)
186  {}
187 #endif //__TBB_CPP11_RVALUE_REF_PRESENT
188 
189  concurrent_unordered_map(const concurrent_unordered_map& table, const Allocator& a)
190  : base_type(table, a)
191  {}
192 
193  // Observers
195  {
196  iterator where = find(key);
197 
198  if (where == end())
199  {
200  where = insert(std::pair<key_type, mapped_type>(key, mapped_type())).first;
201  }
202 
203  return ((*where).second);
204  }
205 
207  {
208  iterator where = find(key);
209 
210  if (where == end())
211  {
213  }
214 
215  return ((*where).second);
216  }
217 
218  const mapped_type& at(const key_type& key) const
219  {
220  const_iterator where = find(key);
221 
222  if (where == end())
223  {
225  }
226 
227  return ((*where).second);
228  }
229 };
230 
231 template < typename Key, typename T, typename Hasher = tbb::tbb_hash<Key>, typename Key_equality = std::equal_to<Key>,
232  typename Allocator = tbb::tbb_allocator<std::pair<const Key, T> > >
234  public internal::concurrent_unordered_base< concurrent_unordered_map_traits< Key, T,
235  internal::hash_compare<Key, Hasher, Key_equality>, Allocator, true> >
236 {
237  // Base type definitions
238  typedef internal::hash_compare<Key, Hasher, Key_equality> hash_compare;
240  typedef internal::concurrent_unordered_base<traits_type> base_type;
241 #if __TBB_EXTRA_DEBUG
242 public:
243 #endif
245 public:
246  using base_type::insert;
247 
248  // Type definitions
249  typedef Key key_type;
250  typedef typename base_type::value_type value_type;
251  typedef T mapped_type;
252  typedef Hasher hasher;
253  typedef Key_equality key_equal;
255 
256  typedef typename base_type::allocator_type allocator_type;
257  typedef typename base_type::pointer pointer;
258  typedef typename base_type::const_pointer const_pointer;
259  typedef typename base_type::reference reference;
260  typedef typename base_type::const_reference const_reference;
261 
262  typedef typename base_type::size_type size_type;
263  typedef typename base_type::difference_type difference_type;
264 
265  typedef typename base_type::iterator iterator;
266  typedef typename base_type::const_iterator const_iterator;
267  typedef typename base_type::iterator local_iterator;
268  typedef typename base_type::const_iterator const_local_iterator;
269 
270  // Construction/destruction/copying
271  explicit concurrent_unordered_multimap(size_type n_of_buckets = base_type::initial_bucket_number,
272  const hasher& a_hasher = hasher(), const key_equal& a_keyeq = key_equal(),
273  const allocator_type& a = allocator_type())
274  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
275  {}
276 
278  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
279  {}
280 
281  concurrent_unordered_multimap(size_type n_of_buckets, const hasher& a_hasher, const allocator_type& a)
282  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
283  {}
284 
286  {}
287 
288  template <typename Iterator>
289  concurrent_unordered_multimap(Iterator first, Iterator last, size_type n_of_buckets = base_type::initial_bucket_number,
290  const hasher& a_hasher = hasher(), const key_equal& a_keyeq = key_equal(),
291  const allocator_type& a = allocator_type())
292  : base_type(n_of_buckets,key_compare(a_hasher,a_keyeq), a)
293  {
294  insert(first, last);
295  }
296 
297  template <typename Iterator>
298  concurrent_unordered_multimap(Iterator first, Iterator last, size_type n_of_buckets, const allocator_type& a)
299  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
300  {
301  insert(first, last);
302  }
303 
304  template <typename Iterator>
305  concurrent_unordered_multimap(Iterator first, Iterator last, size_type n_of_buckets, const hasher& a_hasher,
306  const allocator_type& a)
307  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
308  {
309  insert(first, last);
310  }
311 
312 #if __TBB_INITIALIZER_LISTS_PRESENT
313  concurrent_unordered_multimap(std::initializer_list<value_type> il, size_type n_of_buckets = base_type::initial_bucket_number,
315  const hasher& a_hasher = hasher(), const key_equal& a_keyeq = key_equal(),
316  const allocator_type& a = allocator_type())
317  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
318  {
319  insert(il.begin(),il.end());
320  }
321 
322  concurrent_unordered_multimap(std::initializer_list<value_type> il, size_type n_of_buckets, const allocator_type& a)
323  : base_type(n_of_buckets, key_compare(hasher(), key_equal()), a)
324  {
325  insert(il.begin(), il.end());
326  }
327 
328  concurrent_unordered_multimap(std::initializer_list<value_type> il, size_type n_of_buckets, const hasher& a_hasher,
329  const allocator_type& a)
330  : base_type(n_of_buckets, key_compare(a_hasher, key_equal()), a)
331  {
332  insert(il.begin(), il.end());
333  }
334 
335 #endif //# __TBB_INITIALIZER_LISTS_PRESENT
336 
337 #if __TBB_CPP11_RVALUE_REF_PRESENT
338 #if !__TBB_IMPLICIT_MOVE_PRESENT
340  : base_type(table)
341  {}
342 
344  {
345  return static_cast<concurrent_unordered_multimap&>(base_type::operator=(table));
346  }
347 
349  : base_type(std::move(table))
350  {}
351 
353  {
354  return static_cast<concurrent_unordered_multimap&>(base_type::operator=(std::move(table)));
355  }
356 #endif
357 
358  concurrent_unordered_multimap(concurrent_unordered_multimap&& table, const Allocator& a) : base_type(std::move(table), a)
359  {}
360 #endif //__TBB_CPP11_RVALUE_REF_PRESENT
361 
363  : base_type(table, a)
364  {}
365 };
366 } // namespace interface5
367 
368 using interface5::concurrent_unordered_map;
369 using interface5::concurrent_unordered_multimap;
370 
371 } // namespace tbb
372 
373 #endif// __TBB_concurrent_unordered_map_H
concurrent_unordered_multimap(concurrent_unordered_multimap &&table, const Allocator &a)
__TBB_IMPLICIT_MOVE_PRESENT
concurrent_unordered_multimap(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())
auto last(Container &c) -> decltype(begin(c))
concurrent_unordered_map(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_map(size_type n_of_buckets, const allocator_type &a)
auto first(Container &c) -> decltype(begin(c))
Class for determining type of std::allocator<T>::value_type.
Definition: tbb_stddef.h:454
concurrent_unordered_multimap(std::initializer_list< value_type > il, size_type n_of_buckets, const allocator_type &a)
internal::hash_compare< Key, Hasher, Key_equality > hash_compare
Allocator::template rebind< value_type >::other allocator_type
mapped_type & operator[](const key_type &key)
concurrent_unordered_map(size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
concurrent_unordered_multimap(const concurrent_unordered_multimap &table, const Allocator &a)
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:309
internal::hash_compare< Key, Hasher, Key_equality > hash_compare
static const Key & get_key(const std::pair< Type1, Type2 > &value)
concurrent_unordered_map_traits< Key, T, hash_compare, Allocator, true > traits_type
concurrent_unordered_multimap(Iterator first, Iterator last, size_type n_of_buckets, const allocator_type &a)
concurrent_unordered_map(std::initializer_list< value_type > il, size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
concurrent_unordered_map(std::initializer_list< value_type > il, size_type n_of_buckets, const allocator_type &a)
concurrent_unordered_map(Iterator first, Iterator last, size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
concurrent_unordered_map(const concurrent_unordered_map &table, const Allocator &a)
The graph class.
concurrent_unordered_map_traits< Key, T, hash_compare, Allocator, false > traits_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 ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle * key
concurrent_unordered_multimap(size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
concurrent_unordered_map(concurrent_unordered_map &&table, const Allocator &a)
__TBB_IMPLICIT_MOVE_PRESENT
concurrent_unordered_map(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())
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
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 end
internal::concurrent_unordered_base< traits_type > base_type
concurrent_unordered_multimap(Iterator first, Iterator last, size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
internal::concurrent_unordered_base< traits_type > base_type
concurrent_unordered_multimap(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_multimap(std::initializer_list< value_type > il, size_type n_of_buckets, const hasher &a_hasher, const allocator_type &a)
concurrent_unordered_multimap(size_type n_of_buckets, const allocator_type &a)
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()
concurrent_unordered_map(Iterator first, Iterator last, size_type n_of_buckets, const allocator_type &a)
const mapped_type & at(const key_type &key) const

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.