13e519524SHoward Hinnant// -*- C++ -*- 2eb8650a7SLouis Dionne//===----------------------------------------------------------------------===// 33e519524SHoward Hinnant// 457b08b09SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 557b08b09SChandler Carruth// See https://llvm.org/LICENSE.txt for license information. 657b08b09SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 73e519524SHoward Hinnant// 83e519524SHoward Hinnant//===----------------------------------------------------------------------===// 93e519524SHoward Hinnant 103e519524SHoward Hinnant#ifndef _LIBCPP_HASH_MAP 113e519524SHoward Hinnant#define _LIBCPP_HASH_MAP 123e519524SHoward Hinnant 133e519524SHoward Hinnant/* 143e519524SHoward Hinnant 153e519524SHoward Hinnant hash_map synopsis 163e519524SHoward Hinnant 173e519524SHoward Hinnantnamespace __gnu_cxx 183e519524SHoward Hinnant{ 193e519524SHoward Hinnant 203e519524SHoward Hinnanttemplate <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, 213e519524SHoward Hinnant class Alloc = allocator<pair<const Key, T>>> 223e519524SHoward Hinnantclass hash_map 233e519524SHoward Hinnant{ 243e519524SHoward Hinnantpublic: 253e519524SHoward Hinnant // types 263e519524SHoward Hinnant typedef Key key_type; 273e519524SHoward Hinnant typedef T mapped_type; 283e519524SHoward Hinnant typedef Hash hasher; 293e519524SHoward Hinnant typedef Pred key_equal; 303e519524SHoward Hinnant typedef Alloc allocator_type; 313e519524SHoward Hinnant typedef pair<const key_type, mapped_type> value_type; 323e519524SHoward Hinnant typedef value_type& reference; 333e519524SHoward Hinnant typedef const value_type& const_reference; 343e519524SHoward Hinnant typedef typename allocator_traits<allocator_type>::pointer pointer; 353e519524SHoward Hinnant typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; 363e519524SHoward Hinnant typedef typename allocator_traits<allocator_type>::size_type size_type; 373e519524SHoward Hinnant typedef typename allocator_traits<allocator_type>::difference_type difference_type; 383e519524SHoward Hinnant 393e519524SHoward Hinnant typedef /unspecified/ iterator; 403e519524SHoward Hinnant typedef /unspecified/ const_iterator; 413e519524SHoward Hinnant 423eb5aec6SEric Fiselier hash_map(); 433eb5aec6SEric Fiselier explicit hash_map(size_type n, const hasher& hf = hasher(), 443e519524SHoward Hinnant const key_equal& eql = key_equal(), 453e519524SHoward Hinnant const allocator_type& a = allocator_type()); 463e519524SHoward Hinnant template <class InputIterator> 473eb5aec6SEric Fiselier hash_map(InputIterator f, InputIterator l); 483eb5aec6SEric Fiselier template <class InputIterator> 493e519524SHoward Hinnant hash_map(InputIterator f, InputIterator l, 503eb5aec6SEric Fiselier size_type n, const hasher& hf = hasher(), 513e519524SHoward Hinnant const key_equal& eql = key_equal(), 523e519524SHoward Hinnant const allocator_type& a = allocator_type()); 533e519524SHoward Hinnant hash_map(const hash_map&); 543e519524SHoward Hinnant ~hash_map(); 553e519524SHoward Hinnant hash_map& operator=(const hash_map&); 563e519524SHoward Hinnant 573e519524SHoward Hinnant allocator_type get_allocator() const; 583e519524SHoward Hinnant 593e519524SHoward Hinnant bool empty() const; 603e519524SHoward Hinnant size_type size() const; 613e519524SHoward Hinnant size_type max_size() const; 623e519524SHoward Hinnant 633e519524SHoward Hinnant iterator begin(); 643e519524SHoward Hinnant iterator end(); 653e519524SHoward Hinnant const_iterator begin() const; 663e519524SHoward Hinnant const_iterator end() const; 673e519524SHoward Hinnant 683e519524SHoward Hinnant pair<iterator, bool> insert(const value_type& obj); 693e519524SHoward Hinnant template <class InputIterator> 703e519524SHoward Hinnant void insert(InputIterator first, InputIterator last); 713e519524SHoward Hinnant 723e519524SHoward Hinnant void erase(const_iterator position); 733e519524SHoward Hinnant size_type erase(const key_type& k); 743e519524SHoward Hinnant void erase(const_iterator first, const_iterator last); 753e519524SHoward Hinnant void clear(); 763e519524SHoward Hinnant 773e519524SHoward Hinnant void swap(hash_map&); 783e519524SHoward Hinnant 793e519524SHoward Hinnant hasher hash_funct() const; 803e519524SHoward Hinnant key_equal key_eq() const; 813e519524SHoward Hinnant 823e519524SHoward Hinnant iterator find(const key_type& k); 833e519524SHoward Hinnant const_iterator find(const key_type& k) const; 843e519524SHoward Hinnant size_type count(const key_type& k) const; 853e519524SHoward Hinnant pair<iterator, iterator> equal_range(const key_type& k); 863e519524SHoward Hinnant pair<const_iterator, const_iterator> equal_range(const key_type& k) const; 873e519524SHoward Hinnant 883e519524SHoward Hinnant mapped_type& operator[](const key_type& k); 893e519524SHoward Hinnant 903e519524SHoward Hinnant size_type bucket_count() const; 913e519524SHoward Hinnant size_type max_bucket_count() const; 923e519524SHoward Hinnant 933e519524SHoward Hinnant size_type elems_in_bucket(size_type n) const; 943e519524SHoward Hinnant 953e519524SHoward Hinnant void resize(size_type n); 963e519524SHoward Hinnant}; 973e519524SHoward Hinnant 983e519524SHoward Hinnanttemplate <class Key, class T, class Hash, class Pred, class Alloc> 993e519524SHoward Hinnant void swap(hash_map<Key, T, Hash, Pred, Alloc>& x, 1003e519524SHoward Hinnant hash_map<Key, T, Hash, Pred, Alloc>& y); 1013e519524SHoward Hinnant 1023e519524SHoward Hinnanttemplate <class Key, class T, class Hash, class Pred, class Alloc> 1033e519524SHoward Hinnant bool 1043e519524SHoward Hinnant operator==(const hash_map<Key, T, Hash, Pred, Alloc>& x, 1053e519524SHoward Hinnant const hash_map<Key, T, Hash, Pred, Alloc>& y); 1063e519524SHoward Hinnant 1073e519524SHoward Hinnanttemplate <class Key, class T, class Hash, class Pred, class Alloc> 1083e519524SHoward Hinnant bool 1093e519524SHoward Hinnant operator!=(const hash_map<Key, T, Hash, Pred, Alloc>& x, 1103e519524SHoward Hinnant const hash_map<Key, T, Hash, Pred, Alloc>& y); 1113e519524SHoward Hinnant 1123e519524SHoward Hinnanttemplate <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, 1133e519524SHoward Hinnant class Alloc = allocator<pair<const Key, T>>> 1143e519524SHoward Hinnantclass hash_multimap 1153e519524SHoward Hinnant{ 1163e519524SHoward Hinnantpublic: 1173e519524SHoward Hinnant // types 1183e519524SHoward Hinnant typedef Key key_type; 1193e519524SHoward Hinnant typedef T mapped_type; 1203e519524SHoward Hinnant typedef Hash hasher; 1213e519524SHoward Hinnant typedef Pred key_equal; 1223e519524SHoward Hinnant typedef Alloc allocator_type; 1233e519524SHoward Hinnant typedef pair<const key_type, mapped_type> value_type; 1243e519524SHoward Hinnant typedef value_type& reference; 1253e519524SHoward Hinnant typedef const value_type& const_reference; 1263e519524SHoward Hinnant typedef typename allocator_traits<allocator_type>::pointer pointer; 1273e519524SHoward Hinnant typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; 1283e519524SHoward Hinnant typedef typename allocator_traits<allocator_type>::size_type size_type; 1293e519524SHoward Hinnant typedef typename allocator_traits<allocator_type>::difference_type difference_type; 1303e519524SHoward Hinnant 1313e519524SHoward Hinnant typedef /unspecified/ iterator; 1323e519524SHoward Hinnant typedef /unspecified/ const_iterator; 1333e519524SHoward Hinnant 1343e519524SHoward Hinnant explicit hash_multimap(size_type n = 193, const hasher& hf = hasher(), 1353e519524SHoward Hinnant const key_equal& eql = key_equal(), 1363e519524SHoward Hinnant const allocator_type& a = allocator_type()); 1373e519524SHoward Hinnant template <class InputIterator> 1383e519524SHoward Hinnant hash_multimap(InputIterator f, InputIterator l, 1393e519524SHoward Hinnant size_type n = 193, const hasher& hf = hasher(), 1403e519524SHoward Hinnant const key_equal& eql = key_equal(), 1413e519524SHoward Hinnant const allocator_type& a = allocator_type()); 1423e519524SHoward Hinnant explicit hash_multimap(const allocator_type&); 1433e519524SHoward Hinnant hash_multimap(const hash_multimap&); 1443e519524SHoward Hinnant ~hash_multimap(); 1453e519524SHoward Hinnant hash_multimap& operator=(const hash_multimap&); 1463e519524SHoward Hinnant 1473e519524SHoward Hinnant allocator_type get_allocator() const; 1483e519524SHoward Hinnant 1493e519524SHoward Hinnant bool empty() const; 1503e519524SHoward Hinnant size_type size() const; 1513e519524SHoward Hinnant size_type max_size() const; 1523e519524SHoward Hinnant 1533e519524SHoward Hinnant iterator begin(); 1543e519524SHoward Hinnant iterator end(); 1553e519524SHoward Hinnant const_iterator begin() const; 1563e519524SHoward Hinnant const_iterator end() const; 1573e519524SHoward Hinnant 1583e519524SHoward Hinnant iterator insert(const value_type& obj); 1593e519524SHoward Hinnant template <class InputIterator> 1603e519524SHoward Hinnant void insert(InputIterator first, InputIterator last); 1613e519524SHoward Hinnant 1623e519524SHoward Hinnant void erase(const_iterator position); 1633e519524SHoward Hinnant size_type erase(const key_type& k); 1643e519524SHoward Hinnant void erase(const_iterator first, const_iterator last); 1653e519524SHoward Hinnant void clear(); 1663e519524SHoward Hinnant 1673e519524SHoward Hinnant void swap(hash_multimap&); 1683e519524SHoward Hinnant 1693e519524SHoward Hinnant hasher hash_funct() const; 1703e519524SHoward Hinnant key_equal key_eq() const; 1713e519524SHoward Hinnant 1723e519524SHoward Hinnant iterator find(const key_type& k); 1733e519524SHoward Hinnant const_iterator find(const key_type& k) const; 1743e519524SHoward Hinnant size_type count(const key_type& k) const; 1753e519524SHoward Hinnant pair<iterator, iterator> equal_range(const key_type& k); 1763e519524SHoward Hinnant pair<const_iterator, const_iterator> equal_range(const key_type& k) const; 1773e519524SHoward Hinnant 1783e519524SHoward Hinnant size_type bucket_count() const; 1793e519524SHoward Hinnant size_type max_bucket_count() const; 1803e519524SHoward Hinnant 1813e519524SHoward Hinnant size_type elems_in_bucket(size_type n) const; 1823e519524SHoward Hinnant 1833e519524SHoward Hinnant void resize(size_type n); 1843e519524SHoward Hinnant}; 1853e519524SHoward Hinnant 1863e519524SHoward Hinnanttemplate <class Key, class T, class Hash, class Pred, class Alloc> 1873e519524SHoward Hinnant void swap(hash_multimap<Key, T, Hash, Pred, Alloc>& x, 1883e519524SHoward Hinnant hash_multimap<Key, T, Hash, Pred, Alloc>& y); 1893e519524SHoward Hinnant 1903e519524SHoward Hinnanttemplate <class Key, class T, class Hash, class Pred, class Alloc> 1913e519524SHoward Hinnant bool 1923e519524SHoward Hinnant operator==(const hash_multimap<Key, T, Hash, Pred, Alloc>& x, 1933e519524SHoward Hinnant const hash_multimap<Key, T, Hash, Pred, Alloc>& y); 1943e519524SHoward Hinnant 1953e519524SHoward Hinnanttemplate <class Key, class T, class Hash, class Pred, class Alloc> 1963e519524SHoward Hinnant bool 1973e519524SHoward Hinnant operator!=(const hash_multimap<Key, T, Hash, Pred, Alloc>& x, 1983e519524SHoward Hinnant const hash_multimap<Key, T, Hash, Pred, Alloc>& y); 1993e519524SHoward Hinnant 2003e519524SHoward Hinnant} // __gnu_cxx 2013e519524SHoward Hinnant 2023e519524SHoward Hinnant*/ 2033e519524SHoward Hinnant 204385cc25aSLouis Dionne#include <__assert> // all public C++ headers provide the assertion handler 2053e519524SHoward Hinnant#include <__config> 2063e519524SHoward Hinnant#include <__hash_table> 207385cc25aSLouis Dionne#include <algorithm> 2084d81a46fSArthur O'Dwyer#include <ext/__hash> 20934f73804SNikolas Klauser#include <functional> 2103e519524SHoward Hinnant#include <stdexcept> 211ee187e24SEric Fiselier#include <type_traits> 2123e519524SHoward Hinnant 213de4a57cbSLouis Dionne#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES 214de4a57cbSLouis Dionne# include <iterator> 215de4a57cbSLouis Dionne#endif 216de4a57cbSLouis Dionne 2175c703f0fSMarek Kurdej#if defined(__DEPRECATED) && __DEPRECATED 2180c6e7ae4SEric Fiselier#if defined(_LIBCPP_WARNING) 21980b84d4cSHoward Hinnant _LIBCPP_WARNING("Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>") 22080b84d4cSHoward Hinnant#else 2213e519524SHoward Hinnant# warning Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map> 2221dba445eSHoward Hinnant#endif 22380b84d4cSHoward Hinnant#endif 2243e519524SHoward Hinnant 225ee187e24SEric Fiselier#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2263e519524SHoward Hinnant# pragma GCC system_header 227ee187e24SEric Fiselier#endif 2283e519524SHoward Hinnant 2293e519524SHoward Hinnantnamespace __gnu_cxx { 2303e519524SHoward Hinnant 231ee187e24SEric Fiseliertemplate <class _Tp, class _Hash, 232549ddae5SEric Fiselier bool = std::is_empty<_Hash>::value && !std::__libcpp_is_final<_Hash>::value 23342b8bb50SHoward Hinnant > 2343e519524SHoward Hinnantclass __hash_map_hasher 2353e519524SHoward Hinnant : private _Hash 2363e519524SHoward Hinnant{ 2373e519524SHoward Hinnantpublic: 238fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __hash_map_hasher() : _Hash() {} 239fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : _Hash(__h) {} 240fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const {return *this;} 241fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2423e519524SHoward Hinnant size_t operator()(const _Tp& __x) const 2433e519524SHoward Hinnant {return static_cast<const _Hash&>(*this)(__x.first);} 244fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2453e519524SHoward Hinnant size_t operator()(const typename _Tp::first_type& __x) const 2463e519524SHoward Hinnant {return static_cast<const _Hash&>(*this)(__x);} 2473e519524SHoward Hinnant}; 2483e519524SHoward Hinnant 2493e519524SHoward Hinnanttemplate <class _Tp, class _Hash> 2503e519524SHoward Hinnantclass __hash_map_hasher<_Tp, _Hash, false> 2513e519524SHoward Hinnant{ 2523e519524SHoward Hinnant _Hash __hash_; 2533e519524SHoward Hinnantpublic: 254fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __hash_map_hasher() : __hash_() {} 255fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __hash_map_hasher(const _Hash& __h) : __hash_(__h) {} 256fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY const _Hash& hash_function() const {return __hash_;} 257fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2583e519524SHoward Hinnant size_t operator()(const _Tp& __x) const 2593e519524SHoward Hinnant {return __hash_(__x.first);} 260fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2613e519524SHoward Hinnant size_t operator()(const typename _Tp::first_type& __x) const 2623e519524SHoward Hinnant {return __hash_(__x);} 2633e519524SHoward Hinnant}; 2643e519524SHoward Hinnant 265ee187e24SEric Fiseliertemplate <class _Tp, class _Pred, 266549ddae5SEric Fiselier bool = std::is_empty<_Pred>::value && !std::__libcpp_is_final<_Pred>::value 26742b8bb50SHoward Hinnant > 2683e519524SHoward Hinnantclass __hash_map_equal 2693e519524SHoward Hinnant : private _Pred 2703e519524SHoward Hinnant{ 2713e519524SHoward Hinnantpublic: 272fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __hash_map_equal() : _Pred() {} 273fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : _Pred(__p) {} 274fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const {return *this;} 275fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2763e519524SHoward Hinnant bool operator()(const _Tp& __x, const _Tp& __y) const 2773e519524SHoward Hinnant {return static_cast<const _Pred&>(*this)(__x.first, __y.first);} 278fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2793e519524SHoward Hinnant bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const 2803e519524SHoward Hinnant {return static_cast<const _Pred&>(*this)(__x, __y.first);} 281fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2823e519524SHoward Hinnant bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const 2833e519524SHoward Hinnant {return static_cast<const _Pred&>(*this)(__x.first, __y);} 284fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2853e519524SHoward Hinnant bool operator()(const typename _Tp::first_type& __x, 2863e519524SHoward Hinnant const typename _Tp::first_type& __y) const 2873e519524SHoward Hinnant {return static_cast<const _Pred&>(*this)(__x, __y);} 2883e519524SHoward Hinnant}; 2893e519524SHoward Hinnant 2903e519524SHoward Hinnanttemplate <class _Tp, class _Pred> 2913e519524SHoward Hinnantclass __hash_map_equal<_Tp, _Pred, false> 2923e519524SHoward Hinnant{ 2933e519524SHoward Hinnant _Pred __pred_; 2943e519524SHoward Hinnantpublic: 295fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __hash_map_equal() : __pred_() {} 296fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __hash_map_equal(const _Pred& __p) : __pred_(__p) {} 297fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY const _Pred& key_eq() const {return __pred_;} 298fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2993e519524SHoward Hinnant bool operator()(const _Tp& __x, const _Tp& __y) const 3003e519524SHoward Hinnant {return __pred_(__x.first, __y.first);} 301fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 3023e519524SHoward Hinnant bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const 3033e519524SHoward Hinnant {return __pred_(__x, __y.first);} 304fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 3053e519524SHoward Hinnant bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const 3063e519524SHoward Hinnant {return __pred_(__x.first, __y);} 307fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 3083e519524SHoward Hinnant bool operator()(const typename _Tp::first_type& __x, 3093e519524SHoward Hinnant const typename _Tp::first_type& __y) const 3103e519524SHoward Hinnant {return __pred_(__x, __y);} 3113e519524SHoward Hinnant}; 3123e519524SHoward Hinnant 3133e519524SHoward Hinnanttemplate <class _Alloc> 3143e519524SHoward Hinnantclass __hash_map_node_destructor 3153e519524SHoward Hinnant{ 3163e519524SHoward Hinnant typedef _Alloc allocator_type; 317549ddae5SEric Fiselier typedef std::allocator_traits<allocator_type> __alloc_traits; 31875d0dcfdSEric Fiselier typedef typename __alloc_traits::value_type::__node_value_type value_type; 3193e519524SHoward Hinnantpublic: 3203e519524SHoward Hinnant typedef typename __alloc_traits::pointer pointer; 3213e519524SHoward Hinnantprivate: 3223e519524SHoward Hinnant typedef typename value_type::first_type first_type; 3233e519524SHoward Hinnant typedef typename value_type::second_type second_type; 3243e519524SHoward Hinnant 3253e519524SHoward Hinnant allocator_type& __na_; 3263e519524SHoward Hinnant 3273e519524SHoward Hinnantpublic: 3283e519524SHoward Hinnant bool __first_constructed; 3293e519524SHoward Hinnant bool __second_constructed; 3303e519524SHoward Hinnant 331f97936faSEric Fiselier __hash_map_node_destructor(__hash_map_node_destructor const&) = default; 332f97936faSEric Fiselier __hash_map_node_destructor& operator=(const __hash_map_node_destructor&) = delete; 333f97936faSEric Fiselier 334fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 3353e519524SHoward Hinnant explicit __hash_map_node_destructor(allocator_type& __na) 3363e519524SHoward Hinnant : __na_(__na), 3373e519524SHoward Hinnant __first_constructed(false), 3383e519524SHoward Hinnant __second_constructed(false) 3393e519524SHoward Hinnant {} 3403e519524SHoward Hinnant 341afa7a957SEric Fiselier#ifndef _LIBCPP_CXX03_LANG 342fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 343549ddae5SEric Fiselier __hash_map_node_destructor(std::__hash_node_destructor<allocator_type>&& __x) 3443e519524SHoward Hinnant : __na_(__x.__na_), 3453e519524SHoward Hinnant __first_constructed(__x.__value_constructed), 3463e519524SHoward Hinnant __second_constructed(__x.__value_constructed) 3473e519524SHoward Hinnant { 3483e519524SHoward Hinnant __x.__value_constructed = false; 3493e519524SHoward Hinnant } 350afa7a957SEric Fiselier#else // _LIBCPP_CXX03_LANG 351fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 352236317d2SEric Fiselier __hash_map_node_destructor(const std::__hash_node_destructor<allocator_type>& __x) 3533e519524SHoward Hinnant : __na_(__x.__na_), 3543e519524SHoward Hinnant __first_constructed(__x.__value_constructed), 3553e519524SHoward Hinnant __second_constructed(__x.__value_constructed) 3563e519524SHoward Hinnant { 3573e519524SHoward Hinnant const_cast<bool&>(__x.__value_constructed) = false; 3583e519524SHoward Hinnant } 359afa7a957SEric Fiselier#endif // _LIBCPP_CXX03_LANG 3603e519524SHoward Hinnant 361fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 3623e519524SHoward Hinnant void operator()(pointer __p) 3633e519524SHoward Hinnant { 3643e519524SHoward Hinnant if (__second_constructed) 365ce48a113SHoward Hinnant __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second)); 3663e519524SHoward Hinnant if (__first_constructed) 367ce48a113SHoward Hinnant __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first)); 3683e519524SHoward Hinnant if (__p) 3693e519524SHoward Hinnant __alloc_traits::deallocate(__na_, __p, 1); 3703e519524SHoward Hinnant } 3713e519524SHoward Hinnant}; 3723e519524SHoward Hinnant 3733e519524SHoward Hinnanttemplate <class _HashIterator> 374e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS __hash_map_iterator 3753e519524SHoward Hinnant{ 3763e519524SHoward Hinnant _HashIterator __i_; 3773e519524SHoward Hinnant 3783e519524SHoward Hinnant typedef const typename _HashIterator::value_type::first_type key_type; 3793e519524SHoward Hinnant typedef typename _HashIterator::value_type::second_type mapped_type; 3803e519524SHoward Hinnantpublic: 381549ddae5SEric Fiselier typedef std::forward_iterator_tag iterator_category; 382549ddae5SEric Fiselier typedef std::pair<key_type, mapped_type> value_type; 3833e519524SHoward Hinnant typedef typename _HashIterator::difference_type difference_type; 3843e519524SHoward Hinnant typedef value_type& reference; 385549ddae5SEric Fiselier typedef typename std::__rebind_pointer<typename _HashIterator::pointer, value_type>::type 3863e519524SHoward Hinnant pointer; 3873e519524SHoward Hinnant 388fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __hash_map_iterator() {} 3893e519524SHoward Hinnant 390fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __hash_map_iterator(_HashIterator __i) : __i_(__i) {} 3913e519524SHoward Hinnant 392fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *operator->();} 393fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return (pointer)__i_.operator->();} 3943e519524SHoward Hinnant 395fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __hash_map_iterator& operator++() {++__i_; return *this;} 396fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 3973e519524SHoward Hinnant __hash_map_iterator operator++(int) 3983e519524SHoward Hinnant { 3993e519524SHoward Hinnant __hash_map_iterator __t(*this); 4003e519524SHoward Hinnant ++(*this); 4013e519524SHoward Hinnant return __t; 4023e519524SHoward Hinnant } 4033e519524SHoward Hinnant 404fb100021SHoward Hinnant friend _LIBCPP_INLINE_VISIBILITY 405fb100021SHoward Hinnant bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y) 4063e519524SHoward Hinnant {return __x.__i_ == __y.__i_;} 407fb100021SHoward Hinnant friend _LIBCPP_INLINE_VISIBILITY 408fb100021SHoward Hinnant bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y) 4093e519524SHoward Hinnant {return __x.__i_ != __y.__i_;} 4103e519524SHoward Hinnant 411e2f2d1edSEric Fiselier template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_map; 412e2f2d1edSEric Fiselier template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_multimap; 413e2f2d1edSEric Fiselier template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; 414e2f2d1edSEric Fiselier template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; 415e2f2d1edSEric Fiselier template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator; 4163e519524SHoward Hinnant}; 4173e519524SHoward Hinnant 4183e519524SHoward Hinnanttemplate <class _HashIterator> 419e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator 4203e519524SHoward Hinnant{ 4213e519524SHoward Hinnant _HashIterator __i_; 4223e519524SHoward Hinnant 4233e519524SHoward Hinnant typedef const typename _HashIterator::value_type::first_type key_type; 4243e519524SHoward Hinnant typedef typename _HashIterator::value_type::second_type mapped_type; 4253e519524SHoward Hinnantpublic: 426549ddae5SEric Fiselier typedef std::forward_iterator_tag iterator_category; 427549ddae5SEric Fiselier typedef std::pair<key_type, mapped_type> value_type; 4283e519524SHoward Hinnant typedef typename _HashIterator::difference_type difference_type; 4293e519524SHoward Hinnant typedef const value_type& reference; 430549ddae5SEric Fiselier typedef typename std::__rebind_pointer<typename _HashIterator::pointer, const value_type>::type 4313e519524SHoward Hinnant pointer; 4323e519524SHoward Hinnant 433fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator() {} 4343e519524SHoward Hinnant 435fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 4363e519524SHoward Hinnant __hash_map_const_iterator(_HashIterator __i) : __i_(__i) {} 437fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 4383e519524SHoward Hinnant __hash_map_const_iterator( 4393e519524SHoward Hinnant __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i) 4403e519524SHoward Hinnant : __i_(__i.__i_) {} 4413e519524SHoward Hinnant 442fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 4433e519524SHoward Hinnant reference operator*() const {return *operator->();} 444fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 4453e519524SHoward Hinnant pointer operator->() const {return (pointer)__i_.operator->();} 4463e519524SHoward Hinnant 447fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 4483e519524SHoward Hinnant __hash_map_const_iterator& operator++() {++__i_; return *this;} 449fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 4503e519524SHoward Hinnant __hash_map_const_iterator operator++(int) 4513e519524SHoward Hinnant { 4523e519524SHoward Hinnant __hash_map_const_iterator __t(*this); 4533e519524SHoward Hinnant ++(*this); 4543e519524SHoward Hinnant return __t; 4553e519524SHoward Hinnant } 4563e519524SHoward Hinnant 457fb100021SHoward Hinnant friend _LIBCPP_INLINE_VISIBILITY 458fb100021SHoward Hinnant bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) 4593e519524SHoward Hinnant {return __x.__i_ == __y.__i_;} 460fb100021SHoward Hinnant friend _LIBCPP_INLINE_VISIBILITY 461fb100021SHoward Hinnant bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y) 4623e519524SHoward Hinnant {return __x.__i_ != __y.__i_;} 4633e519524SHoward Hinnant 464e2f2d1edSEric Fiselier template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_map; 465e2f2d1edSEric Fiselier template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS hash_multimap; 466e2f2d1edSEric Fiselier template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator; 467e2f2d1edSEric Fiselier template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; 4683e519524SHoward Hinnant}; 4693e519524SHoward Hinnant 470549ddae5SEric Fiseliertemplate <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = std::equal_to<_Key>, 471549ddae5SEric Fiselier class _Alloc = std::allocator<std::pair<const _Key, _Tp> > > 472e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS hash_map 4733e519524SHoward Hinnant{ 4743e519524SHoward Hinnantpublic: 4753e519524SHoward Hinnant // types 4763e519524SHoward Hinnant typedef _Key key_type; 4773e519524SHoward Hinnant typedef _Tp mapped_type; 478fe473ae2SAlexis Hunt typedef _Tp data_type; 4793e519524SHoward Hinnant typedef _Hash hasher; 4803e519524SHoward Hinnant typedef _Pred key_equal; 4813e519524SHoward Hinnant typedef _Alloc allocator_type; 482549ddae5SEric Fiselier typedef std::pair<const key_type, mapped_type> value_type; 4833e519524SHoward Hinnant typedef value_type& reference; 4843e519524SHoward Hinnant typedef const value_type& const_reference; 4853e519524SHoward Hinnant 4863e519524SHoward Hinnantprivate: 487549ddae5SEric Fiselier typedef std::pair<key_type, mapped_type> __value_type; 4883e519524SHoward Hinnant typedef __hash_map_hasher<__value_type, hasher> __hasher; 4893e519524SHoward Hinnant typedef __hash_map_equal<__value_type, key_equal> __key_equal; 490549ddae5SEric Fiselier typedef typename std::__rebind_alloc_helper< 491549ddae5SEric Fiselier std::allocator_traits<allocator_type>, __value_type>::type __allocator_type; 4923e519524SHoward Hinnant 493549ddae5SEric Fiselier typedef std::__hash_table<__value_type, __hasher, 4943e519524SHoward Hinnant __key_equal, __allocator_type> __table; 4953e519524SHoward Hinnant 4963e519524SHoward Hinnant __table __table_; 4973e519524SHoward Hinnant 4983e519524SHoward Hinnant typedef typename __table::__node_pointer __node_pointer; 4993e519524SHoward Hinnant typedef typename __table::__node_const_pointer __node_const_pointer; 5003e519524SHoward Hinnant typedef typename __table::__node_traits __node_traits; 5013e519524SHoward Hinnant typedef typename __table::__node_allocator __node_allocator; 5023e519524SHoward Hinnant typedef typename __table::__node __node; 503c003db1fSHoward Hinnant typedef __hash_map_node_destructor<__node_allocator> _Dp; 504549ddae5SEric Fiselier typedef std::unique_ptr<__node, _Dp> __node_holder; 505549ddae5SEric Fiselier typedef std::allocator_traits<allocator_type> __alloc_traits; 5063e519524SHoward Hinnantpublic: 5073e519524SHoward Hinnant typedef typename __alloc_traits::pointer pointer; 5083e519524SHoward Hinnant typedef typename __alloc_traits::const_pointer const_pointer; 5093e519524SHoward Hinnant typedef typename __alloc_traits::size_type size_type; 5103e519524SHoward Hinnant typedef typename __alloc_traits::difference_type difference_type; 5113e519524SHoward Hinnant 5123e519524SHoward Hinnant typedef __hash_map_iterator<typename __table::iterator> iterator; 5133e519524SHoward Hinnant typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; 5143e519524SHoward Hinnant 5153eb5aec6SEric Fiselier _LIBCPP_INLINE_VISIBILITY hash_map() { } 5163e519524SHoward Hinnant explicit hash_map(size_type __n, const hasher& __hf = hasher(), 5173e519524SHoward Hinnant const key_equal& __eql = key_equal()); 5183e519524SHoward Hinnant hash_map(size_type __n, const hasher& __hf, 5193e519524SHoward Hinnant const key_equal& __eql, 5203e519524SHoward Hinnant const allocator_type& __a); 5213e519524SHoward Hinnant template <class _InputIterator> 5223e519524SHoward Hinnant hash_map(_InputIterator __first, _InputIterator __last); 5233e519524SHoward Hinnant template <class _InputIterator> 5243e519524SHoward Hinnant hash_map(_InputIterator __first, _InputIterator __last, 5253e519524SHoward Hinnant size_type __n, const hasher& __hf = hasher(), 5263e519524SHoward Hinnant const key_equal& __eql = key_equal()); 5273e519524SHoward Hinnant template <class _InputIterator> 5283e519524SHoward Hinnant hash_map(_InputIterator __first, _InputIterator __last, 5293e519524SHoward Hinnant size_type __n, const hasher& __hf, 5303e519524SHoward Hinnant const key_equal& __eql, 5313e519524SHoward Hinnant const allocator_type& __a); 5323e519524SHoward Hinnant hash_map(const hash_map& __u); 5333e519524SHoward Hinnant 534fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5353e519524SHoward Hinnant allocator_type get_allocator() const 5363e519524SHoward Hinnant {return allocator_type(__table_.__node_alloc());} 5373e519524SHoward Hinnant 538fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5393e519524SHoward Hinnant bool empty() const {return __table_.size() == 0;} 540fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5413e519524SHoward Hinnant size_type size() const {return __table_.size();} 542fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5433e519524SHoward Hinnant size_type max_size() const {return __table_.max_size();} 5443e519524SHoward Hinnant 545fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5463e519524SHoward Hinnant iterator begin() {return __table_.begin();} 547fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5483e519524SHoward Hinnant iterator end() {return __table_.end();} 549fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5503e519524SHoward Hinnant const_iterator begin() const {return __table_.begin();} 551fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5523e519524SHoward Hinnant const_iterator end() const {return __table_.end();} 5533e519524SHoward Hinnant 554fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 555549ddae5SEric Fiselier std::pair<iterator, bool> insert(const value_type& __x) 5563e519524SHoward Hinnant {return __table_.__insert_unique(__x);} 557fe473ae2SAlexis Hunt _LIBCPP_INLINE_VISIBILITY 558fe473ae2SAlexis Hunt iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} 5593e519524SHoward Hinnant template <class _InputIterator> 560cd31b434SEvgeniy Stepanov _LIBCPP_INLINE_VISIBILITY 5613e519524SHoward Hinnant void insert(_InputIterator __first, _InputIterator __last); 5623e519524SHoward Hinnant 563fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5643e519524SHoward Hinnant void erase(const_iterator __p) {__table_.erase(__p.__i_);} 565fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5663e519524SHoward Hinnant size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} 567fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5683e519524SHoward Hinnant void erase(const_iterator __first, const_iterator __last) 5693e519524SHoward Hinnant {__table_.erase(__first.__i_, __last.__i_);} 570fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5713e519524SHoward Hinnant void clear() {__table_.clear();} 5723e519524SHoward Hinnant 573fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5743e519524SHoward Hinnant void swap(hash_map& __u) {__table_.swap(__u.__table_);} 5753e519524SHoward Hinnant 576fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5773e519524SHoward Hinnant hasher hash_funct() const 5783e519524SHoward Hinnant {return __table_.hash_function().hash_function();} 579fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5803e519524SHoward Hinnant key_equal key_eq() const 5813e519524SHoward Hinnant {return __table_.key_eq().key_eq();} 5823e519524SHoward Hinnant 583fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5843e519524SHoward Hinnant iterator find(const key_type& __k) {return __table_.find(__k);} 585fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5863e519524SHoward Hinnant const_iterator find(const key_type& __k) const {return __table_.find(__k);} 587fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5883e519524SHoward Hinnant size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} 589fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 590549ddae5SEric Fiselier std::pair<iterator, iterator> equal_range(const key_type& __k) 5913e519524SHoward Hinnant {return __table_.__equal_range_unique(__k);} 592fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 593549ddae5SEric Fiselier std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const 5943e519524SHoward Hinnant {return __table_.__equal_range_unique(__k);} 5953e519524SHoward Hinnant 5963e519524SHoward Hinnant mapped_type& operator[](const key_type& __k); 5973e519524SHoward Hinnant 598fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 5993e519524SHoward Hinnant size_type bucket_count() const {return __table_.bucket_count();} 600fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 6013e519524SHoward Hinnant size_type max_bucket_count() const {return __table_.max_bucket_count();} 6023e519524SHoward Hinnant 603fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 6043e519524SHoward Hinnant size_type elems_in_bucket(size_type __n) const 6053e519524SHoward Hinnant {return __table_.bucket_size(__n);} 6063e519524SHoward Hinnant 607fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 608*3085e42fSIvan Trofimov void resize(size_type __n) {__table_.__rehash_unique(__n);} 6093e519524SHoward Hinnant 6103e519524SHoward Hinnantprivate: 6113e519524SHoward Hinnant __node_holder __construct_node(const key_type& __k); 6123e519524SHoward Hinnant}; 6133e519524SHoward Hinnant 6143e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 6153e519524SHoward Hinnanthash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( 6163e519524SHoward Hinnant size_type __n, const hasher& __hf, const key_equal& __eql) 6173e519524SHoward Hinnant : __table_(__hf, __eql) 6183e519524SHoward Hinnant{ 619*3085e42fSIvan Trofimov __table_.__rehash_unique(__n); 6203e519524SHoward Hinnant} 6213e519524SHoward Hinnant 6223e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 6233e519524SHoward Hinnanthash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( 6243e519524SHoward Hinnant size_type __n, const hasher& __hf, const key_equal& __eql, 6253e519524SHoward Hinnant const allocator_type& __a) 6263e519524SHoward Hinnant : __table_(__hf, __eql, __a) 6273e519524SHoward Hinnant{ 628*3085e42fSIvan Trofimov __table_.__rehash_unique(__n); 6293e519524SHoward Hinnant} 6303e519524SHoward Hinnant 6313e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 6323e519524SHoward Hinnanttemplate <class _InputIterator> 6333e519524SHoward Hinnanthash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( 6343e519524SHoward Hinnant _InputIterator __first, _InputIterator __last) 6353e519524SHoward Hinnant{ 6363e519524SHoward Hinnant insert(__first, __last); 6373e519524SHoward Hinnant} 6383e519524SHoward Hinnant 6393e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 6403e519524SHoward Hinnanttemplate <class _InputIterator> 6413e519524SHoward Hinnanthash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( 6423e519524SHoward Hinnant _InputIterator __first, _InputIterator __last, size_type __n, 6433e519524SHoward Hinnant const hasher& __hf, const key_equal& __eql) 6443e519524SHoward Hinnant : __table_(__hf, __eql) 6453e519524SHoward Hinnant{ 646*3085e42fSIvan Trofimov __table_.__rehash_unique(__n); 6473e519524SHoward Hinnant insert(__first, __last); 6483e519524SHoward Hinnant} 6493e519524SHoward Hinnant 6503e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 6513e519524SHoward Hinnanttemplate <class _InputIterator> 6523e519524SHoward Hinnanthash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( 6533e519524SHoward Hinnant _InputIterator __first, _InputIterator __last, size_type __n, 6543e519524SHoward Hinnant const hasher& __hf, const key_equal& __eql, const allocator_type& __a) 6553e519524SHoward Hinnant : __table_(__hf, __eql, __a) 6563e519524SHoward Hinnant{ 657*3085e42fSIvan Trofimov __table_.__rehash_unique(__n); 6583e519524SHoward Hinnant insert(__first, __last); 6593e519524SHoward Hinnant} 6603e519524SHoward Hinnant 6613e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 6623e519524SHoward Hinnanthash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_map( 6633e519524SHoward Hinnant const hash_map& __u) 6643e519524SHoward Hinnant : __table_(__u.__table_) 6653e519524SHoward Hinnant{ 666*3085e42fSIvan Trofimov __table_.__rehash_unique(__u.bucket_count()); 6673e519524SHoward Hinnant insert(__u.begin(), __u.end()); 6683e519524SHoward Hinnant} 6693e519524SHoward Hinnant 6703e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 6713e519524SHoward Hinnanttypename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder 6723e519524SHoward Hinnanthash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k) 6733e519524SHoward Hinnant{ 6743e519524SHoward Hinnant __node_allocator& __na = __table_.__node_alloc(); 675c003db1fSHoward Hinnant __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); 676ce48a113SHoward Hinnant __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k); 6773e519524SHoward Hinnant __h.get_deleter().__first_constructed = true; 678ce48a113SHoward Hinnant __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); 6793e519524SHoward Hinnant __h.get_deleter().__second_constructed = true; 6808d4860aaSLouis Dionne return __h; 6813e519524SHoward Hinnant} 6823e519524SHoward Hinnant 6833e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 6843e519524SHoward Hinnanttemplate <class _InputIterator> 685cd31b434SEvgeniy Stepanovinline 6863e519524SHoward Hinnantvoid 6873e519524SHoward Hinnanthash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, 6883e519524SHoward Hinnant _InputIterator __last) 6893e519524SHoward Hinnant{ 6903e519524SHoward Hinnant for (; __first != __last; ++__first) 6913e519524SHoward Hinnant __table_.__insert_unique(*__first); 6923e519524SHoward Hinnant} 6933e519524SHoward Hinnant 6943e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 6953e519524SHoward Hinnant_Tp& 6963e519524SHoward Hinnanthash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) 6973e519524SHoward Hinnant{ 6983e519524SHoward Hinnant iterator __i = find(__k); 6993e519524SHoward Hinnant if (__i != end()) 7003e519524SHoward Hinnant return __i->second; 7013e519524SHoward Hinnant __node_holder __h = __construct_node(__k); 702549ddae5SEric Fiselier std::pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); 7033e519524SHoward Hinnant __h.release(); 7043e519524SHoward Hinnant return __r.first->second; 7053e519524SHoward Hinnant} 7063e519524SHoward Hinnant 7073e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 708fb100021SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 7093e519524SHoward Hinnantvoid 7103e519524SHoward Hinnantswap(hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, 7113e519524SHoward Hinnant hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) 7123e519524SHoward Hinnant{ 7133e519524SHoward Hinnant __x.swap(__y); 7143e519524SHoward Hinnant} 7153e519524SHoward Hinnant 7163e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 7173e519524SHoward Hinnantbool 7183e519524SHoward Hinnantoperator==(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, 7193e519524SHoward Hinnant const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) 7203e519524SHoward Hinnant{ 7213e519524SHoward Hinnant if (__x.size() != __y.size()) 7223e519524SHoward Hinnant return false; 7233e519524SHoward Hinnant typedef typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator 7243e519524SHoward Hinnant const_iterator; 7253e519524SHoward Hinnant for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end(); 7263e519524SHoward Hinnant __i != __ex; ++__i) 7273e519524SHoward Hinnant { 7283e519524SHoward Hinnant const_iterator __j = __y.find(__i->first); 7293e519524SHoward Hinnant if (__j == __ey || !(*__i == *__j)) 7303e519524SHoward Hinnant return false; 7313e519524SHoward Hinnant } 7323e519524SHoward Hinnant return true; 7333e519524SHoward Hinnant} 7343e519524SHoward Hinnant 7353e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 736fb100021SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 7373e519524SHoward Hinnantbool 7383e519524SHoward Hinnantoperator!=(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, 7393e519524SHoward Hinnant const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) 7403e519524SHoward Hinnant{ 7413e519524SHoward Hinnant return !(__x == __y); 7423e519524SHoward Hinnant} 7433e519524SHoward Hinnant 744549ddae5SEric Fiseliertemplate <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = std::equal_to<_Key>, 745549ddae5SEric Fiselier class _Alloc = std::allocator<std::pair<const _Key, _Tp> > > 746e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS hash_multimap 7473e519524SHoward Hinnant{ 7483e519524SHoward Hinnantpublic: 7493e519524SHoward Hinnant // types 7503e519524SHoward Hinnant typedef _Key key_type; 7513e519524SHoward Hinnant typedef _Tp mapped_type; 752fe473ae2SAlexis Hunt typedef _Tp data_type; 7533e519524SHoward Hinnant typedef _Hash hasher; 7543e519524SHoward Hinnant typedef _Pred key_equal; 7553e519524SHoward Hinnant typedef _Alloc allocator_type; 756549ddae5SEric Fiselier typedef std::pair<const key_type, mapped_type> value_type; 7573e519524SHoward Hinnant typedef value_type& reference; 7583e519524SHoward Hinnant typedef const value_type& const_reference; 7593e519524SHoward Hinnant 7603e519524SHoward Hinnantprivate: 761549ddae5SEric Fiselier typedef std::pair<key_type, mapped_type> __value_type; 7623e519524SHoward Hinnant typedef __hash_map_hasher<__value_type, hasher> __hasher; 7633e519524SHoward Hinnant typedef __hash_map_equal<__value_type, key_equal> __key_equal; 764549ddae5SEric Fiselier typedef typename std::__rebind_alloc_helper<std::allocator_traits<allocator_type>, __value_type>::type __allocator_type; 7653e519524SHoward Hinnant 766549ddae5SEric Fiselier typedef std::__hash_table<__value_type, __hasher, 7673e519524SHoward Hinnant __key_equal, __allocator_type> __table; 7683e519524SHoward Hinnant 7693e519524SHoward Hinnant __table __table_; 7703e519524SHoward Hinnant 7713e519524SHoward Hinnant typedef typename __table::__node_traits __node_traits; 7723e519524SHoward Hinnant typedef typename __table::__node_allocator __node_allocator; 7733e519524SHoward Hinnant typedef typename __table::__node __node; 774c003db1fSHoward Hinnant typedef __hash_map_node_destructor<__node_allocator> _Dp; 775549ddae5SEric Fiselier typedef std::unique_ptr<__node, _Dp> __node_holder; 776549ddae5SEric Fiselier typedef std::allocator_traits<allocator_type> __alloc_traits; 7773e519524SHoward Hinnantpublic: 7783e519524SHoward Hinnant typedef typename __alloc_traits::pointer pointer; 7793e519524SHoward Hinnant typedef typename __alloc_traits::const_pointer const_pointer; 7803e519524SHoward Hinnant typedef typename __alloc_traits::size_type size_type; 7813e519524SHoward Hinnant typedef typename __alloc_traits::difference_type difference_type; 7823e519524SHoward Hinnant 7833e519524SHoward Hinnant typedef __hash_map_iterator<typename __table::iterator> iterator; 7843e519524SHoward Hinnant typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator; 7853e519524SHoward Hinnant 786fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 7873eb5aec6SEric Fiselier hash_multimap() { } 7883e519524SHoward Hinnant explicit hash_multimap(size_type __n, const hasher& __hf = hasher(), 7893e519524SHoward Hinnant const key_equal& __eql = key_equal()); 7903e519524SHoward Hinnant hash_multimap(size_type __n, const hasher& __hf, 7913e519524SHoward Hinnant const key_equal& __eql, 7923e519524SHoward Hinnant const allocator_type& __a); 7933e519524SHoward Hinnant template <class _InputIterator> 7943e519524SHoward Hinnant hash_multimap(_InputIterator __first, _InputIterator __last); 7953e519524SHoward Hinnant template <class _InputIterator> 7963e519524SHoward Hinnant hash_multimap(_InputIterator __first, _InputIterator __last, 7973e519524SHoward Hinnant size_type __n, const hasher& __hf = hasher(), 7983e519524SHoward Hinnant const key_equal& __eql = key_equal()); 7993e519524SHoward Hinnant template <class _InputIterator> 8003e519524SHoward Hinnant hash_multimap(_InputIterator __first, _InputIterator __last, 8013e519524SHoward Hinnant size_type __n, const hasher& __hf, 8023e519524SHoward Hinnant const key_equal& __eql, 8033e519524SHoward Hinnant const allocator_type& __a); 8043e519524SHoward Hinnant hash_multimap(const hash_multimap& __u); 8053e519524SHoward Hinnant 806fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8073e519524SHoward Hinnant allocator_type get_allocator() const 8083e519524SHoward Hinnant {return allocator_type(__table_.__node_alloc());} 8093e519524SHoward Hinnant 810fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8113e519524SHoward Hinnant bool empty() const {return __table_.size() == 0;} 812fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8133e519524SHoward Hinnant size_type size() const {return __table_.size();} 814fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8153e519524SHoward Hinnant size_type max_size() const {return __table_.max_size();} 8163e519524SHoward Hinnant 817fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8183e519524SHoward Hinnant iterator begin() {return __table_.begin();} 819fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8203e519524SHoward Hinnant iterator end() {return __table_.end();} 821fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8223e519524SHoward Hinnant const_iterator begin() const {return __table_.begin();} 823fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8243e519524SHoward Hinnant const_iterator end() const {return __table_.end();} 8253e519524SHoward Hinnant 826fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8273e519524SHoward Hinnant iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);} 828fe473ae2SAlexis Hunt _LIBCPP_INLINE_VISIBILITY 829fe473ae2SAlexis Hunt iterator insert(const_iterator, const value_type& __x) {return insert(__x);} 8303e519524SHoward Hinnant template <class _InputIterator> 831cd31b434SEvgeniy Stepanov _LIBCPP_INLINE_VISIBILITY 8323e519524SHoward Hinnant void insert(_InputIterator __first, _InputIterator __last); 8333e519524SHoward Hinnant 834fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8353e519524SHoward Hinnant void erase(const_iterator __p) {__table_.erase(__p.__i_);} 836fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8373e519524SHoward Hinnant size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} 838fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8393e519524SHoward Hinnant void erase(const_iterator __first, const_iterator __last) 8403e519524SHoward Hinnant {__table_.erase(__first.__i_, __last.__i_);} 841fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8423e519524SHoward Hinnant void clear() {__table_.clear();} 8433e519524SHoward Hinnant 844fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8453e519524SHoward Hinnant void swap(hash_multimap& __u) {__table_.swap(__u.__table_);} 8463e519524SHoward Hinnant 847fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8483e519524SHoward Hinnant hasher hash_funct() const 8493e519524SHoward Hinnant {return __table_.hash_function().hash_function();} 850fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8513e519524SHoward Hinnant key_equal key_eq() const 8523e519524SHoward Hinnant {return __table_.key_eq().key_eq();} 8533e519524SHoward Hinnant 854fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8553e519524SHoward Hinnant iterator find(const key_type& __k) {return __table_.find(__k);} 856fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8573e519524SHoward Hinnant const_iterator find(const key_type& __k) const {return __table_.find(__k);} 858fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8593e519524SHoward Hinnant size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} 860fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 861549ddae5SEric Fiselier std::pair<iterator, iterator> equal_range(const key_type& __k) 8623e519524SHoward Hinnant {return __table_.__equal_range_multi(__k);} 863fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 864549ddae5SEric Fiselier std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const 8653e519524SHoward Hinnant {return __table_.__equal_range_multi(__k);} 8663e519524SHoward Hinnant 867fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8683e519524SHoward Hinnant size_type bucket_count() const {return __table_.bucket_count();} 869fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8703e519524SHoward Hinnant size_type max_bucket_count() const {return __table_.max_bucket_count();} 8713e519524SHoward Hinnant 872fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 8733e519524SHoward Hinnant size_type elems_in_bucket(size_type __n) const 8743e519524SHoward Hinnant {return __table_.bucket_size(__n);} 8753e519524SHoward Hinnant 876fb100021SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 877*3085e42fSIvan Trofimov void resize(size_type __n) {__table_.__rehash_multi(__n);} 8783e519524SHoward Hinnant}; 8793e519524SHoward Hinnant 8803e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 8813e519524SHoward Hinnanthash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( 8823e519524SHoward Hinnant size_type __n, const hasher& __hf, const key_equal& __eql) 8833e519524SHoward Hinnant : __table_(__hf, __eql) 8843e519524SHoward Hinnant{ 885*3085e42fSIvan Trofimov __table_.__rehash_multi(__n); 8863e519524SHoward Hinnant} 8873e519524SHoward Hinnant 8883e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 8893e519524SHoward Hinnanthash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( 8903e519524SHoward Hinnant size_type __n, const hasher& __hf, const key_equal& __eql, 8913e519524SHoward Hinnant const allocator_type& __a) 8923e519524SHoward Hinnant : __table_(__hf, __eql, __a) 8933e519524SHoward Hinnant{ 894*3085e42fSIvan Trofimov __table_.__rehash_multi(__n); 8953e519524SHoward Hinnant} 8963e519524SHoward Hinnant 8973e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 8983e519524SHoward Hinnanttemplate <class _InputIterator> 8993e519524SHoward Hinnanthash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( 9003e519524SHoward Hinnant _InputIterator __first, _InputIterator __last) 9013e519524SHoward Hinnant{ 9023e519524SHoward Hinnant insert(__first, __last); 9033e519524SHoward Hinnant} 9043e519524SHoward Hinnant 9053e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 9063e519524SHoward Hinnanttemplate <class _InputIterator> 9073e519524SHoward Hinnanthash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( 9083e519524SHoward Hinnant _InputIterator __first, _InputIterator __last, size_type __n, 9093e519524SHoward Hinnant const hasher& __hf, const key_equal& __eql) 9103e519524SHoward Hinnant : __table_(__hf, __eql) 9113e519524SHoward Hinnant{ 912*3085e42fSIvan Trofimov __table_.__rehash_multi(__n); 9133e519524SHoward Hinnant insert(__first, __last); 9143e519524SHoward Hinnant} 9153e519524SHoward Hinnant 9163e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 9173e519524SHoward Hinnanttemplate <class _InputIterator> 9183e519524SHoward Hinnanthash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( 9193e519524SHoward Hinnant _InputIterator __first, _InputIterator __last, size_type __n, 9203e519524SHoward Hinnant const hasher& __hf, const key_equal& __eql, const allocator_type& __a) 9213e519524SHoward Hinnant : __table_(__hf, __eql, __a) 9223e519524SHoward Hinnant{ 923*3085e42fSIvan Trofimov __table_.__rehash_multi(__n); 9243e519524SHoward Hinnant insert(__first, __last); 9253e519524SHoward Hinnant} 9263e519524SHoward Hinnant 9273e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 9283e519524SHoward Hinnanthash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap( 9293e519524SHoward Hinnant const hash_multimap& __u) 9303e519524SHoward Hinnant : __table_(__u.__table_) 9313e519524SHoward Hinnant{ 932*3085e42fSIvan Trofimov __table_.__rehash_multi(__u.bucket_count()); 9333e519524SHoward Hinnant insert(__u.begin(), __u.end()); 9343e519524SHoward Hinnant} 9353e519524SHoward Hinnant 9363e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 9373e519524SHoward Hinnanttemplate <class _InputIterator> 938cd31b434SEvgeniy Stepanovinline 9393e519524SHoward Hinnantvoid 9403e519524SHoward Hinnanthash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, 9413e519524SHoward Hinnant _InputIterator __last) 9423e519524SHoward Hinnant{ 9433e519524SHoward Hinnant for (; __first != __last; ++__first) 9443e519524SHoward Hinnant __table_.__insert_multi(*__first); 9453e519524SHoward Hinnant} 9463e519524SHoward Hinnant 9473e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 948fb100021SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 9493e519524SHoward Hinnantvoid 9503e519524SHoward Hinnantswap(hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, 9513e519524SHoward Hinnant hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) 9523e519524SHoward Hinnant{ 9533e519524SHoward Hinnant __x.swap(__y); 9543e519524SHoward Hinnant} 9553e519524SHoward Hinnant 9563e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 9573e519524SHoward Hinnantbool 9583e519524SHoward Hinnantoperator==(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, 9593e519524SHoward Hinnant const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) 9603e519524SHoward Hinnant{ 9613e519524SHoward Hinnant if (__x.size() != __y.size()) 9623e519524SHoward Hinnant return false; 9633e519524SHoward Hinnant typedef typename hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator 9643e519524SHoward Hinnant const_iterator; 965549ddae5SEric Fiselier typedef std::pair<const_iterator, const_iterator> _EqRng; 9663e519524SHoward Hinnant for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) 9673e519524SHoward Hinnant { 9683e519524SHoward Hinnant _EqRng __xeq = __x.equal_range(__i->first); 9693e519524SHoward Hinnant _EqRng __yeq = __y.equal_range(__i->first); 970ce48a113SHoward Hinnant if (_VSTD::distance(__xeq.first, __xeq.second) != 971ce48a113SHoward Hinnant _VSTD::distance(__yeq.first, __yeq.second) || 972ce48a113SHoward Hinnant !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first)) 9733e519524SHoward Hinnant return false; 9743e519524SHoward Hinnant __i = __xeq.second; 9753e519524SHoward Hinnant } 9763e519524SHoward Hinnant return true; 9773e519524SHoward Hinnant} 9783e519524SHoward Hinnant 9793e519524SHoward Hinnanttemplate <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> 980fb100021SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 9813e519524SHoward Hinnantbool 9823e519524SHoward Hinnantoperator!=(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, 9833e519524SHoward Hinnant const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) 9843e519524SHoward Hinnant{ 9853e519524SHoward Hinnant return !(__x == __y); 9863e519524SHoward Hinnant} 9873e519524SHoward Hinnant 988d2b0df35SNikolas Klauser} // namespace __gnu_cxx 9893e519524SHoward Hinnant 9903e519524SHoward Hinnant#endif // _LIBCPP_HASH_MAP 991