Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===------------------------- hash_set ------------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_HASH_SET |
| 12 | #define _LIBCPP_HASH_SET |
| 13 | |
| 14 | /* |
| 15 | |
| 16 | hash_set synopsis |
| 17 | |
| 18 | namespace __gnu_cxx |
| 19 | { |
| 20 | |
| 21 | template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, |
| 22 | class Alloc = allocator<Value>> |
| 23 | class hash_set |
| 24 | { |
| 25 | public: |
| 26 | // types |
| 27 | typedef Value key_type; |
| 28 | typedef key_type value_type; |
| 29 | typedef Hash hasher; |
| 30 | typedef Pred key_equal; |
| 31 | typedef Alloc allocator_type; |
| 32 | typedef value_type& reference; |
| 33 | typedef const value_type& const_reference; |
| 34 | typedef typename allocator_traits<allocator_type>::pointer pointer; |
| 35 | typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; |
| 36 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 37 | typedef typename allocator_traits<allocator_type>::difference_type difference_type; |
| 38 | |
| 39 | typedef /unspecified/ iterator; |
| 40 | typedef /unspecified/ const_iterator; |
| 41 | |
| 42 | explicit hash_set(size_type n = 193, const hasher& hf = hasher(), |
| 43 | const key_equal& eql = key_equal(), |
| 44 | const allocator_type& a = allocator_type()); |
| 45 | template <class InputIterator> |
| 46 | hash_set(InputIterator f, InputIterator l, |
| 47 | size_type n = 193, const hasher& hf = hasher(), |
| 48 | const key_equal& eql = key_equal(), |
| 49 | const allocator_type& a = allocator_type()); |
| 50 | hash_set(const hash_set&); |
| 51 | ~hash_set(); |
| 52 | hash_set& operator=(const hash_set&); |
| 53 | |
| 54 | allocator_type get_allocator() const; |
| 55 | |
| 56 | bool empty() const; |
| 57 | size_type size() const; |
| 58 | size_type max_size() const; |
| 59 | |
| 60 | iterator begin(); |
| 61 | iterator end(); |
| 62 | const_iterator begin() const; |
| 63 | const_iterator end() const; |
| 64 | |
| 65 | pair<iterator, bool> insert(const value_type& obj); |
| 66 | template <class InputIterator> |
| 67 | void insert(InputIterator first, InputIterator last); |
| 68 | |
| 69 | void erase(const_iterator position); |
| 70 | size_type erase(const key_type& k); |
| 71 | void erase(const_iterator first, const_iterator last); |
| 72 | void clear(); |
| 73 | |
| 74 | void swap(hash_set&); |
| 75 | |
| 76 | hasher hash_funct() const; |
| 77 | key_equal key_eq() const; |
| 78 | |
| 79 | iterator find(const key_type& k); |
| 80 | const_iterator find(const key_type& k) const; |
| 81 | size_type count(const key_type& k) const; |
| 82 | pair<iterator, iterator> equal_range(const key_type& k); |
| 83 | pair<const_iterator, const_iterator> equal_range(const key_type& k) const; |
| 84 | |
| 85 | size_type bucket_count() const; |
| 86 | size_type max_bucket_count() const; |
| 87 | |
| 88 | size_type elems_in_bucket(size_type n) const; |
| 89 | |
| 90 | void resize(size_type n); |
| 91 | }; |
| 92 | |
| 93 | template <class Value, class Hash, class Pred, class Alloc> |
| 94 | void swap(hash_set<Value, Hash, Pred, Alloc>& x, |
| 95 | hash_set<Value, Hash, Pred, Alloc>& y); |
| 96 | |
| 97 | template <class Value, class Hash, class Pred, class Alloc> |
| 98 | bool |
| 99 | operator==(const hash_set<Value, Hash, Pred, Alloc>& x, |
| 100 | const hash_set<Value, Hash, Pred, Alloc>& y); |
| 101 | |
| 102 | template <class Value, class Hash, class Pred, class Alloc> |
| 103 | bool |
| 104 | operator!=(const hash_set<Value, Hash, Pred, Alloc>& x, |
| 105 | const hash_set<Value, Hash, Pred, Alloc>& y); |
| 106 | |
| 107 | template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, |
| 108 | class Alloc = allocator<Value>> |
| 109 | class hash_multiset |
| 110 | { |
| 111 | public: |
| 112 | // types |
| 113 | typedef Value key_type; |
| 114 | typedef key_type value_type; |
| 115 | typedef Hash hasher; |
| 116 | typedef Pred key_equal; |
| 117 | typedef Alloc allocator_type; |
| 118 | typedef value_type& reference; |
| 119 | typedef const value_type& const_reference; |
| 120 | typedef typename allocator_traits<allocator_type>::pointer pointer; |
| 121 | typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; |
| 122 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 123 | typedef typename allocator_traits<allocator_type>::difference_type difference_type; |
| 124 | |
| 125 | typedef /unspecified/ iterator; |
| 126 | typedef /unspecified/ const_iterator; |
| 127 | |
| 128 | explicit hash_multiset(size_type n = 193, const hasher& hf = hasher(), |
| 129 | const key_equal& eql = key_equal(), |
| 130 | const allocator_type& a = allocator_type()); |
| 131 | template <class InputIterator> |
| 132 | hash_multiset(InputIterator f, InputIterator l, |
| 133 | size_type n = 193, const hasher& hf = hasher(), |
| 134 | const key_equal& eql = key_equal(), |
| 135 | const allocator_type& a = allocator_type()); |
| 136 | hash_multiset(const hash_multiset&); |
| 137 | ~hash_multiset(); |
| 138 | hash_multiset& operator=(const hash_multiset&); |
| 139 | |
| 140 | allocator_type get_allocator() const; |
| 141 | |
| 142 | bool empty() const; |
| 143 | size_type size() const; |
| 144 | size_type max_size() const; |
| 145 | |
| 146 | iterator begin(); |
| 147 | iterator end(); |
| 148 | const_iterator begin() const; |
| 149 | const_iterator end() const; |
| 150 | |
| 151 | iterator insert(const value_type& obj); |
| 152 | template <class InputIterator> |
| 153 | void insert(InputIterator first, InputIterator last); |
| 154 | |
| 155 | void erase(const_iterator position); |
| 156 | size_type erase(const key_type& k); |
| 157 | void erase(const_iterator first, const_iterator last); |
| 158 | void clear(); |
| 159 | |
| 160 | void swap(hash_multiset&); |
| 161 | |
| 162 | hasher hash_funct() const; |
| 163 | key_equal key_eq() const; |
| 164 | |
| 165 | iterator find(const key_type& k); |
| 166 | const_iterator find(const key_type& k) const; |
| 167 | size_type count(const key_type& k) const; |
| 168 | pair<iterator, iterator> equal_range(const key_type& k); |
| 169 | pair<const_iterator, const_iterator> equal_range(const key_type& k) const; |
| 170 | |
| 171 | size_type bucket_count() const; |
| 172 | size_type max_bucket_count() const; |
| 173 | |
| 174 | size_type elems_in_bucket(size_type n) const; |
| 175 | |
| 176 | void resize(size_type n); |
| 177 | }; |
| 178 | |
| 179 | template <class Value, class Hash, class Pred, class Alloc> |
| 180 | void swap(hash_multiset<Value, Hash, Pred, Alloc>& x, |
| 181 | hash_multiset<Value, Hash, Pred, Alloc>& y); |
| 182 | |
| 183 | template <class Value, class Hash, class Pred, class Alloc> |
| 184 | bool |
| 185 | operator==(const hash_multiset<Value, Hash, Pred, Alloc>& x, |
| 186 | const hash_multiset<Value, Hash, Pred, Alloc>& y); |
| 187 | |
| 188 | template <class Value, class Hash, class Pred, class Alloc> |
| 189 | bool |
| 190 | operator!=(const hash_multiset<Value, Hash, Pred, Alloc>& x, |
| 191 | const hash_multiset<Value, Hash, Pred, Alloc>& y); |
| 192 | } // __gnu_cxx |
| 193 | |
| 194 | */ |
| 195 | |
| 196 | #include <__config> |
| 197 | #include <__hash_table> |
| 198 | #include <functional> |
| 199 | |
| 200 | #warning Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set> |
| 201 | |
| 202 | namespace __gnu_cxx { |
| 203 | |
| 204 | using namespace std; |
| 205 | |
| 206 | template <class _Value, class _Hash = std::hash<_Value>, class _Pred = equal_to<_Value>, |
| 207 | class _Alloc = allocator<_Value> > |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 208 | class _LIBCPP_VISIBLE hash_set |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 209 | { |
| 210 | public: |
| 211 | // types |
| 212 | typedef _Value key_type; |
| 213 | typedef key_type value_type; |
| 214 | typedef _Hash hasher; |
| 215 | typedef _Pred key_equal; |
| 216 | typedef _Alloc allocator_type; |
| 217 | typedef value_type& reference; |
| 218 | typedef const value_type& const_reference; |
| 219 | |
| 220 | private: |
| 221 | typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; |
| 222 | |
| 223 | __table __table_; |
| 224 | |
| 225 | public: |
| 226 | typedef typename __table::pointer pointer; |
| 227 | typedef typename __table::const_pointer const_pointer; |
| 228 | typedef typename __table::size_type size_type; |
| 229 | typedef typename __table::difference_type difference_type; |
| 230 | |
| 231 | typedef typename __table::const_iterator iterator; |
| 232 | typedef typename __table::const_iterator const_iterator; |
| 233 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 234 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 235 | hash_set() {__table_.rehash(193);} |
| 236 | explicit hash_set(size_type __n, const hasher& __hf = hasher(), |
| 237 | const key_equal& __eql = key_equal()); |
| 238 | hash_set(size_type __n, const hasher& __hf, const key_equal& __eql, |
| 239 | const allocator_type& __a); |
| 240 | template <class _InputIterator> |
| 241 | hash_set(_InputIterator __first, _InputIterator __last); |
| 242 | template <class _InputIterator> |
| 243 | hash_set(_InputIterator __first, _InputIterator __last, |
| 244 | size_type __n, const hasher& __hf = hasher(), |
| 245 | const key_equal& __eql = key_equal()); |
| 246 | template <class _InputIterator> |
| 247 | hash_set(_InputIterator __first, _InputIterator __last, |
| 248 | size_type __n, const hasher& __hf, const key_equal& __eql, |
| 249 | const allocator_type& __a); |
| 250 | hash_set(const hash_set& __u); |
| 251 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 252 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 253 | allocator_type get_allocator() const |
| 254 | {return allocator_type(__table_.__node_alloc());} |
| 255 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 256 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 257 | bool empty() const {return __table_.size() == 0;} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 258 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 259 | size_type size() const {return __table_.size();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 260 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 261 | size_type max_size() const {return __table_.max_size();} |
| 262 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 263 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 264 | iterator begin() {return __table_.begin();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 265 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 266 | iterator end() {return __table_.end();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 267 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 268 | const_iterator begin() const {return __table_.begin();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 269 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | const_iterator end() const {return __table_.end();} |
| 271 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 272 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 273 | pair<iterator, bool> insert(const value_type& __x) |
| 274 | {return __table_.__insert_unique(__x);} |
| 275 | template <class _InputIterator> |
| 276 | void insert(_InputIterator __first, _InputIterator __last); |
| 277 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 278 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 279 | void erase(const_iterator __p) {__table_.erase(__p);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 280 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 281 | size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 282 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 283 | void erase(const_iterator __first, const_iterator __last) |
| 284 | {__table_.erase(__first, __last);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 285 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 286 | void clear() {__table_.clear();} |
| 287 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 288 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 289 | void swap(hash_set& __u) {__table_.swap(__u.__table_);} |
| 290 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 291 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 292 | hasher hash_funct() const {return __table_.hash_function();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 293 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 294 | key_equal key_eq() const {return __table_.key_eq();} |
| 295 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 296 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 297 | iterator find(const key_type& __k) {return __table_.find(__k);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 298 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 299 | const_iterator find(const key_type& __k) const {return __table_.find(__k);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 300 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 301 | size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 302 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 303 | pair<iterator, iterator> equal_range(const key_type& __k) |
| 304 | {return __table_.__equal_range_unique(__k);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 305 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 306 | pair<const_iterator, const_iterator> equal_range(const key_type& __k) const |
| 307 | {return __table_.__equal_range_unique(__k);} |
| 308 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 309 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 310 | size_type bucket_count() const {return __table_.bucket_count();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 311 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 312 | size_type max_bucket_count() const {return __table_.max_bucket_count();} |
| 313 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 314 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 315 | size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);} |
| 316 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 317 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 318 | void resize(size_type __n) {__table_.rehash(__n);} |
| 319 | }; |
| 320 | |
| 321 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 322 | hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n, |
| 323 | const hasher& __hf, const key_equal& __eql) |
| 324 | : __table_(__hf, __eql) |
| 325 | { |
| 326 | __table_.rehash(__n); |
| 327 | } |
| 328 | |
| 329 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 330 | hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n, |
| 331 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
| 332 | : __table_(__hf, __eql, __a) |
| 333 | { |
| 334 | __table_.rehash(__n); |
| 335 | } |
| 336 | |
| 337 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 338 | template <class _InputIterator> |
| 339 | hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( |
| 340 | _InputIterator __first, _InputIterator __last) |
| 341 | { |
| 342 | __table_.rehash(193); |
| 343 | insert(__first, __last); |
| 344 | } |
| 345 | |
| 346 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 347 | template <class _InputIterator> |
| 348 | hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( |
| 349 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 350 | const hasher& __hf, const key_equal& __eql) |
| 351 | : __table_(__hf, __eql) |
| 352 | { |
| 353 | __table_.rehash(__n); |
| 354 | insert(__first, __last); |
| 355 | } |
| 356 | |
| 357 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 358 | template <class _InputIterator> |
| 359 | hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( |
| 360 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 361 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
| 362 | : __table_(__hf, __eql, __a) |
| 363 | { |
| 364 | __table_.rehash(__n); |
| 365 | insert(__first, __last); |
| 366 | } |
| 367 | |
| 368 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 369 | hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( |
| 370 | const hash_set& __u) |
| 371 | : __table_(__u.__table_) |
| 372 | { |
| 373 | __table_.rehash(__u.bucket_count()); |
| 374 | insert(__u.begin(), __u.end()); |
| 375 | } |
| 376 | |
| 377 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 378 | template <class _InputIterator> |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 379 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 380 | void |
| 381 | hash_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, |
| 382 | _InputIterator __last) |
| 383 | { |
| 384 | for (; __first != __last; ++__first) |
| 385 | __table_.__insert_unique(*__first); |
| 386 | } |
| 387 | |
| 388 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 389 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 390 | void |
| 391 | swap(hash_set<_Value, _Hash, _Pred, _Alloc>& __x, |
| 392 | hash_set<_Value, _Hash, _Pred, _Alloc>& __y) |
| 393 | { |
| 394 | __x.swap(__y); |
| 395 | } |
| 396 | |
| 397 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 398 | bool |
| 399 | operator==(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x, |
| 400 | const hash_set<_Value, _Hash, _Pred, _Alloc>& __y) |
| 401 | { |
| 402 | if (__x.size() != __y.size()) |
| 403 | return false; |
| 404 | typedef typename hash_set<_Value, _Hash, _Pred, _Alloc>::const_iterator |
| 405 | const_iterator; |
| 406 | for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); |
| 407 | __i != __ex; ++__i) |
| 408 | { |
| 409 | const_iterator __j = __y.find(*__i); |
| 410 | if (__j == __ey || !(*__i == *__j)) |
| 411 | return false; |
| 412 | } |
| 413 | return true; |
| 414 | } |
| 415 | |
| 416 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 417 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 418 | bool |
| 419 | operator!=(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x, |
| 420 | const hash_set<_Value, _Hash, _Pred, _Alloc>& __y) |
| 421 | { |
| 422 | return !(__x == __y); |
| 423 | } |
| 424 | |
| 425 | template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, |
| 426 | class _Alloc = allocator<_Value> > |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 427 | class _LIBCPP_VISIBLE hash_multiset |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 428 | { |
| 429 | public: |
| 430 | // types |
| 431 | typedef _Value key_type; |
| 432 | typedef key_type value_type; |
| 433 | typedef _Hash hasher; |
| 434 | typedef _Pred key_equal; |
| 435 | typedef _Alloc allocator_type; |
| 436 | typedef value_type& reference; |
| 437 | typedef const value_type& const_reference; |
| 438 | |
| 439 | private: |
| 440 | typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; |
| 441 | |
| 442 | __table __table_; |
| 443 | |
| 444 | public: |
| 445 | typedef typename __table::pointer pointer; |
| 446 | typedef typename __table::const_pointer const_pointer; |
| 447 | typedef typename __table::size_type size_type; |
| 448 | typedef typename __table::difference_type difference_type; |
| 449 | |
| 450 | typedef typename __table::const_iterator iterator; |
| 451 | typedef typename __table::const_iterator const_iterator; |
| 452 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 453 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 454 | hash_multiset() {__table_.rehash(193);} |
| 455 | explicit hash_multiset(size_type __n, const hasher& __hf = hasher(), |
| 456 | const key_equal& __eql = key_equal()); |
| 457 | hash_multiset(size_type __n, const hasher& __hf, |
| 458 | const key_equal& __eql, const allocator_type& __a); |
| 459 | template <class _InputIterator> |
| 460 | hash_multiset(_InputIterator __first, _InputIterator __last); |
| 461 | template <class _InputIterator> |
| 462 | hash_multiset(_InputIterator __first, _InputIterator __last, |
| 463 | size_type __n, const hasher& __hf = hasher(), |
| 464 | const key_equal& __eql = key_equal()); |
| 465 | template <class _InputIterator> |
| 466 | hash_multiset(_InputIterator __first, _InputIterator __last, |
| 467 | size_type __n , const hasher& __hf, |
| 468 | const key_equal& __eql, const allocator_type& __a); |
| 469 | hash_multiset(const hash_multiset& __u); |
| 470 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 471 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 472 | allocator_type get_allocator() const |
| 473 | {return allocator_type(__table_.__node_alloc());} |
| 474 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 475 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 476 | bool empty() const {return __table_.size() == 0;} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 477 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 478 | size_type size() const {return __table_.size();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 479 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 480 | size_type max_size() const {return __table_.max_size();} |
| 481 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 482 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 483 | iterator begin() {return __table_.begin();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 484 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 485 | iterator end() {return __table_.end();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 486 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 487 | const_iterator begin() const {return __table_.begin();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 488 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 489 | const_iterator end() const {return __table_.end();} |
| 490 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 491 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 492 | iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} |
| 493 | template <class _InputIterator> |
| 494 | void insert(_InputIterator __first, _InputIterator __last); |
| 495 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 496 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 497 | void erase(const_iterator __p) {__table_.erase(__p);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 498 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 499 | size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 500 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 501 | void erase(const_iterator __first, const_iterator __last) |
| 502 | {__table_.erase(__first, __last);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 503 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 504 | void clear() {__table_.clear();} |
| 505 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 506 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 507 | void swap(hash_multiset& __u) {__table_.swap(__u.__table_);} |
| 508 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 509 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 510 | hasher hash_funct() const {return __table_.hash_function();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 511 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 512 | key_equal key_eq() const {return __table_.key_eq();} |
| 513 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 514 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 515 | iterator find(const key_type& __k) {return __table_.find(__k);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 516 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 517 | const_iterator find(const key_type& __k) const {return __table_.find(__k);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 518 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 519 | size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 520 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 521 | pair<iterator, iterator> equal_range(const key_type& __k) |
| 522 | {return __table_.__equal_range_multi(__k);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 523 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 524 | pair<const_iterator, const_iterator> equal_range(const key_type& __k) const |
| 525 | {return __table_.__equal_range_multi(__k);} |
| 526 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 527 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 528 | size_type bucket_count() const {return __table_.bucket_count();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 529 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 530 | size_type max_bucket_count() const {return __table_.max_bucket_count();} |
| 531 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 532 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 533 | size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);} |
| 534 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 535 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 536 | void resize(size_type __n) {__table_.rehash(__n);} |
| 537 | }; |
| 538 | |
| 539 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 540 | hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( |
| 541 | size_type __n, const hasher& __hf, const key_equal& __eql) |
| 542 | : __table_(__hf, __eql) |
| 543 | { |
| 544 | __table_.rehash(__n); |
| 545 | } |
| 546 | |
| 547 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 548 | hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( |
| 549 | size_type __n, const hasher& __hf, const key_equal& __eql, |
| 550 | const allocator_type& __a) |
| 551 | : __table_(__hf, __eql, __a) |
| 552 | { |
| 553 | __table_.rehash(__n); |
| 554 | } |
| 555 | |
| 556 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 557 | template <class _InputIterator> |
| 558 | hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( |
| 559 | _InputIterator __first, _InputIterator __last) |
| 560 | { |
| 561 | __table_.rehash(193); |
| 562 | insert(__first, __last); |
| 563 | } |
| 564 | |
| 565 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 566 | template <class _InputIterator> |
| 567 | hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( |
| 568 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 569 | const hasher& __hf, const key_equal& __eql) |
| 570 | : __table_(__hf, __eql) |
| 571 | { |
| 572 | __table_.rehash(__n); |
| 573 | insert(__first, __last); |
| 574 | } |
| 575 | |
| 576 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 577 | template <class _InputIterator> |
| 578 | hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( |
| 579 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 580 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
| 581 | : __table_(__hf, __eql, __a) |
| 582 | { |
| 583 | __table_.rehash(__n); |
| 584 | insert(__first, __last); |
| 585 | } |
| 586 | |
| 587 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 588 | hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( |
| 589 | const hash_multiset& __u) |
| 590 | : __table_(__u.__table_) |
| 591 | { |
| 592 | __table_.rehash(__u.bucket_count()); |
| 593 | insert(__u.begin(), __u.end()); |
| 594 | } |
| 595 | |
| 596 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 597 | template <class _InputIterator> |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 598 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 599 | void |
| 600 | hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, |
| 601 | _InputIterator __last) |
| 602 | { |
| 603 | for (; __first != __last; ++__first) |
| 604 | __table_.__insert_multi(*__first); |
| 605 | } |
| 606 | |
| 607 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 608 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 609 | void |
| 610 | swap(hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, |
| 611 | hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) |
| 612 | { |
| 613 | __x.swap(__y); |
| 614 | } |
| 615 | |
| 616 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 617 | bool |
| 618 | operator==(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, |
| 619 | const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) |
| 620 | { |
| 621 | if (__x.size() != __y.size()) |
| 622 | return false; |
| 623 | typedef typename hash_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator |
| 624 | const_iterator; |
| 625 | typedef pair<const_iterator, const_iterator> _EqRng; |
| 626 | for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) |
| 627 | { |
| 628 | _EqRng __xeq = __x.equal_range(*__i); |
| 629 | _EqRng __yeq = __y.equal_range(*__i); |
| 630 | if (_STD::distance(__xeq.first, __xeq.second) != |
| 631 | _STD::distance(__yeq.first, __yeq.second) || |
| 632 | !_STD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) |
| 633 | return false; |
| 634 | __i = __xeq.second; |
| 635 | } |
| 636 | return true; |
| 637 | } |
| 638 | |
| 639 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 640 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 641 | bool |
| 642 | operator!=(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, |
| 643 | const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) |
| 644 | { |
| 645 | return !(__x == __y); |
| 646 | } |
| 647 | |
| 648 | } // __gnu_cxx |
| 649 | |
| 650 | #endif // _LIBCPP_HASH_SET |