30 #ifndef _UNORDERED_MAP_H
31 #define _UNORDERED_MAP_H
35 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
39 using __umap_traits = __detail::_Hashtable_traits<_Cache, false, true>;
41 template<
typename _Key,
43 typename _Hash = hash<_Key>,
44 typename _Pred = std::equal_to<_Key>,
45 typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
46 typename _Tr = __umap_traits<__cache_default<_Key, _Hash>::value>>
47 using __umap_hashtable = _Hashtable<_Key, std::pair<const _Key, _Tp>,
48 _Alloc, __detail::_Select1st,
50 __detail::_Mod_range_hashing,
51 __detail::_Default_ranged_hash,
52 __detail::_Prime_rehash_policy, _Tr>;
56 using __ummap_traits = __detail::_Hashtable_traits<_Cache, false, false>;
58 template<
typename _Key,
60 typename _Hash = hash<_Key>,
61 typename _Pred = std::equal_to<_Key>,
62 typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
63 typename _Tr = __ummap_traits<__cache_default<_Key, _Hash>::value>>
64 using __ummap_hashtable = _Hashtable<_Key, std::pair<const _Key, _Tp>,
65 _Alloc, __detail::_Select1st,
67 __detail::_Mod_range_hashing,
68 __detail::_Default_ranged_hash,
69 __detail::_Prime_rehash_policy, _Tr>;
93 template<
class _Key,
class _Tp,
94 class _Hash = hash<_Key>,
95 class _Pred = std::equal_to<_Key>,
96 class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
97 class unordered_map : __check_copy_constructible<_Alloc>
99 typedef __umap_hashtable<_Key, _Tp, _Hash, _Pred, _Alloc> _Hashtable;
105 typedef typename _Hashtable::key_type key_type;
107 typedef typename _Hashtable::value_type value_type;
108 typedef typename _Hashtable::mapped_type mapped_type;
109 typedef typename _Hashtable::hasher hasher;
110 typedef typename _Hashtable::key_equal key_equal;
111 typedef typename _Hashtable::allocator_type allocator_type;
115 typedef typename allocator_type::pointer pointer;
117 typedef typename allocator_type::const_pointer const_pointer;
118 typedef typename allocator_type::reference reference;
119 typedef typename allocator_type::const_reference const_reference;
120 typedef typename _Hashtable::iterator iterator;
121 typedef typename _Hashtable::const_iterator const_iterator;
122 typedef typename _Hashtable::local_iterator local_iterator;
123 typedef typename _Hashtable::const_local_iterator const_local_iterator;
124 typedef typename _Hashtable::size_type size_type;
125 typedef typename _Hashtable::difference_type difference_type;
138 unordered_map(size_type __n = 10,
139 const hasher& __hf = hasher(),
140 const key_equal& __eql = key_equal(),
141 const allocator_type& __a = allocator_type())
142 : _M_h(__n, __hf, __eql, __a)
158 template<
typename _InputIterator>
159 unordered_map(_InputIterator __f, _InputIterator __l,
161 const hasher& __hf = hasher(),
162 const key_equal& __eql = key_equal(),
163 const allocator_type& __a = allocator_type())
164 : _M_h(__f, __l, __n, __hf, __eql, __a)
168 unordered_map(
const unordered_map&) =
default;
171 unordered_map(unordered_map&&) =
default;
184 unordered_map(initializer_list<value_type> __l,
186 const hasher& __hf = hasher(),
187 const key_equal& __eql = key_equal(),
188 const allocator_type& __a = allocator_type())
189 : _M_h(__l, __n, __hf, __eql, __a)
194 operator=(
const unordered_map&) =
default;
198 operator=(unordered_map&&) =
default;
212 operator=(initializer_list<value_type> __l)
221 get_allocator()
const noexcept
222 {
return _M_h.get_allocator(); }
228 empty()
const noexcept
229 {
return _M_h.empty(); }
233 size()
const noexcept
234 {
return _M_h.size(); }
238 max_size()
const noexcept
239 {
return _M_h.max_size(); }
249 {
return _M_h.begin(); }
257 begin()
const noexcept
258 {
return _M_h.begin(); }
261 cbegin()
const noexcept
262 {
return _M_h.begin(); }
271 {
return _M_h.end(); }
280 {
return _M_h.end(); }
283 cend()
const noexcept
284 {
return _M_h.end(); }
308 template<
typename... _Args>
309 std::pair<iterator, bool>
310 emplace(_Args&&... __args)
311 {
return _M_h.emplace(std::forward<_Args>(__args)...); }
338 template<
typename... _Args>
340 emplace_hint(const_iterator __pos, _Args&&... __args)
341 {
return _M_h.emplace_hint(__pos, std::forward<_Args>(__args)...); }
361 std::pair<iterator, bool>
362 insert(
const value_type& __x)
363 {
return _M_h.insert(__x); }
365 template<
typename _Pair,
typename =
typename
366 std::enable_if<std::is_constructible<value_type,
367 _Pair&&>::value>::type>
368 std::pair<iterator, bool>
370 {
return _M_h.insert(std::forward<_Pair>(__x)); }
396 insert(const_iterator __hint,
const value_type& __x)
397 {
return _M_h.insert(__hint, __x); }
399 template<
typename _Pair,
typename =
typename
400 std::enable_if<std::is_constructible<value_type,
401 _Pair&&>::value>::type>
403 insert(const_iterator __hint, _Pair&& __x)
404 {
return _M_h.insert(__hint, std::forward<_Pair>(__x)); }
416 template<
typename _InputIterator>
418 insert(_InputIterator __first, _InputIterator __last)
419 { _M_h.insert(__first, __last); }
429 insert(initializer_list<value_type> __l)
430 { _M_h.insert(__l); }
447 erase(const_iterator __position)
448 {
return _M_h.erase(__position); }
453 {
return _M_h.erase(__it); }
469 erase(
const key_type& __x)
470 {
return _M_h.erase(__x); }
487 erase(const_iterator __first, const_iterator __last)
488 {
return _M_h.erase(__first, __last); }
510 swap(unordered_map& __x)
511 { _M_h.swap(__x._M_h); }
518 hash_function()
const
519 {
return _M_h.hash_function(); }
525 {
return _M_h.key_eq(); }
542 find(
const key_type& __x)
543 {
return _M_h.find(__x); }
546 find(
const key_type& __x)
const
547 {
return _M_h.find(__x); }
560 count(
const key_type& __x)
const
561 {
return _M_h.count(__x); }
572 std::pair<iterator, iterator>
573 equal_range(
const key_type& __x)
574 {
return _M_h.equal_range(__x); }
576 std::pair<const_iterator, const_iterator>
577 equal_range(
const key_type& __x)
const
578 {
return _M_h.equal_range(__x); }
595 operator[](
const key_type& __k)
596 {
return _M_h[__k]; }
599 operator[](key_type&& __k)
600 {
return _M_h[std::move(__k)]; }
612 at(
const key_type& __k)
613 {
return _M_h.at(__k); }
616 at(
const key_type& __k)
const
617 {
return _M_h.at(__k); }
624 bucket_count()
const noexcept
625 {
return _M_h.bucket_count(); }
629 max_bucket_count()
const noexcept
630 {
return _M_h.max_bucket_count(); }
638 bucket_size(size_type __n)
const
639 {
return _M_h.bucket_size(__n); }
647 bucket(
const key_type& __key)
const
648 {
return _M_h.bucket(__key); }
658 {
return _M_h.begin(__n); }
668 begin(size_type __n)
const
669 {
return _M_h.begin(__n); }
672 cbegin(size_type __n)
const
673 {
return _M_h.cbegin(__n); }
684 {
return _M_h.end(__n); }
694 end(size_type __n)
const
695 {
return _M_h.end(__n); }
698 cend(size_type __n)
const
699 {
return _M_h.cend(__n); }
706 load_factor()
const noexcept
707 {
return _M_h.load_factor(); }
712 max_load_factor()
const noexcept
713 {
return _M_h.max_load_factor(); }
720 max_load_factor(
float __z)
721 { _M_h.max_load_factor(__z); }
731 rehash(size_type __n)
732 { _M_h.rehash(__n); }
742 reserve(size_type __n)
743 { _M_h.reserve(__n); }
745 template<
typename _Key1,
typename _Tp1,
typename _Hash1,
typename _Pred1,
748 operator==(
const unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&,
749 const unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&);
774 template<
class _Key,
class _Tp,
775 class _Hash = hash<_Key>,
776 class _Pred = std::equal_to<_Key>,
777 class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
778 class unordered_multimap : __check_copy_constructible<_Alloc>
780 typedef __ummap_hashtable<_Key, _Tp, _Hash, _Pred, _Alloc> _Hashtable;
786 typedef typename _Hashtable::key_type key_type;
788 typedef typename _Hashtable::value_type value_type;
789 typedef typename _Hashtable::mapped_type mapped_type;
790 typedef typename _Hashtable::hasher hasher;
791 typedef typename _Hashtable::key_equal key_equal;
792 typedef typename _Hashtable::allocator_type allocator_type;
796 typedef typename allocator_type::pointer pointer;
798 typedef typename allocator_type::const_pointer const_pointer;
799 typedef typename allocator_type::reference reference;
800 typedef typename allocator_type::const_reference const_reference;
801 typedef typename _Hashtable::iterator iterator;
802 typedef typename _Hashtable::const_iterator const_iterator;
803 typedef typename _Hashtable::local_iterator local_iterator;
804 typedef typename _Hashtable::const_local_iterator const_local_iterator;
805 typedef typename _Hashtable::size_type size_type;
806 typedef typename _Hashtable::difference_type difference_type;
819 unordered_multimap(size_type __n = 10,
820 const hasher& __hf = hasher(),
821 const key_equal& __eql = key_equal(),
822 const allocator_type& __a = allocator_type())
823 : _M_h(__n, __hf, __eql, __a)
839 template<
typename _InputIterator>
840 unordered_multimap(_InputIterator __f, _InputIterator __l,
842 const hasher& __hf = hasher(),
843 const key_equal& __eql = key_equal(),
844 const allocator_type& __a = allocator_type())
845 : _M_h(__f, __l, __n, __hf, __eql, __a)
849 unordered_multimap(
const unordered_multimap&) =
default;
852 unordered_multimap(unordered_multimap&&) =
default;
865 unordered_multimap(initializer_list<value_type> __l,
867 const hasher& __hf = hasher(),
868 const key_equal& __eql = key_equal(),
869 const allocator_type& __a = allocator_type())
870 : _M_h(__l, __n, __hf, __eql, __a)
875 operator=(
const unordered_multimap&) =
default;
879 operator=(unordered_multimap&&) =
default;
893 operator=(initializer_list<value_type> __l)
902 get_allocator()
const noexcept
903 {
return _M_h.get_allocator(); }
909 empty()
const noexcept
910 {
return _M_h.empty(); }
914 size()
const noexcept
915 {
return _M_h.size(); }
919 max_size()
const noexcept
920 {
return _M_h.max_size(); }
930 {
return _M_h.begin(); }
938 begin()
const noexcept
939 {
return _M_h.begin(); }
942 cbegin()
const noexcept
943 {
return _M_h.begin(); }
952 {
return _M_h.end(); }
961 {
return _M_h.end(); }
964 cend()
const noexcept
965 {
return _M_h.end(); }
985 template<
typename... _Args>
987 emplace(_Args&&... __args)
988 {
return _M_h.emplace(std::forward<_Args>(__args)...); }
1011 template<
typename... _Args>
1013 emplace_hint(const_iterator __pos, _Args&&... __args)
1014 {
return _M_h.emplace_hint(__pos, std::forward<_Args>(__args)...); }
1027 insert(
const value_type& __x)
1028 {
return _M_h.insert(__x); }
1030 template<
typename _Pair,
typename =
typename
1031 std::enable_if<std::is_constructible<value_type,
1032 _Pair&&>::value>::type>
1035 {
return _M_h.insert(std::forward<_Pair>(__x)); }
1059 insert(const_iterator __hint,
const value_type& __x)
1060 {
return _M_h.insert(__hint, __x); }
1062 template<
typename _Pair,
typename =
typename
1063 std::enable_if<std::is_constructible<value_type,
1064 _Pair&&>::value>::type>
1066 insert(const_iterator __hint, _Pair&& __x)
1067 {
return _M_h.insert(__hint, std::forward<_Pair>(__x)); }
1079 template<
typename _InputIterator>
1081 insert(_InputIterator __first, _InputIterator __last)
1082 { _M_h.insert(__first, __last); }
1093 insert(initializer_list<value_type> __l)
1094 { _M_h.insert(__l); }
1111 erase(const_iterator __position)
1112 {
return _M_h.erase(__position); }
1116 erase(iterator __it)
1117 {
return _M_h.erase(__it); }
1132 erase(
const key_type& __x)
1133 {
return _M_h.erase(__x); }
1151 erase(const_iterator __first, const_iterator __last)
1152 {
return _M_h.erase(__first, __last); }
1175 swap(unordered_multimap& __x)
1176 { _M_h.swap(__x._M_h); }
1183 hash_function()
const
1184 {
return _M_h.hash_function(); }
1190 {
return _M_h.key_eq(); }
1207 find(
const key_type& __x)
1208 {
return _M_h.find(__x); }
1211 find(
const key_type& __x)
const
1212 {
return _M_h.find(__x); }
1221 count(
const key_type& __x)
const
1222 {
return _M_h.count(__x); }
1231 std::pair<iterator, iterator>
1232 equal_range(
const key_type& __x)
1233 {
return _M_h.equal_range(__x); }
1235 std::pair<const_iterator, const_iterator>
1236 equal_range(
const key_type& __x)
const
1237 {
return _M_h.equal_range(__x); }
1244 bucket_count()
const noexcept
1245 {
return _M_h.bucket_count(); }
1249 max_bucket_count()
const noexcept
1250 {
return _M_h.max_bucket_count(); }
1258 bucket_size(size_type __n)
const
1259 {
return _M_h.bucket_size(__n); }
1267 bucket(
const key_type& __key)
const
1268 {
return _M_h.bucket(__key); }
1277 begin(size_type __n)
1278 {
return _M_h.begin(__n); }
1287 const_local_iterator
1288 begin(size_type __n)
const
1289 {
return _M_h.begin(__n); }
1291 const_local_iterator
1292 cbegin(size_type __n)
const
1293 {
return _M_h.cbegin(__n); }
1304 {
return _M_h.end(__n); }
1313 const_local_iterator
1314 end(size_type __n)
const
1315 {
return _M_h.end(__n); }
1317 const_local_iterator
1318 cend(size_type __n)
const
1319 {
return _M_h.cend(__n); }
1326 load_factor()
const noexcept
1327 {
return _M_h.load_factor(); }
1332 max_load_factor()
const noexcept
1333 {
return _M_h.max_load_factor(); }
1340 max_load_factor(
float __z)
1341 { _M_h.max_load_factor(__z); }
1351 rehash(size_type __n)
1352 { _M_h.rehash(__n); }
1362 reserve(size_type __n)
1363 { _M_h.reserve(__n); }
1365 template<
typename _Key1,
typename _Tp1,
typename _Hash1,
typename _Pred1,
1368 operator==(
const unordered_multimap<_Key1, _Tp1,
1369 _Hash1, _Pred1, _Alloc1>&,
1370 const unordered_multimap<_Key1, _Tp1,
1371 _Hash1, _Pred1, _Alloc1>&);
1374 template<
class _Key,
class _Tp,
class _Hash,
class _Pred,
class _Alloc>
1376 swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1377 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1380 template<
class _Key,
class _Tp,
class _Hash,
class _Pred,
class _Alloc>
1382 swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1383 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1386 template<
class _Key,
class _Tp,
class _Hash,
class _Pred,
class _Alloc>
1388 operator==(
const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1389 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1390 {
return __x._M_h._M_equal(__y._M_h); }
1392 template<
class _Key,
class _Tp,
class _Hash,
class _Pred,
class _Alloc>
1394 operator!=(
const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1395 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1396 {
return !(__x == __y); }
1398 template<
class _Key,
class _Tp,
class _Hash,
class _Pred,
class _Alloc>
1400 operator==(
const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1401 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1402 {
return __x._M_h._M_equal(__y._M_h); }
1404 template<
class _Key,
class _Tp,
class _Hash,
class _Pred,
class _Alloc>
1406 operator!=(
const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1407 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1408 {
return !(__x == __y); }
1410 _GLIBCXX_END_NAMESPACE_CONTAINER
bool operator==(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
namespace std _GLIBCXX_VISIBILITY(default)
Definition: unordered_map.h:33
bool operator!=(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
void swap(exception_ptr &__lhs, exception_ptr &__rhs)
Definition: exception_ptr.h:160