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