1// -*- C++ -*- 2//===-------------------------- unordered_map -----------------------------===// 3// 4// The LLVM Compiler Infrastructure 5// 6// This file is distributed under the University of Illinois Open Source 7// License. See LICENSE.TXT for details. 8// 9//===----------------------------------------------------------------------===// 10 11#ifndef _LIBCPP_UNORDERED_MAP 12#define _LIBCPP_UNORDERED_MAP 13 14/* 15 16 unordered_map synopsis 17 18#include <initializer_list> 19 20namespace std 21{ 22 23template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, 24 class Alloc = allocator<pair<const Key, T>>> 25class unordered_map 26{ 27public: 28 // types 29 typedef Key key_type; 30 typedef T mapped_type; 31 typedef Hash hasher; 32 typedef Pred key_equal; 33 typedef Alloc allocator_type; 34 typedef pair<const key_type, mapped_type> value_type; 35 typedef value_type& reference; 36 typedef const value_type& const_reference; 37 typedef typename allocator_traits<allocator_type>::pointer pointer; 38 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; 39 typedef typename allocator_traits<allocator_type>::size_type size_type; 40 typedef typename allocator_traits<allocator_type>::difference_type difference_type; 41 42 typedef /unspecified/ iterator; 43 typedef /unspecified/ const_iterator; 44 typedef /unspecified/ local_iterator; 45 typedef /unspecified/ const_local_iterator; 46 47 explicit unordered_map(size_type n = 0, const hasher& hf = hasher(), 48 const key_equal& eql = key_equal(), 49 const allocator_type& a = allocator_type()); 50 template <class InputIterator> 51 unordered_map(InputIterator f, InputIterator l, 52 size_type n = 0, const hasher& hf = hasher(), 53 const key_equal& eql = key_equal(), 54 const allocator_type& a = allocator_type()); 55 explicit unordered_map(const allocator_type&); 56 unordered_map(const unordered_map&); 57 unordered_map(const unordered_map&, const Allocator&); 58 unordered_map(unordered_map&&); 59 unordered_map(unordered_map&&, const Allocator&); 60 unordered_map(initializer_list<value_type>, size_type n = 0, 61 const hasher& hf = hasher(), const key_equal& eql = key_equal(), 62 const allocator_type& a = allocator_type()); 63 ~unordered_map(); 64 unordered_map& operator=(const unordered_map&); 65 unordered_map& operator=(unordered_map&&); 66 unordered_map& operator=(initializer_list<value_type>); 67 68 allocator_type get_allocator() const; 69 70 bool empty() const; 71 size_type size() const; 72 size_type max_size() const; 73 74 iterator begin(); 75 iterator end(); 76 const_iterator begin() const; 77 const_iterator end() const; 78 const_iterator cbegin() const; 79 const_iterator cend() const; 80 81 template <class... Args> 82 pair<iterator, bool> emplace(Args&&... args); 83 template <class... Args> 84 iterator emplace_hint(const_iterator position, Args&&... args); 85 pair<iterator, bool> insert(const value_type& obj); 86 template <class P> 87 pair<iterator, bool> insert(P&& obj); 88 iterator insert(const_iterator hint, const value_type& obj); 89 template <class P> 90 iterator insert(const_iterator hint, P&& obj); 91 template <class InputIterator> 92 void insert(InputIterator first, InputIterator last); 93 void insert(initializer_list<value_type>); 94 95 iterator erase(const_iterator position); 96 size_type erase(const key_type& k); 97 iterator erase(const_iterator first, const_iterator last); 98 void clear(); 99 100 void swap(unordered_map&); 101 102 hasher hash_function() const; 103 key_equal key_eq() const; 104 105 iterator find(const key_type& k); 106 const_iterator find(const key_type& k) const; 107 size_type count(const key_type& k) const; 108 pair<iterator, iterator> equal_range(const key_type& k); 109 pair<const_iterator, const_iterator> equal_range(const key_type& k) const; 110 111 mapped_type& operator[](const key_type& k); 112 mapped_type& operator[](key_type&& k); 113 114 mapped_type& at(const key_type& k); 115 const mapped_type& at(const key_type& k) const; 116 117 size_type bucket_count() const; 118 size_type max_bucket_count() const; 119 120 size_type bucket_size(size_type n) const; 121 size_type bucket(const key_type& k) const; 122 123 local_iterator begin(size_type n); 124 local_iterator end(size_type n); 125 const_local_iterator begin(size_type n) const; 126 const_local_iterator end(size_type n) const; 127 const_local_iterator cbegin(size_type n) const; 128 const_local_iterator cend(size_type n) const; 129 130 float load_factor() const; 131 float max_load_factor() const; 132 void max_load_factor(float z); 133 void rehash(size_type n); 134 void reserve(size_type n); 135}; 136 137template <class Key, class T, class Hash, class Pred, class Alloc> 138 void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x, 139 unordered_map<Key, T, Hash, Pred, Alloc>& y); 140 141template <class Key, class T, class Hash, class Pred, class Alloc> 142 bool 143 operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x, 144 const unordered_map<Key, T, Hash, Pred, Alloc>& y); 145 146template <class Key, class T, class Hash, class Pred, class Alloc> 147 bool 148 operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x, 149 const unordered_map<Key, T, Hash, Pred, Alloc>& y); 150 151template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, 152 class Alloc = allocator<pair<const Key, T>>> 153class unordered_multimap 154{ 155public: 156 // types 157 typedef Key key_type; 158 typedef T mapped_type; 159 typedef Hash hasher; 160 typedef Pred key_equal; 161 typedef Alloc allocator_type; 162 typedef pair<const key_type, mapped_type> value_type; 163 typedef value_type& reference; 164 typedef const value_type& const_reference; 165 typedef typename allocator_traits<allocator_type>::pointer pointer; 166 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; 167 typedef typename allocator_traits<allocator_type>::size_type size_type; 168 typedef typename allocator_traits<allocator_type>::difference_type difference_type; 169 170 typedef /unspecified/ iterator; 171 typedef /unspecified/ const_iterator; 172 typedef /unspecified/ local_iterator; 173 typedef /unspecified/ const_local_iterator; 174 175 explicit unordered_multimap(size_type n = 0, const hasher& hf = hasher(), 176 const key_equal& eql = key_equal(), 177 const allocator_type& a = allocator_type()); 178 template <class InputIterator> 179 unordered_multimap(InputIterator f, InputIterator l, 180 size_type n = 0, const hasher& hf = hasher(), 181 const key_equal& eql = key_equal(), 182 const allocator_type& a = allocator_type()); 183 explicit unordered_multimap(const allocator_type&); 184 unordered_multimap(const unordered_multimap&); 185 unordered_multimap(const unordered_multimap&, const Allocator&); 186 unordered_multimap(unordered_multimap&&); 187 unordered_multimap(unordered_multimap&&, const Allocator&); 188 unordered_multimap(initializer_list<value_type>, size_type n = 0, 189 const hasher& hf = hasher(), const key_equal& eql = key_equal(), 190 const allocator_type& a = allocator_type()); 191 ~unordered_multimap(); 192 unordered_multimap& operator=(const unordered_multimap&); 193 unordered_multimap& operator=(unordered_multimap&&); 194 unordered_multimap& operator=(initializer_list<value_type>); 195 196 allocator_type get_allocator() const; 197 198 bool empty() const; 199 size_type size() const; 200 size_type max_size() const; 201 202 iterator begin(); 203 iterator end(); 204 const_iterator begin() const; 205 const_iterator end() const; 206 const_iterator cbegin() const; 207 const_iterator cend() const; 208 209 template <class... Args> 210 iterator emplace(Args&&... args); 211 template <class... Args> 212 iterator emplace_hint(const_iterator position, Args&&... args); 213 iterator insert(const value_type& obj); 214 template <class P> 215 iterator insert(P&& obj); 216 iterator insert(const_iterator hint, const value_type& obj); 217 template <class P> 218 iterator insert(const_iterator hint, P&& obj); 219 template <class InputIterator> 220 void insert(InputIterator first, InputIterator last); 221 void insert(initializer_list<value_type>); 222 223 iterator erase(const_iterator position); 224 size_type erase(const key_type& k); 225 iterator erase(const_iterator first, const_iterator last); 226 void clear(); 227 228 void swap(unordered_multimap&); 229 230 hasher hash_function() const; 231 key_equal key_eq() const; 232 233 iterator find(const key_type& k); 234 const_iterator find(const key_type& k) const; 235 size_type count(const key_type& k) const; 236 pair<iterator, iterator> equal_range(const key_type& k); 237 pair<const_iterator, const_iterator> equal_range(const key_type& k) const; 238 239 size_type bucket_count() const; 240 size_type max_bucket_count() const; 241 242 size_type bucket_size(size_type n) const; 243 size_type bucket(const key_type& k) const; 244 245 local_iterator begin(size_type n); 246 local_iterator end(size_type n); 247 const_local_iterator begin(size_type n) const; 248 const_local_iterator end(size_type n) const; 249 const_local_iterator cbegin(size_type n) const; 250 const_local_iterator cend(size_type n) const; 251 252 float load_factor() const; 253 float max_load_factor() const; 254 void max_load_factor(float z); 255 void rehash(size_type n); 256 void reserve(size_type n); 257}; 258 259template <class Key, class T, class Hash, class Pred, class Alloc> 260 void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x, 261 unordered_multimap<Key, T, Hash, Pred, Alloc>& y); 262 263template <class Key, class T, class Hash, class Pred, class Alloc> 264 bool 265 operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x, 266 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y); 267 268template <class Key, class T, class Hash, class Pred, class Alloc> 269 bool 270 operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x, 271 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y); 272 273} // std 274 275*/ 276 277#include <__config> 278#include <__hash_table> 279#include <functional> 280#include <stdexcept> 281 282#pragma GCC system_header 283 284_LIBCPP_BEGIN_NAMESPACE_STD 285 286template <class _Tp, class _Hash, bool = is_empty<_Hash>::value> 287class __unordered_map_hasher 288 : private _Hash 289{ 290public: 291 __unordered_map_hasher() : _Hash() {} 292 __unordered_map_hasher(const _Hash& __h) : _Hash(__h) {} 293 const _Hash& hash_function() const {return *this;} 294 size_t operator()(const _Tp& __x) const 295 {return static_cast<const _Hash&>(*this)(__x.first);} 296 size_t operator()(const typename _Tp::first_type& __x) const 297 {return static_cast<const _Hash&>(*this)(__x);} 298}; 299 300template <class _Tp, class _Hash> 301class __unordered_map_hasher<_Tp, _Hash, false> 302{ 303 _Hash __hash_; 304public: 305 __unordered_map_hasher() : __hash_() {} 306 __unordered_map_hasher(const _Hash& __h) : __hash_(__h) {} 307 const _Hash& hash_function() const {return __hash_;} 308 size_t operator()(const _Tp& __x) const 309 {return __hash_(__x.first);} 310 size_t operator()(const typename _Tp::first_type& __x) const 311 {return __hash_(__x);} 312}; 313 314template <class _Tp, class _Pred, bool = is_empty<_Pred>::value> 315class __unordered_map_equal 316 : private _Pred 317{ 318public: 319 __unordered_map_equal() : _Pred() {} 320 __unordered_map_equal(const _Pred& __p) : _Pred(__p) {} 321 const _Pred& key_eq() const {return *this;} 322 bool operator()(const _Tp& __x, const _Tp& __y) const 323 {return static_cast<const _Pred&>(*this)(__x.first, __y.first);} 324 bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const 325 {return static_cast<const _Pred&>(*this)(__x, __y.first);} 326 bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const 327 {return static_cast<const _Pred&>(*this)(__x.first, __y);} 328 bool operator()(const typename _Tp::first_type& __x, 329 const typename _Tp::first_type& __y) const 330 {return static_cast<const _Pred&>(*this)(__x, __y);} 331}; 332 333template <class _Tp, class _Pred> 334class __unordered_map_equal<_Tp, _Pred, false> 335{ 336 _Pred __pred_; 337public: 338 __unordered_map_equal() : __pred_() {} 339 __unordered_map_equal(const _Pred& __p) : __pred_(__p) {} 340 const _Pred& key_eq() const {return __pred_;} 341 bool operator()(const _Tp& __x, const _Tp& __y) const 342 {return __pred_(__x.first, __y.first);} 343 bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const 344 {return __pred_(__x, __y.first);} 345 bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const 346 {return __pred_(__x.first, __y);} 347 bool operator()(const typename _Tp::first_type& __x, 348 const typename _Tp::first_type& __y) const 349 {return __pred_(__x, __y);} 350}; 351 352template <class _Alloc> 353class __hash_map_node_destructor 354{ 355 typedef _Alloc allocator_type; 356 typedef allocator_traits<allocator_type> __alloc_traits; 357 typedef typename __alloc_traits::value_type::value_type value_type; 358public: 359 typedef typename __alloc_traits::pointer pointer; 360private: 361 typedef typename value_type::first_type first_type; 362 typedef typename value_type::second_type second_type; 363 364 allocator_type& __na_; 365 366 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&); 367 368public: 369 bool __first_constructed; 370 bool __second_constructed; 371 372 explicit __hash_map_node_destructor(allocator_type& __na) 373 : __na_(__na), 374 __first_constructed(false), 375 __second_constructed(false) 376 {} 377 378#ifdef _LIBCPP_MOVE 379 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x) 380 : __na_(__x.__na_), 381 __first_constructed(__x.__value_constructed), 382 __second_constructed(__x.__value_constructed) 383 { 384 __x.__value_constructed = false; 385 } 386#else 387 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x) 388 : __na_(__x.__na_), 389 __first_constructed(__x.__value_constructed), 390 __second_constructed(__x.__value_constructed) 391 { 392 const_cast<bool&>(__x.__value_constructed) = false; 393 } 394#endif 395 396 void operator()(pointer __p) 397 { 398 if (__second_constructed) 399 __alloc_traits::destroy(__na_, addressof(__p->__value_.second)); 400 if (__first_constructed) 401 __alloc_traits::destroy(__na_, addressof(__p->__value_.first)); 402 if (__p) 403 __alloc_traits::deallocate(__na_, __p, 1); 404 } 405}; 406 407template <class _HashIterator> 408class __hash_map_iterator 409{ 410 _HashIterator __i_; 411 412 typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits; 413 typedef const typename _HashIterator::value_type::first_type key_type; 414 typedef typename _HashIterator::value_type::second_type mapped_type; 415public: 416 typedef forward_iterator_tag iterator_category; 417 typedef pair<key_type, mapped_type> value_type; 418 typedef typename _HashIterator::difference_type difference_type; 419 typedef value_type& reference; 420 typedef typename __pointer_traits::template 421#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 422 rebind<value_type> 423#else 424 rebind<value_type>::other 425#endif 426 pointer; 427 428 __hash_map_iterator() {} 429 430 __hash_map_iterator(_HashIterator __i) : __i_(__i) {} 431 432 reference operator*() const {return *operator->();} 433 pointer operator->() const {return (pointer)__i_.operator->();} 434 435 __hash_map_iterator& operator++() {++__i_; return *this;} 436 __hash_map_iterator operator++(int) 437 { 438 __hash_map_iterator __t(*this); 439 ++(*this); 440 return __t; 441 } 442 443 friend bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y) 444 {return __x.__i_ == __y.__i_;} 445 friend bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) 446 {return __x.__i_ != __y.__i_;} 447 448 template <class, class, class, class, class> friend class unordered_map; 449 template <class, class, class, class, class> friend class unordered_multimap; 450 template <class> friend class __hash_const_iterator; 451 template <class> friend class __hash_const_local_iterator; 452 template <class> friend class __hash_map_const_iterator; 453}; 454 455template <class _HashIterator> 456class __hash_map_const_iterator 457{ 458 _HashIterator __i_; 459 460 typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits; 461 typedef const typename _HashIterator::value_type::first_type key_type; 462 typedef typename _HashIterator::value_type::second_type mapped_type; 463public: 464 typedef forward_iterator_tag iterator_category; 465 typedef pair<key_type, mapped_type> value_type; 466 typedef typename _HashIterator::difference_type difference_type; 467 typedef const value_type& reference; 468 typedef typename __pointer_traits::template 469#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 470 rebind<value_type> 471#else 472 rebind<value_type>::other 473#endif 474 pointer; 475 476 __hash_map_const_iterator() {} 477 478 __hash_map_const_iterator(_HashIterator __i) : __i_(__i) {} 479 __hash_map_const_iterator( 480 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i) 481 : __i_(__i.__i_) {} 482 483 reference operator*() const {return *operator->();} 484 pointer operator->() const {return (pointer)__i_.operator->();} 485 486 __hash_map_const_iterator& operator++() {++__i_; return *this;} 487 __hash_map_const_iterator operator++(int) 488 { 489 __hash_map_const_iterator __t(*this); 490 ++(*this); 491 return __t; 492 } 493 494 friend bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) 495 {return __x.__i_ == __y.__i_;} 496 friend bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) 497 {return __x.__i_ != __y.__i_;} 498 499 template <class, class, class, class, class> friend class unordered_map; 500 template <class, class, class, class, class> friend class unordered_multimap; 501 template <class> friend class __hash_const_iterator; 502 template <class> friend class __hash_const_local_iterator; 503}; 504 505template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, 506 class _Alloc = allocator<pair<const _Key, _Tp> > > 507class unordered_map 508{ 509public: 510 // types 511 typedef _Key key_type; 512 typedef _Tp mapped_type; 513 typedef _Hash hasher; 514 typedef _Pred key_equal; 515 typedef _Alloc allocator_type; 516 typedef pair<const key_type, mapped_type> value_type; 517 typedef value_type& reference; 518 typedef const value_type& const_reference; 519 520private: 521 typedef pair<key_type, mapped_type> __value_type; 522 typedef __unordered_map_hasher<__value_type, hasher> __hasher; 523 typedef __unordered_map_equal<__value_type, key_equal> __key_equal; 524 typedef typename allocator_traits<allocator_type>::template 525#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 526 rebind_alloc<__value_type> 527#else 528 rebind_alloc<__value_type>::other 529#endif 530 __allocator_type; 531 532 typedef __hash_table<__value_type, __hasher, 533 __key_equal, __allocator_type> __table; 534 535 __table __table_; 536 537 typedef typename __table::__node_pointer __node_pointer; 538 typedef typename __table::__node_const_pointer __node_const_pointer; 539 typedef typename __table::__node_traits __node_traits; 540 typedef typename __table::__node_allocator __node_allocator; 541 typedef typename __table::__node __node; 542 typedef __hash_map_node_destructor<__node_allocator> _D; 543 typedef unique_ptr<__node, _D> __node_holder; 544 typedef allocator_traits<allocator_type> __alloc_traits; 545public: 546 typedef typename __alloc_traits::pointer pointer; 547 typedef typename __alloc_traits::const_pointer const_pointer; 548 typedef typename __alloc_traits::size_type size_type; 549 typedef typename __alloc_traits::difference_type difference_type; 550 551 typedef __hash_map_iterator<typename __table::iterator> iterator; 552 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; 553 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator; 554 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator; 555 556 unordered_map() {} // = default; 557 explicit unordered_map(size_type __n, const hasher& __hf = hasher(), 558 const key_equal& __eql = key_equal()); 559 unordered_map(size_type __n, const hasher& __hf, 560 const key_equal& __eql, 561 const allocator_type& __a); 562 template <class _InputIterator> 563 unordered_map(_InputIterator __first, _InputIterator __last); 564 template <class _InputIterator> 565 unordered_map(_InputIterator __first, _InputIterator __last, 566 size_type __n, const hasher& __hf = hasher(), 567 const key_equal& __eql = key_equal()); 568 template <class _InputIterator> 569 unordered_map(_InputIterator __first, _InputIterator __last, 570 size_type __n, const hasher& __hf, 571 const key_equal& __eql, 572 const allocator_type& __a); 573 explicit unordered_map(const allocator_type& __a); 574 unordered_map(const unordered_map& __u); 575 unordered_map(const unordered_map& __u, const allocator_type& __a); 576#ifdef _LIBCPP_MOVE 577 unordered_map(unordered_map&& __u); 578 unordered_map(unordered_map&& __u, const allocator_type& __a); 579#endif 580 unordered_map(initializer_list<value_type> __il); 581 unordered_map(initializer_list<value_type> __il, size_type __n, 582 const hasher& __hf = hasher(), const key_equal& __eql = key_equal()); 583 unordered_map(initializer_list<value_type> __il, size_type __n, 584 const hasher& __hf, const key_equal& __eql, 585 const allocator_type& __a); 586 // ~unordered_map() = default; 587 // unordered_map& operator=(const unordered_map& __u) = default; 588#ifdef _LIBCPP_MOVE 589 unordered_map& operator=(unordered_map&& __u); 590#endif 591 unordered_map& operator=(initializer_list<value_type> __il); 592 593 allocator_type get_allocator() const 594 {return allocator_type(__table_.__node_alloc());} 595 596 bool empty() const {return __table_.size() == 0;} 597 size_type size() const {return __table_.size();} 598 size_type max_size() const {return __table_.max_size();} 599 600 iterator begin() {return __table_.begin();} 601 iterator end() {return __table_.end();} 602 const_iterator begin() const {return __table_.begin();} 603 const_iterator end() const {return __table_.end();} 604 const_iterator cbegin() const {return __table_.begin();} 605 const_iterator cend() const {return __table_.end();} 606 607#ifdef _LIBCPP_MOVE 608 pair<iterator, bool> emplace() 609 {return __table_.__emplace_unique();} 610 611 template <class _A0, 612 class = typename enable_if<is_convertible<_A0, value_type>::value>::type> 613 pair<iterator, bool> emplace(_A0&& __a0) 614 {return __table_.__emplace_unique(_STD::forward<_A0>(__a0));} 615 616 template <class _A0, class... _Args, 617 class = typename enable_if<is_convertible<_A0, key_type>::value>::type> 618 pair<iterator, bool> emplace(_A0&& __a0, _Args&&... __args); 619 620 iterator emplace_hint(const_iterator) 621 {return __table_.__emplace_unique().first;} 622 623 template <class _A0, 624 class = typename enable_if<is_convertible<_A0, value_type>::value>::type> 625 iterator emplace_hint(const_iterator, _A0&& __a0) 626 {return __table_.__emplace_unique(_STD::forward<_A0>(__a0)).first;} 627 628 template <class _A0, class... _Args, 629 class = typename enable_if<is_convertible<_A0, key_type>::value>::type> 630 iterator emplace_hint(const_iterator, _A0&& __a0, _Args&&... __args) 631 {return emplace(_STD::forward<_A0>(__a0), 632 _STD::forward<_Args>(__args)...).first;} 633#endif 634 pair<iterator, bool> insert(const value_type& __x) 635 {return __table_.__insert_unique(__x);} 636#ifdef _LIBCPP_MOVE 637 template <class _P, 638 class = typename enable_if<is_convertible<_P, value_type>::value>::type> 639 pair<iterator, bool> insert(_P&& __x) 640 {return __table_.__insert_unique(_STD::forward<_P>(__x));} 641#endif 642 iterator insert(const_iterator, const value_type& __x) 643 {return insert(__x).first;} 644#ifdef _LIBCPP_MOVE 645 template <class _P, 646 class = typename enable_if<is_convertible<_P, value_type>::value>::type> 647 iterator insert(const_iterator, _P&& __x) 648 {return insert(_STD::forward<_P>(__x)).first;} 649#endif 650 template <class _InputIterator> 651 void insert(_InputIterator __first, _InputIterator __last); 652 void insert(initializer_list<value_type> __il) 653 {insert(__il.begin(), __il.end());} 654 655 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);} 656 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} 657 iterator erase(const_iterator __first, const_iterator __last) 658 {return __table_.erase(__first.__i_, __last.__i_);} 659 void clear() {__table_.clear();} 660 661 void swap(unordered_map& __u) {__table_.swap(__u.__table_);} 662 663 hasher hash_function() const 664 {return __table_.hash_function().hash_function();} 665 key_equal key_eq() const 666 {return __table_.key_eq().key_eq();} 667 668 iterator find(const key_type& __k) {return __table_.find(__k);} 669 const_iterator find(const key_type& __k) const {return __table_.find(__k);} 670 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} 671 pair<iterator, iterator> equal_range(const key_type& __k) 672 {return __table_.__equal_range_unique(__k);} 673 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const 674 {return __table_.__equal_range_unique(__k);} 675 676 mapped_type& operator[](const key_type& __k); 677#ifdef _LIBCPP_MOVE 678 mapped_type& operator[](key_type&& __k); 679#endif 680 681 mapped_type& at(const key_type& __k); 682 const mapped_type& at(const key_type& __k) const; 683 684 size_type bucket_count() const {return __table_.bucket_count();} 685 size_type max_bucket_count() const {return __table_.max_bucket_count();} 686 687 size_type bucket_size(size_type __n) const 688 {return __table_.bucket_size(__n);} 689 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} 690 691 local_iterator begin(size_type __n) {return __table_.begin(__n);} 692 local_iterator end(size_type __n) {return __table_.end(__n);} 693 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} 694 const_local_iterator end(size_type __n) const {return __table_.cend(__n);} 695 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} 696 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} 697 698 float load_factor() const {return __table_.load_factor();} 699 float max_load_factor() const {return __table_.max_load_factor();} 700 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} 701 void rehash(size_type __n) {__table_.rehash(__n);} 702 void reserve(size_type __n) {__table_.reserve(__n);} 703 704private: 705#ifdef _LIBCPP_MOVE 706 template <class _A0, class... _Args, 707 class = typename enable_if<is_convertible<_A0, key_type>::value>::type> 708 __node_holder __construct_node(_A0&& __a0, _Args&&... __args); 709 template <class _A0, 710 class = typename enable_if<is_convertible<_A0, value_type>::value>::type> 711 __node_holder __construct_node(_A0&& __a0); 712#else 713 __node_holder __construct_node(const key_type& __k); 714#endif 715}; 716 717template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 718unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( 719 size_type __n, const hasher& __hf, const key_equal& __eql) 720 : __table_(__hf, __eql) 721{ 722 __table_.rehash(__n); 723} 724 725template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 726unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( 727 size_type __n, const hasher& __hf, const key_equal& __eql, 728 const allocator_type& __a) 729 : __table_(__hf, __eql, __a) 730{ 731 __table_.rehash(__n); 732} 733 734template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 735inline 736unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( 737 const allocator_type& __a) 738 : __table_(__a) 739{ 740} 741 742template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 743template <class _InputIterator> 744unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( 745 _InputIterator __first, _InputIterator __last) 746{ 747 insert(__first, __last); 748} 749 750template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 751template <class _InputIterator> 752unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( 753 _InputIterator __first, _InputIterator __last, size_type __n, 754 const hasher& __hf, const key_equal& __eql) 755 : __table_(__hf, __eql) 756{ 757 __table_.rehash(__n); 758 insert(__first, __last); 759} 760 761template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 762template <class _InputIterator> 763unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( 764 _InputIterator __first, _InputIterator __last, size_type __n, 765 const hasher& __hf, const key_equal& __eql, const allocator_type& __a) 766 : __table_(__hf, __eql, __a) 767{ 768 __table_.rehash(__n); 769 insert(__first, __last); 770} 771 772template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 773unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( 774 const unordered_map& __u) 775 : __table_(__u.__table_) 776{ 777 __table_.rehash(__u.bucket_count()); 778 insert(__u.begin(), __u.end()); 779} 780 781template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 782unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( 783 const unordered_map& __u, const allocator_type& __a) 784 : __table_(__u.__table_, __a) 785{ 786 __table_.rehash(__u.bucket_count()); 787 insert(__u.begin(), __u.end()); 788} 789 790#ifdef _LIBCPP_MOVE 791 792template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 793inline 794unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( 795 unordered_map&& __u) 796 : __table_(_STD::move(__u.__table_)) 797{ 798} 799 800template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 801unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( 802 unordered_map&& __u, const allocator_type& __a) 803 : __table_(_STD::move(__u.__table_), __a) 804{ 805 if (__a != __u.get_allocator()) 806 { 807 iterator __i = __u.begin(); 808 while (__u.size() != 0) 809 __table_.__insert_unique( 810 _STD::move(__u.__table_.remove((__i++).__i_)->__value_) 811 ); 812 } 813} 814 815#endif 816 817template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 818unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( 819 initializer_list<value_type> __il) 820{ 821 insert(__il.begin(), __il.end()); 822} 823 824template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 825unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( 826 initializer_list<value_type> __il, size_type __n, const hasher& __hf, 827 const key_equal& __eql) 828 : __table_(__hf, __eql) 829{ 830 __table_.rehash(__n); 831 insert(__il.begin(), __il.end()); 832} 833 834template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 835unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( 836 initializer_list<value_type> __il, size_type __n, const hasher& __hf, 837 const key_equal& __eql, const allocator_type& __a) 838 : __table_(__hf, __eql, __a) 839{ 840 __table_.rehash(__n); 841 insert(__il.begin(), __il.end()); 842} 843 844#ifdef _LIBCPP_MOVE 845 846template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 847inline 848unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& 849unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u) 850{ 851 __table_ = _STD::move(__u.__table_); 852 return *this; 853} 854 855#endif 856 857template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 858inline 859unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& 860unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=( 861 initializer_list<value_type> __il) 862{ 863 __table_.__assign_unique(__il.begin(), __il.end()); 864 return *this; 865} 866 867#ifdef _LIBCPP_MOVE 868 869template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 870template <class _A0, class... _Args, 871 class // = typename enable_if<is_convertible<_A0, key_type>::value>::type 872 > 873typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder 874unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0, 875 _Args&&... __args) 876{ 877 __node_allocator& __na = __table_.__node_alloc(); 878 __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); 879 __node_traits::construct(__na, addressof(__h->__value_.first), 880 _STD::forward<_A0>(__a0)); 881 __h.get_deleter().__first_constructed = true; 882 __node_traits::construct(__na, addressof(__h->__value_.second), 883 _STD::forward<_Args>(__args)...); 884 __h.get_deleter().__second_constructed = true; 885 return __h; 886} 887 888template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 889template <class _A0, 890 class // = typename enable_if<is_convertible<_A0, value_type>::value>::type 891 > 892typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder 893unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0) 894{ 895 __node_allocator& __na = __table_.__node_alloc(); 896 __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); 897 __node_traits::construct(__na, addressof(__h->__value_), 898 _STD::forward<_A0>(__a0)); 899 __h.get_deleter().__first_constructed = true; 900 __h.get_deleter().__second_constructed = true; 901 return __h; 902} 903 904template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 905template <class _A0, class... _Args, 906 class // = typename enable_if<is_convertible<_A0, key_type>::value>::type 907 > 908pair<typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator, bool> 909unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_A0&& __a0, _Args&&... __args) 910{ 911 __node_holder __h = __construct_node(_STD::forward<_A0>(__a0), 912 _STD::forward<_Args>(__args)...); 913 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); 914 if (__r.second) 915 __h.release(); 916 return __r; 917} 918 919#else 920 921template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 922typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder 923unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k) 924{ 925 __node_allocator& __na = __table_.__node_alloc(); 926 __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); 927 __node_traits::construct(__na, addressof(__h->__value_.first), __k); 928 __h.get_deleter().__first_constructed = true; 929 __node_traits::construct(__na, addressof(__h->__value_.second)); 930 __h.get_deleter().__second_constructed = true; 931 return _STD::move(__h); 932} 933 934#endif 935 936template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 937template <class _InputIterator> 938inline 939void 940unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, 941 _InputIterator __last) 942{ 943 for (; __first != __last; ++__first) 944 __table_.__insert_unique(*__first); 945} 946 947template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 948_Tp& 949unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) 950{ 951 iterator __i = find(__k); 952 if (__i != end()) 953 return __i->second; 954 __node_holder __h = __construct_node(__k); 955 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); 956 __h.release(); 957 return __r.first->second; 958} 959 960#ifdef _LIBCPP_MOVE 961 962template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 963_Tp& 964unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k) 965{ 966 iterator __i = find(__k); 967 if (__i != end()) 968 return __i->second; 969 __node_holder __h = __construct_node(_STD::move(__k)); 970 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); 971 __h.release(); 972 return __r.first->second; 973} 974 975#endif 976 977template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 978_Tp& 979unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) 980{ 981 iterator __i = find(__k); 982#ifndef _LIBCPP_NO_EXCEPTIONS 983 if (__i == end()) 984 throw out_of_range("unordered_map::at: key not found"); 985#endif 986 return __i->second; 987} 988 989template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 990const _Tp& 991unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const 992{ 993 const_iterator __i = find(__k); 994#ifndef _LIBCPP_NO_EXCEPTIONS 995 if (__i == end()) 996 throw out_of_range("unordered_map::at: key not found"); 997#endif 998 return __i->second; 999} 1000 1001template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1002inline 1003void 1004swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, 1005 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) 1006{ 1007 __x.swap(__y); 1008} 1009 1010template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1011bool 1012operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, 1013 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) 1014{ 1015 if (__x.size() != __y.size()) 1016 return false; 1017 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator 1018 const_iterator; 1019 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); 1020 __i != __ex; ++__i) 1021 { 1022 const_iterator __j = __y.find(__i->first); 1023 if (__j == __ey || !(*__i == *__j)) 1024 return false; 1025 } 1026 return true; 1027} 1028 1029template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1030inline 1031bool 1032operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, 1033 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) 1034{ 1035 return !(__x == __y); 1036} 1037 1038template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, 1039 class _Alloc = allocator<pair<const _Key, _Tp> > > 1040class unordered_multimap 1041{ 1042public: 1043 // types 1044 typedef _Key key_type; 1045 typedef _Tp mapped_type; 1046 typedef _Hash hasher; 1047 typedef _Pred key_equal; 1048 typedef _Alloc allocator_type; 1049 typedef pair<const key_type, mapped_type> value_type; 1050 typedef value_type& reference; 1051 typedef const value_type& const_reference; 1052 1053private: 1054 typedef pair<key_type, mapped_type> __value_type; 1055 typedef __unordered_map_hasher<__value_type, hasher> __hasher; 1056 typedef __unordered_map_equal<__value_type, key_equal> __key_equal; 1057 typedef typename allocator_traits<allocator_type>::template 1058#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 1059 rebind_alloc<__value_type> 1060#else 1061 rebind_alloc<__value_type>::other 1062#endif 1063 __allocator_type; 1064 1065 typedef __hash_table<__value_type, __hasher, 1066 __key_equal, __allocator_type> __table; 1067 1068 __table __table_; 1069 1070 typedef typename __table::__node_traits __node_traits; 1071 typedef typename __table::__node_allocator __node_allocator; 1072 typedef typename __table::__node __node; 1073 typedef __hash_map_node_destructor<__node_allocator> _D; 1074 typedef unique_ptr<__node, _D> __node_holder; 1075 typedef allocator_traits<allocator_type> __alloc_traits; 1076public: 1077 typedef typename __alloc_traits::pointer pointer; 1078 typedef typename __alloc_traits::const_pointer const_pointer; 1079 typedef typename __alloc_traits::size_type size_type; 1080 typedef typename __alloc_traits::difference_type difference_type; 1081 1082 typedef __hash_map_iterator<typename __table::iterator> iterator; 1083 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; 1084 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator; 1085 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator; 1086 1087 unordered_multimap() {} // = default 1088 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(), 1089 const key_equal& __eql = key_equal()); 1090 unordered_multimap(size_type __n, const hasher& __hf, 1091 const key_equal& __eql, 1092 const allocator_type& __a); 1093 template <class _InputIterator> 1094 unordered_multimap(_InputIterator __first, _InputIterator __last); 1095 template <class _InputIterator> 1096 unordered_multimap(_InputIterator __first, _InputIterator __last, 1097 size_type __n, const hasher& __hf = hasher(), 1098 const key_equal& __eql = key_equal()); 1099 template <class _InputIterator> 1100 unordered_multimap(_InputIterator __first, _InputIterator __last, 1101 size_type __n, const hasher& __hf, 1102 const key_equal& __eql, 1103 const allocator_type& __a); 1104 explicit unordered_multimap(const allocator_type& __a); 1105 unordered_multimap(const unordered_multimap& __u); 1106 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a); 1107#ifdef _LIBCPP_MOVE 1108 unordered_multimap(unordered_multimap&& __u); 1109 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a); 1110#endif 1111 unordered_multimap(initializer_list<value_type> __il); 1112 unordered_multimap(initializer_list<value_type> __il, size_type __n, 1113 const hasher& __hf = hasher(), 1114 const key_equal& __eql = key_equal()); 1115 unordered_multimap(initializer_list<value_type> __il, size_type __n, 1116 const hasher& __hf, const key_equal& __eql, 1117 const allocator_type& __a); 1118 // ~unordered_multimap() = default; 1119 // unordered_multimap& operator=(const unordered_multimap& __u) = default; 1120#ifdef _LIBCPP_MOVE 1121 unordered_multimap& operator=(unordered_multimap&& __u); 1122#endif 1123 unordered_multimap& operator=(initializer_list<value_type> __il); 1124 1125 allocator_type get_allocator() const 1126 {return allocator_type(__table_.__node_alloc());} 1127 1128 bool empty() const {return __table_.size() == 0;} 1129 size_type size() const {return __table_.size();} 1130 size_type max_size() const {return __table_.max_size();} 1131 1132 iterator begin() {return __table_.begin();} 1133 iterator end() {return __table_.end();} 1134 const_iterator begin() const {return __table_.begin();} 1135 const_iterator end() const {return __table_.end();} 1136 const_iterator cbegin() const {return __table_.begin();} 1137 const_iterator cend() const {return __table_.end();} 1138 1139#ifdef _LIBCPP_MOVE 1140 iterator emplace() 1141 {return __table_.__emplace_multi();} 1142 1143 template <class _A0, 1144 class = typename enable_if<is_convertible<_A0, value_type>::value>::type> 1145 iterator emplace(_A0&& __a0) 1146 {return __table_.__emplace_multi(_STD::forward<_A0>(__a0));} 1147 1148 template <class _A0, class... _Args, 1149 class = typename enable_if<is_convertible<_A0, key_type>::value>::type> 1150 iterator emplace(_A0&& __a0, _Args&&... __args); 1151 1152 iterator emplace_hint(const_iterator __p) 1153 {return __table_.__emplace_hint_multi(__p.__i_);} 1154 1155 template <class _A0, 1156 class = typename enable_if<is_convertible<_A0, value_type>::value>::type> 1157 iterator emplace_hint(const_iterator __p, _A0&& __a0) 1158 {return __table_.__emplace_hint_multi(__p.__i_, _STD::forward<_A0>(__a0));} 1159 1160 template <class _A0, class... _Args, 1161 class = typename enable_if<is_convertible<_A0, key_type>::value>::type> 1162 iterator emplace_hint(const_iterator __p, _A0&& __a0, _Args&&... __args); 1163#endif 1164 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} 1165#ifdef _LIBCPP_MOVE 1166 template <class _P, 1167 class = typename enable_if<is_convertible<_P, value_type>::value>::type> 1168 iterator insert(_P&& __x) 1169 {return __table_.__insert_multi(_STD::forward<_P>(__x));} 1170#endif 1171 iterator insert(const_iterator __p, const value_type& __x) 1172 {return __table_.__insert_multi(__p.__i_, __x);} 1173#ifdef _LIBCPP_MOVE 1174 template <class _P, 1175 class = typename enable_if<is_convertible<_P, value_type>::value>::type> 1176 iterator insert(const_iterator __p, _P&& __x) 1177 {return __table_.__insert_multi(__p.__i_, _STD::forward<_P>(__x));} 1178#endif 1179 template <class _InputIterator> 1180 void insert(_InputIterator __first, _InputIterator __last); 1181 void insert(initializer_list<value_type> __il) 1182 {insert(__il.begin(), __il.end());} 1183 1184 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);} 1185 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} 1186 iterator erase(const_iterator __first, const_iterator __last) 1187 {return __table_.erase(__first.__i_, __last.__i_);} 1188 void clear() {__table_.clear();} 1189 1190 void swap(unordered_multimap& __u) {__table_.swap(__u.__table_);} 1191 1192 hasher hash_function() const 1193 {return __table_.hash_function().hash_function();} 1194 key_equal key_eq() const 1195 {return __table_.key_eq().key_eq();} 1196 1197 iterator find(const key_type& __k) {return __table_.find(__k);} 1198 const_iterator find(const key_type& __k) const {return __table_.find(__k);} 1199 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} 1200 pair<iterator, iterator> equal_range(const key_type& __k) 1201 {return __table_.__equal_range_multi(__k);} 1202 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const 1203 {return __table_.__equal_range_multi(__k);} 1204 1205 size_type bucket_count() const {return __table_.bucket_count();} 1206 size_type max_bucket_count() const {return __table_.max_bucket_count();} 1207 1208 size_type bucket_size(size_type __n) const 1209 {return __table_.bucket_size(__n);} 1210 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);} 1211 1212 local_iterator begin(size_type __n) {return __table_.begin(__n);} 1213 local_iterator end(size_type __n) {return __table_.end(__n);} 1214 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);} 1215 const_local_iterator end(size_type __n) const {return __table_.cend(__n);} 1216 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);} 1217 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);} 1218 1219 float load_factor() const {return __table_.load_factor();} 1220 float max_load_factor() const {return __table_.max_load_factor();} 1221 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);} 1222 void rehash(size_type __n) {__table_.rehash(__n);} 1223 void reserve(size_type __n) {__table_.reserve(__n);} 1224 1225private: 1226#ifdef _LIBCPP_MOVE 1227 template <class _A0, class... _Args, 1228 class = typename enable_if<is_convertible<_A0, key_type>::value>::type> 1229 __node_holder __construct_node(_A0&& __a0, _Args&&... __args); 1230 template <class _A0, 1231 class = typename enable_if<is_convertible<_A0, value_type>::value>::type> 1232 __node_holder __construct_node(_A0&& __a0); 1233#endif 1234}; 1235 1236template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1237unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( 1238 size_type __n, const hasher& __hf, const key_equal& __eql) 1239 : __table_(__hf, __eql) 1240{ 1241 __table_.rehash(__n); 1242} 1243 1244template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1245unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( 1246 size_type __n, const hasher& __hf, const key_equal& __eql, 1247 const allocator_type& __a) 1248 : __table_(__hf, __eql, __a) 1249{ 1250 __table_.rehash(__n); 1251} 1252 1253template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1254template <class _InputIterator> 1255unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( 1256 _InputIterator __first, _InputIterator __last) 1257{ 1258 insert(__first, __last); 1259} 1260 1261template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1262template <class _InputIterator> 1263unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( 1264 _InputIterator __first, _InputIterator __last, size_type __n, 1265 const hasher& __hf, const key_equal& __eql) 1266 : __table_(__hf, __eql) 1267{ 1268 __table_.rehash(__n); 1269 insert(__first, __last); 1270} 1271 1272template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1273template <class _InputIterator> 1274unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( 1275 _InputIterator __first, _InputIterator __last, size_type __n, 1276 const hasher& __hf, const key_equal& __eql, const allocator_type& __a) 1277 : __table_(__hf, __eql, __a) 1278{ 1279 __table_.rehash(__n); 1280 insert(__first, __last); 1281} 1282 1283 1284template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1285inline 1286unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( 1287 const allocator_type& __a) 1288 : __table_(__a) 1289{ 1290} 1291 1292template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1293unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( 1294 const unordered_multimap& __u) 1295 : __table_(__u.__table_) 1296{ 1297 __table_.rehash(__u.bucket_count()); 1298 insert(__u.begin(), __u.end()); 1299} 1300 1301template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1302unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( 1303 const unordered_multimap& __u, const allocator_type& __a) 1304 : __table_(__u.__table_, __a) 1305{ 1306 __table_.rehash(__u.bucket_count()); 1307 insert(__u.begin(), __u.end()); 1308} 1309 1310#ifdef _LIBCPP_MOVE 1311 1312template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1313inline 1314unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( 1315 unordered_multimap&& __u) 1316 : __table_(_STD::move(__u.__table_)) 1317{ 1318} 1319 1320template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1321unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( 1322 unordered_multimap&& __u, const allocator_type& __a) 1323 : __table_(_STD::move(__u.__table_), __a) 1324{ 1325 if (__a != __u.get_allocator()) 1326 { 1327 iterator __i = __u.begin(); 1328 while (__u.size() != 0) 1329{ 1330 __table_.__insert_multi( 1331 _STD::move(__u.__table_.remove((__i++).__i_)->__value_) 1332 ); 1333} 1334 } 1335} 1336 1337#endif 1338 1339template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1340unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( 1341 initializer_list<value_type> __il) 1342{ 1343 insert(__il.begin(), __il.end()); 1344} 1345 1346template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1347unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( 1348 initializer_list<value_type> __il, size_type __n, const hasher& __hf, 1349 const key_equal& __eql) 1350 : __table_(__hf, __eql) 1351{ 1352 __table_.rehash(__n); 1353 insert(__il.begin(), __il.end()); 1354} 1355 1356template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1357unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( 1358 initializer_list<value_type> __il, size_type __n, const hasher& __hf, 1359 const key_equal& __eql, const allocator_type& __a) 1360 : __table_(__hf, __eql, __a) 1361{ 1362 __table_.rehash(__n); 1363 insert(__il.begin(), __il.end()); 1364} 1365 1366#ifdef _LIBCPP_MOVE 1367 1368template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1369inline 1370unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& 1371unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u) 1372{ 1373 __table_ = _STD::move(__u.__table_); 1374 return *this; 1375} 1376 1377#endif 1378 1379template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1380inline 1381unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& 1382unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=( 1383 initializer_list<value_type> __il) 1384{ 1385 __table_.__assign_multi(__il.begin(), __il.end()); 1386 return *this; 1387} 1388 1389#ifdef _LIBCPP_MOVE 1390 1391template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1392template <class _A0, class... _Args, 1393 class // = typename enable_if<is_convertible<_A0, key_type>::value>::type 1394 > 1395typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder 1396unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node( 1397 _A0&& __a0, _Args&&... __args) 1398{ 1399 __node_allocator& __na = __table_.__node_alloc(); 1400 __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); 1401 __node_traits::construct(__na, addressof(__h->__value_.first), 1402 _STD::forward<_A0>(__a0)); 1403 __h.get_deleter().__first_constructed = true; 1404 __node_traits::construct(__na, addressof(__h->__value_.second), 1405 _STD::forward<_Args>(__args)...); 1406 __h.get_deleter().__second_constructed = true; 1407 return __h; 1408} 1409 1410template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1411template <class _A0, 1412 class // = typename enable_if<is_convertible<_A0, value_type>::value>::type 1413 > 1414typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder 1415unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0) 1416{ 1417 __node_allocator& __na = __table_.__node_alloc(); 1418 __node_holder __h(__node_traits::allocate(__na, 1), _D(__na)); 1419 __node_traits::construct(__na, addressof(__h->__value_), 1420 _STD::forward<_A0>(__a0)); 1421 __h.get_deleter().__first_constructed = true; 1422 __h.get_deleter().__second_constructed = true; 1423 return __h; 1424} 1425 1426template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1427template <class _A0, class... _Args, 1428 class // = typename enable_if<is_convertible<_A0, key_type>::value>::type 1429 > 1430typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator 1431unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_A0&& __a0, _Args&&... __args) 1432{ 1433 __node_holder __h = __construct_node(_STD::forward<_A0>(__a0), 1434 _STD::forward<_Args>(__args)...); 1435 iterator __r = __table_.__node_insert_multi(__h.get()); 1436 __h.release(); 1437 return __r; 1438} 1439 1440template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1441template <class _A0, class... _Args, 1442 class // = typename enable_if<is_convertible<_A0, key_type>::value>::type 1443 > 1444typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator 1445unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace_hint( 1446 const_iterator __p, _A0&& __a0, _Args&&... __args) 1447{ 1448 __node_holder __h = __construct_node(_STD::forward<_A0>(__a0), 1449 _STD::forward<_Args>(__args)...); 1450 iterator __r = __table_.__node_insert_multi(__p.__i_, __h.get()); 1451 __h.release(); 1452 return __r; 1453} 1454 1455#endif 1456 1457template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1458template <class _InputIterator> 1459inline 1460void 1461unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, 1462 _InputIterator __last) 1463{ 1464 for (; __first != __last; ++__first) 1465 __table_.__insert_multi(*__first); 1466} 1467 1468template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1469inline 1470void 1471swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, 1472 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) 1473{ 1474 __x.swap(__y); 1475} 1476 1477template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1478bool 1479operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, 1480 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) 1481{ 1482 if (__x.size() != __y.size()) 1483 return false; 1484 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator 1485 const_iterator; 1486 typedef pair<const_iterator, const_iterator> _EqRng; 1487 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) 1488 { 1489 _EqRng __xeq = __x.equal_range(__i->first); 1490 _EqRng __yeq = __y.equal_range(__i->first); 1491 if (_STD::distance(__xeq.first, __xeq.second) != 1492 _STD::distance(__yeq.first, __yeq.second) || 1493 !_STD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) 1494 return false; 1495 __i = __xeq.second; 1496 } 1497 return true; 1498} 1499 1500template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 1501inline 1502bool 1503operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, 1504 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) 1505{ 1506 return !(__x == __y); 1507} 1508 1509_LIBCPP_END_NAMESPACE_STD 1510 1511#endif // _LIBCPP_UNORDERED_MAP 1512