30 #ifndef _UNORDERED_SET_H
31 #define _UNORDERED_SET_H
33 namespace std _GLIBCXX_VISIBILITY(default)
35 _GLIBCXX_BEGIN_NAMESPACE_VERSION
36 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
42 template<
typename _Value,
47 using __uset_hashtable = _Hashtable<_Value, _Value, _Alloc,
48 __detail::_Identity, _Pred, _Hash,
49 __detail::_Mod_range_hashing,
50 __detail::_Default_ranged_hash,
51 __detail::_Prime_rehash_policy, _Tr>;
57 template<
typename _Value,
62 using __umset_hashtable = _Hashtable<_Value, _Value, _Alloc,
65 __detail::_Mod_range_hashing,
66 __detail::_Default_ranged_hash,
67 __detail::_Prime_rehash_policy, _Tr>;
69 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
95 template<
typename _Value,
101 typedef __uset_hashtable<_Value, _Hash, _Pred, _Alloc> _Hashtable;
110 typedef typename _Hashtable::hasher
hasher;
129 #if __cplusplus > 201402L
130 using node_type =
typename _Hashtable::node_type;
131 using insert_return_type =
typename _Hashtable::insert_return_type;
151 : _M_h(__n, __hf, __eql, __a)
167 template<
typename _InputIterator>
173 : _M_h(__first, __last, __n, __hf, __eql, __a)
198 : _M_h(__uset._M_h, __a)
208 noexcept( noexcept(_Hashtable(
std::move(__uset._M_h), __a)) )
209 : _M_h(
std::
move(__uset._M_h), __a)
228 : _M_h(__l, __n, __hf, __eql, __a)
240 template<
typename _InputIterator>
247 template<
typename _InputIterator>
295 {
return _M_h.get_allocator(); }
300 _GLIBCXX_NODISCARD
bool
302 {
return _M_h.empty(); }
307 {
return _M_h.size(); }
312 {
return _M_h.max_size(); }
323 {
return _M_h.begin(); }
327 {
return _M_h.begin(); }
337 {
return _M_h.end(); }
341 {
return _M_h.end(); }
350 {
return _M_h.begin(); }
358 {
return _M_h.end(); }
377 template<
typename... _Args>
380 {
return _M_h.emplace(std::forward<_Args>(__args)...); }
403 template<
typename... _Args>
406 {
return _M_h.emplace_hint(__pos, std::forward<_Args>(__args)...); }
424 {
return _M_h.insert(__x); }
453 {
return _M_h.insert(__hint, __x); }
457 {
return _M_h.insert(__hint,
std::move(__x)); }
469 template<
typename _InputIterator>
471 insert(_InputIterator __first, _InputIterator __last)
472 { _M_h.insert(__first, __last); }
483 { _M_h.insert(__l); }
485 #if __cplusplus > 201402L
490 __glibcxx_assert(__pos !=
end());
491 return _M_h.extract(__pos);
497 {
return _M_h.extract(__key); }
502 {
return _M_h._M_reinsert_node(
std::move(__nh)); }
507 {
return _M_h._M_reinsert_node(
std::move(__nh)).position; }
526 {
return _M_h.erase(__position); }
531 {
return _M_h.erase(__position); }
548 {
return _M_h.erase(__x); }
566 {
return _M_h.erase(__first, __last); }
589 noexcept( noexcept(_M_h.swap(__x._M_h)) )
590 { _M_h.swap(__x._M_h); }
592 #if __cplusplus > 201402L
593 template<
typename,
typename,
typename>
594 friend class std::_Hash_merge_helper;
596 template<
typename _H2,
typename _P2>
600 using _Merge_helper = _Hash_merge_helper<unordered_set, _H2, _P2>;
601 _M_h._M_merge_unique(_Merge_helper::_S_get_table(__source));
604 template<
typename _H2,
typename _P2>
606 merge(unordered_set<_Value, _H2, _P2, _Alloc>&& __source)
609 template<
typename _H2,
typename _P2>
611 merge(unordered_multiset<_Value, _H2, _P2, _Alloc>& __source)
613 using _Merge_helper = _Hash_merge_helper<unordered_set, _H2, _P2>;
614 _M_h._M_merge_unique(_Merge_helper::_S_get_table(__source));
617 template<
typename _H2,
typename _P2>
619 merge(unordered_multiset<_Value, _H2, _P2, _Alloc>&& __source)
629 {
return _M_h.hash_function(); }
635 {
return _M_h.key_eq(); }
653 {
return _M_h.find(__x); }
655 #if __cplusplus > 201703L
656 template<
typename _Kt>
659 -> decltype(_M_h._M_find_tr(__k))
660 {
return _M_h._M_find_tr(__k); }
665 {
return _M_h.find(__x); }
667 #if __cplusplus > 201703L
668 template<
typename _Kt>
671 -> decltype(_M_h._M_find_tr(__k))
672 {
return _M_h._M_find_tr(__k); }
688 {
return _M_h.count(__x); }
690 #if __cplusplus > 201703L
691 template<
typename _Kt>
694 -> decltype(_M_h._M_count_tr(__k))
695 {
return _M_h._M_count_tr(__k); }
699 #if __cplusplus > 201703L
708 {
return _M_h.find(__x) != _M_h.end(); }
710 template<
typename _Kt>
713 -> decltype(_M_h._M_find_tr(__k),
void(),
true)
714 {
return _M_h._M_find_tr(__k) != _M_h.end(); }
729 {
return _M_h.equal_range(__x); }
731 #if __cplusplus > 201703L
732 template<
typename _Kt>
735 -> decltype(_M_h._M_equal_range_tr(__k))
736 {
return _M_h._M_equal_range_tr(__k); }
741 {
return _M_h.equal_range(__x); }
743 #if __cplusplus > 201703L
744 template<
typename _Kt>
747 -> decltype(_M_h._M_equal_range_tr(__k))
748 {
return _M_h._M_equal_range_tr(__k); }
757 {
return _M_h.bucket_count(); }
762 {
return _M_h.max_bucket_count(); }
771 {
return _M_h.bucket_size(__n); }
780 {
return _M_h.bucket(__key); }
791 {
return _M_h.begin(__n); }
795 {
return _M_h.begin(__n); }
799 {
return _M_h.cbegin(__n); }
811 {
return _M_h.end(__n); }
815 {
return _M_h.end(__n); }
819 {
return _M_h.cend(__n); }
827 {
return _M_h.load_factor(); }
833 {
return _M_h.max_load_factor(); }
841 { _M_h.max_load_factor(__z); }
852 { _M_h.rehash(__n); }
863 { _M_h.reserve(__n); }
865 template<
typename _Value1,
typename _Hash1,
typename _Pred1,
872 #if __cpp_deduction_guides >= 201606
874 template<
typename _InputIterator,
876 hash<typename iterator_traits<_InputIterator>::value_type>,
878 equal_to<typename iterator_traits<_InputIterator>::value_type>,
879 typename _Allocator =
880 allocator<typename iterator_traits<_InputIterator>::value_type>,
881 typename = _RequireInputIter<_InputIterator>,
882 typename = _RequireNotAllocatorOrIntegral<_Hash>,
883 typename = _RequireNotAllocator<_Pred>,
884 typename = _RequireAllocator<_Allocator>>
885 unordered_set(_InputIterator, _InputIterator,
887 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
888 -> unordered_set<
typename iterator_traits<_InputIterator>::value_type,
889 _Hash, _Pred, _Allocator>;
891 template<
typename _Tp,
typename _Hash = hash<_Tp>,
892 typename _Pred = equal_to<_Tp>,
893 typename _Allocator = allocator<_Tp>,
894 typename = _RequireNotAllocatorOrIntegral<_Hash>,
895 typename = _RequireNotAllocator<_Pred>,
896 typename = _RequireAllocator<_Allocator>>
897 unordered_set(initializer_list<_Tp>,
899 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
900 -> unordered_set<_Tp, _Hash, _Pred, _Allocator>;
902 template<
typename _InputIterator,
typename _Allocator,
903 typename = _RequireInputIter<_InputIterator>,
904 typename = _RequireAllocator<_Allocator>>
905 unordered_set(_InputIterator, _InputIterator,
909 typename iterator_traits<_InputIterator>::value_type>,
911 typename iterator_traits<_InputIterator>::value_type>,
914 template<
typename _InputIterator,
typename _Hash,
typename _Allocator,
915 typename = _RequireInputIter<_InputIterator>,
916 typename = _RequireNotAllocatorOrIntegral<_Hash>,
917 typename = _RequireAllocator<_Allocator>>
918 unordered_set(_InputIterator, _InputIterator,
924 typename iterator_traits<_InputIterator>::value_type>,
927 template<
typename _Tp,
typename _Allocator,
928 typename = _RequireAllocator<_Allocator>>
929 unordered_set(initializer_list<_Tp>,
931 -> unordered_set<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
933 template<
typename _Tp,
typename _Hash,
typename _Allocator,
934 typename = _RequireNotAllocatorOrIntegral<_Hash>,
935 typename = _RequireAllocator<_Allocator>>
936 unordered_set(initializer_list<_Tp>,
938 -> unordered_set<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
963 template<
typename _Value,
964 typename _Hash = hash<_Value>,
965 typename _Pred = equal_to<_Value>,
966 typename _Alloc = allocator<_Value>>
967 class unordered_multiset
969 typedef __umset_hashtable<_Value, _Hash, _Pred, _Alloc> _Hashtable;
978 typedef typename _Hashtable::hasher
hasher;
997 #if __cplusplus > 201402L
998 using node_type =
typename _Hashtable::node_type;
1018 : _M_h(__n, __hf, __eql, __a)
1034 template<
typename _InputIterator>
1040 : _M_h(__first, __last, __n, __hf, __eql, __a)
1065 : _M_h(__l, __n, __hf, __eql, __a)
1092 : _M_h(__umset._M_h, __a)
1102 noexcept( noexcept(_Hashtable(
std::move(__umset._M_h), __a)) )
1103 : _M_h(
std::
move(__umset._M_h), __a)
1115 template<
typename _InputIterator>
1122 template<
typename _InputIterator>
1162 {
return _M_h.get_allocator(); }
1167 _GLIBCXX_NODISCARD
bool
1169 {
return _M_h.empty(); }
1174 {
return _M_h.size(); }
1179 {
return _M_h.max_size(); }
1190 {
return _M_h.begin(); }
1194 {
return _M_h.begin(); }
1204 {
return _M_h.end(); }
1208 {
return _M_h.end(); }
1217 {
return _M_h.begin(); }
1225 {
return _M_h.end(); }
1236 template<
typename... _Args>
1239 {
return _M_h.emplace(std::forward<_Args>(__args)...); }
1258 template<
typename... _Args>
1261 {
return _M_h.emplace_hint(__pos, std::forward<_Args>(__args)...); }
1273 {
return _M_h.insert(__x); }
1299 {
return _M_h.insert(__hint, __x); }
1303 {
return _M_h.insert(__hint,
std::move(__x)); }
1314 template<
typename _InputIterator>
1316 insert(_InputIterator __first, _InputIterator __last)
1317 { _M_h.insert(__first, __last); }
1328 { _M_h.insert(__l); }
1330 #if __cplusplus > 201402L
1335 __glibcxx_assert(__pos !=
end());
1336 return _M_h.extract(__pos);
1342 {
return _M_h.extract(__key); }
1347 {
return _M_h._M_reinsert_node_multi(
cend(),
std::move(__nh)); }
1352 {
return _M_h._M_reinsert_node_multi(__hint,
std::move(__nh)); }
1372 {
return _M_h.erase(__position); }
1377 {
return _M_h.erase(__position); }
1395 {
return _M_h.erase(__x); }
1415 {
return _M_h.erase(__first, __last); }
1439 noexcept( noexcept(_M_h.swap(__x._M_h)) )
1440 { _M_h.swap(__x._M_h); }
1442 #if __cplusplus > 201402L
1443 template<
typename,
typename,
typename>
1444 friend class std::_Hash_merge_helper;
1446 template<
typename _H2,
typename _P2>
1451 = _Hash_merge_helper<unordered_multiset, _H2, _P2>;
1452 _M_h._M_merge_multi(_Merge_helper::_S_get_table(__source));
1455 template<
typename _H2,
typename _P2>
1457 merge(unordered_multiset<_Value, _H2, _P2, _Alloc>&& __source)
1458 { merge(__source); }
1460 template<
typename _H2,
typename _P2>
1462 merge(unordered_set<_Value, _H2, _P2, _Alloc>& __source)
1465 = _Hash_merge_helper<unordered_multiset, _H2, _P2>;
1466 _M_h._M_merge_multi(_Merge_helper::_S_get_table(__source));
1469 template<
typename _H2,
typename _P2>
1471 merge(unordered_set<_Value, _H2, _P2, _Alloc>&& __source)
1472 { merge(__source); }
1481 {
return _M_h.hash_function(); }
1487 {
return _M_h.key_eq(); }
1505 {
return _M_h.find(__x); }
1507 #if __cplusplus > 201703L
1508 template<
typename _Kt>
1511 -> decltype(_M_h._M_find_tr(__x))
1512 {
return _M_h._M_find_tr(__x); }
1517 {
return _M_h.find(__x); }
1519 #if __cplusplus > 201703L
1520 template<
typename _Kt>
1523 -> decltype(_M_h._M_find_tr(__x))
1524 {
return _M_h._M_find_tr(__x); }
1536 {
return _M_h.count(__x); }
1538 #if __cplusplus > 201703L
1539 template<
typename _Kt>
1541 count(
const _Kt& __x)
const -> decltype(_M_h._M_count_tr(__x))
1542 {
return _M_h._M_count_tr(__x); }
1546 #if __cplusplus > 201703L
1555 {
return _M_h.find(__x) != _M_h.end(); }
1557 template<
typename _Kt>
1560 -> decltype(_M_h._M_find_tr(__x),
void(),
true)
1561 {
return _M_h._M_find_tr(__x) != _M_h.end(); }
1574 {
return _M_h.equal_range(__x); }
1576 #if __cplusplus > 201703L
1577 template<
typename _Kt>
1580 -> decltype(_M_h._M_equal_range_tr(__x))
1581 {
return _M_h._M_equal_range_tr(__x); }
1586 {
return _M_h.equal_range(__x); }
1588 #if __cplusplus > 201703L
1589 template<
typename _Kt>
1592 -> decltype(_M_h._M_equal_range_tr(__x))
1593 {
return _M_h._M_equal_range_tr(__x); }
1602 {
return _M_h.bucket_count(); }
1607 {
return _M_h.max_bucket_count(); }
1616 {
return _M_h.bucket_size(__n); }
1624 bucket(
const key_type& __key)
const
1625 {
return _M_h.bucket(__key); }
1636 {
return _M_h.begin(__n); }
1640 {
return _M_h.begin(__n); }
1644 {
return _M_h.cbegin(__n); }
1656 {
return _M_h.end(__n); }
1660 {
return _M_h.end(__n); }
1664 {
return _M_h.cend(__n); }
1672 {
return _M_h.load_factor(); }
1678 {
return _M_h.max_load_factor(); }
1686 { _M_h.max_load_factor(__z); }
1697 { _M_h.rehash(__n); }
1708 { _M_h.reserve(__n); }
1710 template<
typename _Value1,
typename _Hash1,
typename _Pred1,
1718 #if __cpp_deduction_guides >= 201606
1720 template<
typename _InputIterator,
1722 hash<typename iterator_traits<_InputIterator>::value_type>,
1724 equal_to<typename iterator_traits<_InputIterator>::value_type>,
1725 typename _Allocator =
1726 allocator<typename iterator_traits<_InputIterator>::value_type>,
1727 typename = _RequireInputIter<_InputIterator>,
1728 typename = _RequireNotAllocatorOrIntegral<_Hash>,
1729 typename = _RequireNotAllocator<_Pred>,
1730 typename = _RequireAllocator<_Allocator>>
1731 unordered_multiset(_InputIterator, _InputIterator,
1733 _Hash = _Hash(), _Pred = _Pred(),
1734 _Allocator = _Allocator())
1735 -> unordered_multiset<
typename iterator_traits<_InputIterator>::value_type,
1736 _Hash, _Pred, _Allocator>;
1738 template<
typename _Tp,
typename _Hash = hash<_Tp>,
1739 typename _Pred = equal_to<_Tp>,
1740 typename _Allocator = allocator<_Tp>,
1741 typename = _RequireNotAllocatorOrIntegral<_Hash>,
1742 typename = _RequireNotAllocator<_Pred>,
1743 typename = _RequireAllocator<_Allocator>>
1744 unordered_multiset(initializer_list<_Tp>,
1746 _Hash = _Hash(), _Pred = _Pred(),
1747 _Allocator = _Allocator())
1748 -> unordered_multiset<_Tp, _Hash, _Pred, _Allocator>;
1750 template<
typename _InputIterator,
typename _Allocator,
1751 typename = _RequireInputIter<_InputIterator>,
1752 typename = _RequireAllocator<_Allocator>>
1753 unordered_multiset(_InputIterator, _InputIterator,
1757 iterator_traits<_InputIterator>::value_type>,
1759 iterator_traits<_InputIterator>::value_type>,
1762 template<
typename _InputIterator,
typename _Hash,
typename _Allocator,
1763 typename = _RequireInputIter<_InputIterator>,
1764 typename = _RequireNotAllocatorOrIntegral<_Hash>,
1765 typename = _RequireAllocator<_Allocator>>
1766 unordered_multiset(_InputIterator, _InputIterator,
1769 -> unordered_multiset<
typename
1770 iterator_traits<_InputIterator>::value_type,
1774 iterator_traits<_InputIterator>::value_type>,
1777 template<
typename _Tp,
typename _Allocator,
1778 typename = _RequireAllocator<_Allocator>>
1779 unordered_multiset(initializer_list<_Tp>,
1781 -> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
1783 template<
typename _Tp,
typename _Hash,
typename _Allocator,
1784 typename = _RequireNotAllocatorOrIntegral<_Hash>,
1785 typename = _RequireAllocator<_Allocator>>
1786 unordered_multiset(initializer_list<_Tp>,
1788 -> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
1792 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1794 swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1795 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
1796 noexcept(noexcept(__x.swap(__y)))
1799 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1801 swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1802 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1803 noexcept(noexcept(__x.swap(__y)))
1806 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1808 operator==(
const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1809 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
1810 {
return __x._M_h._M_equal(__y._M_h); }
1812 #if __cpp_impl_three_way_comparison < 201907L
1813 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1815 operator!=(
const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1816 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
1817 {
return !(__x == __y); }
1820 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1822 operator==(
const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1823 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1824 {
return __x._M_h._M_equal(__y._M_h); }
1826 #if __cpp_impl_three_way_comparison < 201907L
1827 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1829 operator!=(
const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1830 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1831 {
return !(__x == __y); }
1834 _GLIBCXX_END_NAMESPACE_CONTAINER
1836 #if __cplusplus > 201402L
1838 template<
typename _Val,
typename _Hash1,
typename _Eq1,
typename _Alloc,
1839 typename _Hash2,
typename _Eq2>
1840 struct _Hash_merge_helper<
1841 _GLIBCXX_STD_C::unordered_set<_Val, _Hash1, _Eq1, _Alloc>, _Hash2, _Eq2>
1844 template<
typename... _Tp>
1845 using unordered_set = _GLIBCXX_STD_C::unordered_set<_Tp...>;
1846 template<
typename... _Tp>
1847 using unordered_multiset = _GLIBCXX_STD_C::unordered_multiset<_Tp...>;
1849 friend unordered_set<_Val, _Hash1, _Eq1, _Alloc>;
1852 _S_get_table(unordered_set<_Val, _Hash2, _Eq2, _Alloc>& __set)
1853 {
return __set._M_h; }
1856 _S_get_table(unordered_multiset<_Val, _Hash2, _Eq2, _Alloc>& __set)
1857 {
return __set._M_h; }
1861 template<
typename _Val,
typename _Hash1,
typename _Eq1,
typename _Alloc,
1862 typename _Hash2,
typename _Eq2>
1863 struct _Hash_merge_helper<
1864 _GLIBCXX_STD_C::unordered_multiset<_Val, _Hash1, _Eq1, _Alloc>,
1868 template<
typename... _Tp>
1869 using unordered_set = _GLIBCXX_STD_C::unordered_set<_Tp...>;
1870 template<
typename... _Tp>
1871 using unordered_multiset = _GLIBCXX_STD_C::unordered_multiset<_Tp...>;
1873 friend unordered_multiset<_Val, _Hash1, _Eq1, _Alloc>;
1876 _S_get_table(unordered_set<_Val, _Hash2, _Eq2, _Alloc>& __set)
1877 {
return __set._M_h; }
1880 _S_get_table(unordered_multiset<_Val, _Hash2, _Eq2, _Alloc>& __set)
1881 {
return __set._M_h; }
1885 _GLIBCXX_END_NAMESPACE_VERSION