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 | |
Howard Hinnant | 4f59803 | 2011-07-24 23:59:50 +0000 | [diff] [blame] | 200 | #if __DEPRECATED |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 201 | #warning Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set> |
Howard Hinnant | 4f59803 | 2011-07-24 23:59:50 +0000 | [diff] [blame] | 202 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 203 | |
| 204 | namespace __gnu_cxx { |
| 205 | |
| 206 | using namespace std; |
| 207 | |
| 208 | template <class _Value, class _Hash = std::hash<_Value>, class _Pred = equal_to<_Value>, |
| 209 | class _Alloc = allocator<_Value> > |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 210 | class _LIBCPP_VISIBLE hash_set |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 211 | { |
| 212 | public: |
| 213 | // types |
| 214 | typedef _Value key_type; |
| 215 | typedef key_type value_type; |
| 216 | typedef _Hash hasher; |
| 217 | typedef _Pred key_equal; |
| 218 | typedef _Alloc allocator_type; |
| 219 | typedef value_type& reference; |
| 220 | typedef const value_type& const_reference; |
| 221 | |
| 222 | private: |
| 223 | typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; |
| 224 | |
| 225 | __table __table_; |
| 226 | |
| 227 | public: |
| 228 | typedef typename __table::pointer pointer; |
| 229 | typedef typename __table::const_pointer const_pointer; |
| 230 | typedef typename __table::size_type size_type; |
| 231 | typedef typename __table::difference_type difference_type; |
| 232 | |
| 233 | typedef typename __table::const_iterator iterator; |
| 234 | typedef typename __table::const_iterator const_iterator; |
| 235 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 236 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 237 | hash_set() {__table_.rehash(193);} |
| 238 | explicit hash_set(size_type __n, const hasher& __hf = hasher(), |
| 239 | const key_equal& __eql = key_equal()); |
| 240 | hash_set(size_type __n, const hasher& __hf, const key_equal& __eql, |
| 241 | const allocator_type& __a); |
| 242 | template <class _InputIterator> |
| 243 | hash_set(_InputIterator __first, _InputIterator __last); |
| 244 | template <class _InputIterator> |
| 245 | hash_set(_InputIterator __first, _InputIterator __last, |
| 246 | size_type __n, const hasher& __hf = hasher(), |
| 247 | const key_equal& __eql = key_equal()); |
| 248 | template <class _InputIterator> |
| 249 | hash_set(_InputIterator __first, _InputIterator __last, |
| 250 | size_type __n, const hasher& __hf, const key_equal& __eql, |
| 251 | const allocator_type& __a); |
| 252 | hash_set(const hash_set& __u); |
| 253 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 254 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 255 | allocator_type get_allocator() const |
| 256 | {return allocator_type(__table_.__node_alloc());} |
| 257 | |
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 | bool empty() const {return __table_.size() == 0;} |
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 size() const {return __table_.size();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 262 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 263 | size_type max_size() const {return __table_.max_size();} |
| 264 | |
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 begin() {return __table_.begin();} |
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 | iterator end() {return __table_.end();} |
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 begin() const {return __table_.begin();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 271 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 272 | const_iterator end() const {return __table_.end();} |
| 273 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 274 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 275 | pair<iterator, bool> insert(const value_type& __x) |
| 276 | {return __table_.__insert_unique(__x);} |
Sean Hunt | e36a196 | 2011-07-29 23:31:53 +0000 | [diff] [blame^] | 277 | _LIBCPP_INLINE_VISIBILITY |
| 278 | iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 279 | template <class _InputIterator> |
| 280 | void insert(_InputIterator __first, _InputIterator __last); |
| 281 | |
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 __p) {__table_.erase(__p);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 284 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 285 | size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 286 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 287 | void erase(const_iterator __first, const_iterator __last) |
| 288 | {__table_.erase(__first, __last);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 289 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 290 | void clear() {__table_.clear();} |
| 291 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 292 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 293 | void swap(hash_set& __u) {__table_.swap(__u.__table_);} |
| 294 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 295 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 296 | hasher hash_funct() const {return __table_.hash_function();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 297 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 298 | key_equal key_eq() const {return __table_.key_eq();} |
| 299 | |
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 | iterator find(const key_type& __k) {return __table_.find(__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 | const_iterator find(const key_type& __k) const {return __table_.find(__k);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 304 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 305 | 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] | 306 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 307 | pair<iterator, iterator> equal_range(const key_type& __k) |
| 308 | {return __table_.__equal_range_unique(__k);} |
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 | pair<const_iterator, const_iterator> equal_range(const key_type& __k) const |
| 311 | {return __table_.__equal_range_unique(__k);} |
| 312 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 313 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 314 | size_type bucket_count() const {return __table_.bucket_count();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 315 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 316 | size_type max_bucket_count() const {return __table_.max_bucket_count();} |
| 317 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 318 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 319 | size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);} |
| 320 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 321 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 322 | void resize(size_type __n) {__table_.rehash(__n);} |
| 323 | }; |
| 324 | |
| 325 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 326 | hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n, |
| 327 | const hasher& __hf, const key_equal& __eql) |
| 328 | : __table_(__hf, __eql) |
| 329 | { |
| 330 | __table_.rehash(__n); |
| 331 | } |
| 332 | |
| 333 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 334 | hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set(size_type __n, |
| 335 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
| 336 | : __table_(__hf, __eql, __a) |
| 337 | { |
| 338 | __table_.rehash(__n); |
| 339 | } |
| 340 | |
| 341 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 342 | template <class _InputIterator> |
| 343 | hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( |
| 344 | _InputIterator __first, _InputIterator __last) |
| 345 | { |
| 346 | __table_.rehash(193); |
| 347 | insert(__first, __last); |
| 348 | } |
| 349 | |
| 350 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 351 | template <class _InputIterator> |
| 352 | hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( |
| 353 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 354 | const hasher& __hf, const key_equal& __eql) |
| 355 | : __table_(__hf, __eql) |
| 356 | { |
| 357 | __table_.rehash(__n); |
| 358 | insert(__first, __last); |
| 359 | } |
| 360 | |
| 361 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 362 | template <class _InputIterator> |
| 363 | hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( |
| 364 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 365 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
| 366 | : __table_(__hf, __eql, __a) |
| 367 | { |
| 368 | __table_.rehash(__n); |
| 369 | insert(__first, __last); |
| 370 | } |
| 371 | |
| 372 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 373 | hash_set<_Value, _Hash, _Pred, _Alloc>::hash_set( |
| 374 | const hash_set& __u) |
| 375 | : __table_(__u.__table_) |
| 376 | { |
| 377 | __table_.rehash(__u.bucket_count()); |
| 378 | insert(__u.begin(), __u.end()); |
| 379 | } |
| 380 | |
| 381 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 382 | template <class _InputIterator> |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 383 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 384 | void |
| 385 | hash_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, |
| 386 | _InputIterator __last) |
| 387 | { |
| 388 | for (; __first != __last; ++__first) |
| 389 | __table_.__insert_unique(*__first); |
| 390 | } |
| 391 | |
| 392 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 393 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 394 | void |
| 395 | swap(hash_set<_Value, _Hash, _Pred, _Alloc>& __x, |
| 396 | hash_set<_Value, _Hash, _Pred, _Alloc>& __y) |
| 397 | { |
| 398 | __x.swap(__y); |
| 399 | } |
| 400 | |
| 401 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 402 | bool |
| 403 | operator==(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x, |
| 404 | const hash_set<_Value, _Hash, _Pred, _Alloc>& __y) |
| 405 | { |
| 406 | if (__x.size() != __y.size()) |
| 407 | return false; |
| 408 | typedef typename hash_set<_Value, _Hash, _Pred, _Alloc>::const_iterator |
| 409 | const_iterator; |
| 410 | for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); |
| 411 | __i != __ex; ++__i) |
| 412 | { |
| 413 | const_iterator __j = __y.find(*__i); |
| 414 | if (__j == __ey || !(*__i == *__j)) |
| 415 | return false; |
| 416 | } |
| 417 | return true; |
| 418 | } |
| 419 | |
| 420 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 421 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 422 | bool |
| 423 | operator!=(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x, |
| 424 | const hash_set<_Value, _Hash, _Pred, _Alloc>& __y) |
| 425 | { |
| 426 | return !(__x == __y); |
| 427 | } |
| 428 | |
| 429 | template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, |
| 430 | class _Alloc = allocator<_Value> > |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 431 | class _LIBCPP_VISIBLE hash_multiset |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 432 | { |
| 433 | public: |
| 434 | // types |
| 435 | typedef _Value key_type; |
| 436 | typedef key_type value_type; |
| 437 | typedef _Hash hasher; |
| 438 | typedef _Pred key_equal; |
| 439 | typedef _Alloc allocator_type; |
| 440 | typedef value_type& reference; |
| 441 | typedef const value_type& const_reference; |
| 442 | |
| 443 | private: |
| 444 | typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; |
| 445 | |
| 446 | __table __table_; |
| 447 | |
| 448 | public: |
| 449 | typedef typename __table::pointer pointer; |
| 450 | typedef typename __table::const_pointer const_pointer; |
| 451 | typedef typename __table::size_type size_type; |
| 452 | typedef typename __table::difference_type difference_type; |
| 453 | |
| 454 | typedef typename __table::const_iterator iterator; |
| 455 | typedef typename __table::const_iterator const_iterator; |
| 456 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 457 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 458 | hash_multiset() {__table_.rehash(193);} |
| 459 | explicit hash_multiset(size_type __n, const hasher& __hf = hasher(), |
| 460 | const key_equal& __eql = key_equal()); |
| 461 | hash_multiset(size_type __n, const hasher& __hf, |
| 462 | const key_equal& __eql, const allocator_type& __a); |
| 463 | template <class _InputIterator> |
| 464 | hash_multiset(_InputIterator __first, _InputIterator __last); |
| 465 | template <class _InputIterator> |
| 466 | hash_multiset(_InputIterator __first, _InputIterator __last, |
| 467 | size_type __n, const hasher& __hf = hasher(), |
| 468 | const key_equal& __eql = key_equal()); |
| 469 | template <class _InputIterator> |
| 470 | hash_multiset(_InputIterator __first, _InputIterator __last, |
| 471 | size_type __n , const hasher& __hf, |
| 472 | const key_equal& __eql, const allocator_type& __a); |
| 473 | hash_multiset(const hash_multiset& __u); |
| 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 | allocator_type get_allocator() const |
| 477 | {return allocator_type(__table_.__node_alloc());} |
| 478 | |
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 | bool empty() const {return __table_.size() == 0;} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 481 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 482 | size_type size() const {return __table_.size();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 483 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 484 | size_type max_size() const {return __table_.max_size();} |
| 485 | |
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 | iterator begin() {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 | iterator end() {return __table_.end();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 490 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 491 | const_iterator begin() const {return __table_.begin();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 492 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 493 | const_iterator end() const {return __table_.end();} |
| 494 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 495 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 496 | iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} |
Sean Hunt | e36a196 | 2011-07-29 23:31:53 +0000 | [diff] [blame^] | 497 | _LIBCPP_INLINE_VISIBILITY |
| 498 | iterator insert(const_iterator, const value_type& __x) {return insert(__x);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 499 | template <class _InputIterator> |
| 500 | void insert(_InputIterator __first, _InputIterator __last); |
| 501 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 502 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 503 | void erase(const_iterator __p) {__table_.erase(__p);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 504 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 505 | size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} |
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 erase(const_iterator __first, const_iterator __last) |
| 508 | {__table_.erase(__first, __last);} |
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 | void clear() {__table_.clear();} |
| 511 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 512 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 513 | void swap(hash_multiset& __u) {__table_.swap(__u.__table_);} |
| 514 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 515 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 516 | hasher hash_funct() const {return __table_.hash_function();} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 517 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 518 | key_equal key_eq() const {return __table_.key_eq();} |
| 519 | |
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 | iterator find(const key_type& __k) {return __table_.find(__k);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 522 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 523 | const_iterator find(const key_type& __k) const {return __table_.find(__k);} |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 524 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 525 | 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] | 526 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 527 | pair<iterator, iterator> equal_range(const key_type& __k) |
| 528 | {return __table_.__equal_range_multi(__k);} |
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 | pair<const_iterator, const_iterator> equal_range(const key_type& __k) const |
| 531 | {return __table_.__equal_range_multi(__k);} |
| 532 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 533 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 534 | size_type bucket_count() const {return __table_.bucket_count();} |
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 | size_type max_bucket_count() const {return __table_.max_bucket_count();} |
| 537 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 538 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 539 | size_type elems_in_bucket(size_type __n) const {return __table_.bucket_size(__n);} |
| 540 | |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 541 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 542 | void resize(size_type __n) {__table_.rehash(__n);} |
| 543 | }; |
| 544 | |
| 545 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 546 | hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( |
| 547 | size_type __n, const hasher& __hf, const key_equal& __eql) |
| 548 | : __table_(__hf, __eql) |
| 549 | { |
| 550 | __table_.rehash(__n); |
| 551 | } |
| 552 | |
| 553 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 554 | hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( |
| 555 | size_type __n, const hasher& __hf, const key_equal& __eql, |
| 556 | const allocator_type& __a) |
| 557 | : __table_(__hf, __eql, __a) |
| 558 | { |
| 559 | __table_.rehash(__n); |
| 560 | } |
| 561 | |
| 562 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 563 | template <class _InputIterator> |
| 564 | hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( |
| 565 | _InputIterator __first, _InputIterator __last) |
| 566 | { |
| 567 | __table_.rehash(193); |
| 568 | insert(__first, __last); |
| 569 | } |
| 570 | |
| 571 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 572 | template <class _InputIterator> |
| 573 | hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( |
| 574 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 575 | const hasher& __hf, const key_equal& __eql) |
| 576 | : __table_(__hf, __eql) |
| 577 | { |
| 578 | __table_.rehash(__n); |
| 579 | insert(__first, __last); |
| 580 | } |
| 581 | |
| 582 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 583 | template <class _InputIterator> |
| 584 | hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( |
| 585 | _InputIterator __first, _InputIterator __last, size_type __n, |
| 586 | const hasher& __hf, const key_equal& __eql, const allocator_type& __a) |
| 587 | : __table_(__hf, __eql, __a) |
| 588 | { |
| 589 | __table_.rehash(__n); |
| 590 | insert(__first, __last); |
| 591 | } |
| 592 | |
| 593 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 594 | hash_multiset<_Value, _Hash, _Pred, _Alloc>::hash_multiset( |
| 595 | const hash_multiset& __u) |
| 596 | : __table_(__u.__table_) |
| 597 | { |
| 598 | __table_.rehash(__u.bucket_count()); |
| 599 | insert(__u.begin(), __u.end()); |
| 600 | } |
| 601 | |
| 602 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 603 | template <class _InputIterator> |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 604 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 605 | void |
| 606 | hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, |
| 607 | _InputIterator __last) |
| 608 | { |
| 609 | for (; __first != __last; ++__first) |
| 610 | __table_.__insert_multi(*__first); |
| 611 | } |
| 612 | |
| 613 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 614 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 615 | void |
| 616 | swap(hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, |
| 617 | hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) |
| 618 | { |
| 619 | __x.swap(__y); |
| 620 | } |
| 621 | |
| 622 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
| 623 | bool |
| 624 | operator==(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, |
| 625 | const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) |
| 626 | { |
| 627 | if (__x.size() != __y.size()) |
| 628 | return false; |
| 629 | typedef typename hash_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator |
| 630 | const_iterator; |
| 631 | typedef pair<const_iterator, const_iterator> _EqRng; |
| 632 | for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) |
| 633 | { |
| 634 | _EqRng __xeq = __x.equal_range(*__i); |
| 635 | _EqRng __yeq = __y.equal_range(*__i); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 636 | if (_VSTD::distance(__xeq.first, __xeq.second) != |
| 637 | _VSTD::distance(__yeq.first, __yeq.second) || |
| 638 | !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 639 | return false; |
| 640 | __i = __xeq.second; |
| 641 | } |
| 642 | return true; |
| 643 | } |
| 644 | |
| 645 | template <class _Value, class _Hash, class _Pred, class _Alloc> |
Howard Hinnant | 422a53f | 2010-09-21 21:28:23 +0000 | [diff] [blame] | 646 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 647 | bool |
| 648 | operator!=(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, |
| 649 | const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __y) |
| 650 | { |
| 651 | return !(__x == __y); |
| 652 | } |
| 653 | |
| 654 | } // __gnu_cxx |
| 655 | |
| 656 | #endif // _LIBCPP_HASH_SET |