00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __TBB_concurrent_unordered_set_H
00033 #define __TBB_concurrent_unordered_set_H
00034
00035 #include "internal/_concurrent_unordered_impl.h"
00036
00037 namespace tbb
00038 {
00039
00040 namespace interface5 {
00041
00042
00043 template<typename Key, typename Hash_compare, typename Allocator, bool Allow_multimapping>
00044 class concurrent_unordered_set_traits
00045 {
00046 protected:
00047 typedef Key value_type;
00048 typedef Key key_type;
00049 typedef Hash_compare hash_compare;
00050 typedef typename Allocator::template rebind<value_type>::other allocator_type;
00051 enum { allow_multimapping = Allow_multimapping };
00052
00053 concurrent_unordered_set_traits() : my_hash_compare() {}
00054 concurrent_unordered_set_traits(const hash_compare& hc) : my_hash_compare(hc) {}
00055
00056 typedef hash_compare value_compare;
00057
00058 static const Key& get_key(const value_type& value) {
00059 return value;
00060 }
00061
00062 hash_compare my_hash_compare;
00063 };
00064
00065 template <typename Key, typename Hasher = tbb::tbb_hash<Key>, typename Key_equality = std::equal_to<Key>, typename Allocator = tbb::tbb_allocator<Key> >
00066 class concurrent_unordered_set : public internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key, internal::hash_compare<Key, Hasher, Key_equality>, Allocator, false> >
00067 {
00068
00069 typedef internal::hash_compare<Key, Hasher, Key_equality> hash_compare;
00070 typedef internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key, hash_compare, Allocator, false> > base_type;
00071 typedef concurrent_unordered_set_traits<Key, internal::hash_compare<Key, Hasher, Key_equality>, Allocator, false> traits_type;
00072 using traits_type::my_hash_compare;
00073 #if __TBB_EXTRA_DEBUG
00074 public:
00075 #endif
00076 using traits_type::allow_multimapping;
00077 public:
00078 using base_type::end;
00079 using base_type::find;
00080 using base_type::insert;
00081
00082
00083 typedef Key key_type;
00084 typedef typename base_type::value_type value_type;
00085 typedef Key mapped_type;
00086 typedef Hasher hasher;
00087 typedef Key_equality key_equal;
00088 typedef hash_compare key_compare;
00089
00090 typedef typename base_type::allocator_type allocator_type;
00091 typedef typename base_type::pointer pointer;
00092 typedef typename base_type::const_pointer const_pointer;
00093 typedef typename base_type::reference reference;
00094 typedef typename base_type::const_reference const_reference;
00095
00096 typedef typename base_type::size_type size_type;
00097 typedef typename base_type::difference_type difference_type;
00098
00099 typedef typename base_type::iterator iterator;
00100 typedef typename base_type::const_iterator const_iterator;
00101 typedef typename base_type::iterator local_iterator;
00102 typedef typename base_type::const_iterator const_local_iterator;
00103
00104
00105 explicit concurrent_unordered_set(size_type n_of_buckets = 8, const hasher& a_hasher = hasher(),
00106 const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
00107 : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
00108 {
00109 }
00110
00111 concurrent_unordered_set(const Allocator& a) : base_type(8, key_compare(), a)
00112 {
00113 }
00114
00115 template <typename Iterator>
00116 concurrent_unordered_set(Iterator first, Iterator last, size_type n_of_buckets = 8, const hasher& a_hasher = hasher(),
00117 const key_equal& a_keyeq = key_equal(), const allocator_type& a = allocator_type())
00118 : base_type(n_of_buckets, key_compare(a_hasher, a_keyeq), a)
00119 {
00120 for (; first != last; ++first)
00121 base_type::insert(*first);
00122 }
00123
00124 concurrent_unordered_set(const concurrent_unordered_set& table) : base_type(table)
00125 {
00126 }
00127
00128 concurrent_unordered_set(const concurrent_unordered_set& table, const Allocator& a)
00129 : base_type(table, a)
00130 {
00131 }
00132
00133 concurrent_unordered_set& operator=(const concurrent_unordered_set& table)
00134 {
00135 base_type::operator=(table);
00136 return (*this);
00137 }
00138
00139 iterator unsafe_erase(const_iterator where)
00140 {
00141 return base_type::unsafe_erase(where);
00142 }
00143
00144 size_type unsafe_erase(const key_type& key)
00145 {
00146 return base_type::unsafe_erase(key);
00147 }
00148
00149 iterator unsafe_erase(const_iterator first, const_iterator last)
00150 {
00151 return base_type::unsafe_erase(first, last);
00152 }
00153
00154 void swap(concurrent_unordered_set& table)
00155 {
00156 base_type::swap(table);
00157 }
00158
00159
00160 hasher hash_function() const
00161 {
00162 return my_hash_compare.my_hash_object;
00163 }
00164
00165 key_equal key_eq() const
00166 {
00167 return my_hash_compare.my_key_compare_object;
00168 }
00169 };
00170
00171 template <typename Key, typename Hasher = tbb::tbb_hash<Key>, typename Key_equality = std::equal_to<Key>,
00172 typename Allocator = tbb::tbb_allocator<Key> >
00173 class concurrent_unordered_multiset :
00174 public internal::concurrent_unordered_base< concurrent_unordered_set_traits<Key,
00175 internal::hash_compare<Key, Hasher, Key_equality>, Allocator, true> >
00176 {
00177 public:
00178
00179 typedef internal::hash_compare<Key, Hasher, Key_equality> hash_compare;
00180 typedef concurrent_unordered_set_traits<Key, hash_compare, Allocator, true> traits_type;
00181 typedef internal::concurrent_unordered_base< traits_type > base_type;
00182 using traits_type::allow_multimapping;
00183 using traits_type::my_hash_compare;
00184
00185
00186 typedef Key key_type;
00187 typedef typename base_type::value_type value_type;
00188 typedef Key mapped_type;
00189 typedef Hasher hasher;
00190 typedef Key_equality key_equal;
00191 typedef hash_compare key_compare;
00192
00193 typedef typename base_type::allocator_type allocator_type;
00194 typedef typename base_type::pointer pointer;
00195 typedef typename base_type::const_pointer const_pointer;
00196 typedef typename base_type::reference reference;
00197 typedef typename base_type::const_reference const_reference;
00198
00199 typedef typename base_type::size_type size_type;
00200 typedef typename base_type::difference_type difference_type;
00201
00202 typedef typename base_type::iterator iterator;
00203 typedef typename base_type::const_iterator const_iterator;
00204 typedef typename base_type::iterator local_iterator;
00205 typedef typename base_type::const_iterator const_local_iterator;
00206
00207
00208 explicit concurrent_unordered_multiset(size_type n_of_buckets = 8,
00209 const hasher& _Hasher = hasher(), const key_equal& _Key_equality = key_equal(),
00210 const allocator_type& a = allocator_type())
00211 : base_type(n_of_buckets, key_compare(_Hasher, _Key_equality), a)
00212 {
00213 }
00214
00215 concurrent_unordered_multiset(const Allocator& a) : base_type(8, key_compare(), a)
00216 {
00217 }
00218
00219 template <typename Iterator>
00220 concurrent_unordered_multiset(Iterator first, Iterator last, size_type n_of_buckets = 8,
00221 const hasher& _Hasher = hasher(), const key_equal& _Key_equality = key_equal(),
00222 const allocator_type& a = allocator_type())
00223 : base_type(n_of_buckets, key_compare(_Hasher, _Key_equality), a)
00224 {
00225 for (; first != last; ++first)
00226 {
00227 base_type::insert(*first);
00228 }
00229 }
00230
00231 concurrent_unordered_multiset(const concurrent_unordered_multiset& table) : base_type(table)
00232 {
00233 }
00234
00235 concurrent_unordered_multiset(const concurrent_unordered_multiset& table, const Allocator& a) : base_type(table, a)
00236 {
00237 }
00238
00239 concurrent_unordered_multiset& operator=(const concurrent_unordered_multiset& table)
00240 {
00241 base_type::operator=(table);
00242 return (*this);
00243 }
00244
00245
00246 std::pair<iterator, bool> insert(const value_type& value)
00247 {
00248 return base_type::insert(value);
00249 }
00250
00251 iterator insert(const_iterator where, const value_type& value)
00252 {
00253 return base_type::insert(where, value);
00254 }
00255
00256 template<class Iterator>
00257 void insert(Iterator first, Iterator last)
00258 {
00259 base_type::insert(first, last);
00260 }
00261
00262 iterator unsafe_erase(const_iterator where)
00263 {
00264 return base_type::unsafe_erase(where);
00265 }
00266
00267 size_type unsafe_erase(const key_type& key)
00268 {
00269 return base_type::unsafe_erase(key);
00270 }
00271
00272 iterator unsafe_erase(const_iterator first, const_iterator last)
00273 {
00274 return base_type::unsafe_erase(first, last);
00275 }
00276
00277 void swap(concurrent_unordered_multiset& table)
00278 {
00279 base_type::swap(table);
00280 }
00281
00282
00283 hasher hash_function() const
00284 {
00285 return my_hash_compare.my_hash_object;
00286 }
00287
00288 key_equal key_eq() const
00289 {
00290 return my_hash_compare.my_key_compare_object;
00291 }
00292 };
00293 }
00294
00295 using interface5::concurrent_unordered_set;
00296 using interface5::concurrent_unordered_multiset;
00297
00298 }
00299
00300 #endif// __TBB_concurrent_unordered_set_H