BRE12
concurrent_unordered_set.h
1 /*
2  Copyright 2005-2016 Intel Corporation. All Rights Reserved.
3 
4  This file is part of Threading Building Blocks. Threading Building Blocks is free software;
5  you can redistribute it and/or modify it under the terms of the GNU General Public License
6  version 2 as published by the Free Software Foundation. Threading Building Blocks is
7  distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
8  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9  See the GNU General Public License for more details. You should have received a copy of
10  the GNU General Public License along with Threading Building Blocks; if not, write to the
11  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12 
13  As a special exception, you may use this file as part of a free software library without
14  restriction. Specifically, if other files instantiate templates or use macros or inline
15  functions from this file, or you compile this file and link it with other files to produce
16  an executable, this file does not by itself cause the resulting executable to be covered
17  by the GNU General Public License. This exception does not however invalidate any other
18  reasons why the executable file might be covered by the GNU General Public License.
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 
27 #include "internal/_concurrent_unordered_impl.h"
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 
45  concurrent_unordered_set_traits() : my_hash_compare() {}
46  concurrent_unordered_set_traits(const hash_compare& hc) : my_hash_compare(hc) {}
47 
48  typedef hash_compare value_compare;
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
62  typedef internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key, hash_compare, Allocator, false> > 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 
100  concurrent_unordered_set(const Allocator& a) : base_type(base_type::initial_bucket_number, key_compare(), a)
101  {
102  }
103 
104  template <typename Iterator>
105  concurrent_unordered_set(Iterator first, Iterator last, size_type n_of_buckets = base_type::initial_bucket_number, const hasher& a_hasher = hasher(),
106  const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
107  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
108  {
109  insert(first, last);
110  }
111 
112 #if __TBB_INITIALIZER_LISTS_PRESENT
113  concurrent_unordered_set(std::initializer_list<value_type> il, size_type n_of_buckets = base_type::initial_bucket_number, const hasher& a_hasher = hasher(),
115  const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
116  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
117  {
118  this->insert(il.begin(),il.end());
119  }
120 #endif //# __TBB_INITIALIZER_LISTS_PRESENT
121 
122 #if __TBB_CPP11_IMPLICIT_MOVE_MEMBERS_GENERATION_BROKEN
124  : base_type(table)
125  {
126  }
127 
128  concurrent_unordered_set& operator=(const concurrent_unordered_set& table)
129  {
130  return static_cast<concurrent_unordered_set&>(base_type::operator=(table));
131  }
132 
133  concurrent_unordered_set(concurrent_unordered_set&& table)
134  : base_type(std::move(table))
135  {
136  }
137 
138  concurrent_unordered_set& operator=(concurrent_unordered_set&& table)
139  {
140  return static_cast<concurrent_unordered_set&>(base_type::operator=(std::move(table)));
141  }
142 #endif //__TBB_CPP11_IMPLICIT_MOVE_MEMBERS_GENERATION_BROKEN
143 
144  concurrent_unordered_set(const concurrent_unordered_set& table, const Allocator& a)
145  : base_type(table, a)
146  {
147  }
148 
149 #if __TBB_CPP11_RVALUE_REF_PRESENT
150  concurrent_unordered_set(concurrent_unordered_set&& table, const Allocator& a)
151  : base_type(std::move(table), a)
152  {
153  }
154 #endif //__TBB_CPP11_RVALUE_REF_PRESENT
155 
156 };
157 
158 template <typename Key, typename Hasher = tbb::tbb_hash<Key>, typename Key_equality = std::equal_to<Key>,
159  typename Allocator = tbb::tbb_allocator<Key> >
161  public internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key,
162  internal::hash_compare<Key, Hasher, Key_equality>, Allocator, true> >
163 {
164  // Base type definitions
167  typedef internal::concurrent_unordered_base< traits_type > base_type;
168 #if __TBB_EXTRA_DEBUG
169 public:
170 #endif
171  using traits_type::allow_multimapping;
172 public:
173  using base_type::insert;
174 
175  // Type definitions
176  typedef Key key_type;
177  typedef typename base_type::value_type value_type;
178  typedef Key mapped_type;
179  typedef Hasher hasher;
180  typedef Key_equality key_equal;
181  typedef hash_compare key_compare;
182 
183  typedef typename base_type::allocator_type allocator_type;
184  typedef typename base_type::pointer pointer;
185  typedef typename base_type::const_pointer const_pointer;
186  typedef typename base_type::reference reference;
187  typedef typename base_type::const_reference const_reference;
188 
189  typedef typename base_type::size_type size_type;
190  typedef typename base_type::difference_type difference_type;
191 
192  typedef typename base_type::iterator iterator;
193  typedef typename base_type::const_iterator const_iterator;
194  typedef typename base_type::iterator local_iterator;
195  typedef typename base_type::const_iterator const_local_iterator;
196 
197  // Construction/destruction/copying
198  explicit concurrent_unordered_multiset(size_type n_of_buckets = base_type::initial_bucket_number,
199  const hasher& _Hasher = hasher(), const key_equal& _Key_equality = key_equal(),
200  const allocator_type& a = allocator_type())
201  : base_type(n_of_buckets, key_compare(_Hasher, _Key_equality), a)
202  {
203  }
204 
205  concurrent_unordered_multiset(const Allocator& a) : base_type(base_type::initial_bucket_number, key_compare(), a)
206  {
207  }
208 
209  template <typename Iterator>
210  concurrent_unordered_multiset(Iterator first, Iterator last, size_type n_of_buckets = base_type::initial_bucket_number,
211  const hasher& _Hasher = hasher(), const key_equal& _Key_equality = key_equal(),
212  const allocator_type& a = allocator_type())
213  : base_type(n_of_buckets, key_compare(_Hasher, _Key_equality), a)
214  {
215  insert(first, last);
216  }
217 
218 #if __TBB_INITIALIZER_LISTS_PRESENT
219  concurrent_unordered_multiset(std::initializer_list<value_type> il, size_type n_of_buckets = base_type::initial_bucket_number, const hasher& a_hasher = hasher(),
221  const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
222  : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
223  {
224  this->insert(il.begin(),il.end());
225  }
226 #endif //# __TBB_INITIALIZER_LISTS_PRESENT
227 
228 #if __TBB_CPP11_IMPLICIT_MOVE_MEMBERS_GENERATION_BROKEN
230  : base_type(table)
231  {
232  }
233 
234  concurrent_unordered_multiset& operator=(const concurrent_unordered_multiset& table)
235  {
236  return static_cast<concurrent_unordered_multiset&>(base_type::operator=(table));
237  }
238 
239  concurrent_unordered_multiset(concurrent_unordered_multiset&& table)
240  : base_type(std::move(table))
241  {
242  }
243 
244  concurrent_unordered_multiset& operator=(concurrent_unordered_multiset&& table)
245  {
246  return static_cast<concurrent_unordered_multiset&>(base_type::operator=(std::move(table)));
247  }
248 #endif //__TBB_CPP11_IMPLICIT_MOVE_MEMBERS_GENERATION_BROKEN
249 
250  concurrent_unordered_multiset(const concurrent_unordered_multiset& table, const Allocator& a)
251  : base_type(table, a)
252  {
253  }
254 
255 #if __TBB_CPP11_RVALUE_REF_PRESENT
256  concurrent_unordered_multiset(concurrent_unordered_multiset&& table, const Allocator& a)
257  : base_type(std::move(table), a)
258  {
259  }
260 #endif //__TBB_CPP11_RVALUE_REF_PRESENT
261 };
262 } // namespace interface5
263 
266 
267 } // namespace tbb
268 
269 #endif// __TBB_concurrent_unordered_set_H
Definition: concurrent_unordered_set.h:160
Definition: concurrent_unordered_set.h:58
Definition: concurrent_unordered_set.h:36
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44
Definition: _tbb_hash_compare_impl.h:33