30 #ifndef _UNORDERED_SET_H 31 #define _UNORDERED_SET_H 33 namespace std _GLIBCXX_VISIBILITY(default)
35 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
41 template<
typename _Value,
47 __detail::_Identity, _Pred, _Hash,
56 template<
typename _Value,
68 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
92 template<
class _Value,
107 typedef typename _Hashtable::hasher
hasher;
126 #if __cplusplus > 201402L 127 using node_type =
typename _Hashtable::node_type;
128 using insert_return_type =
typename _Hashtable::insert_return_type;
148 : _M_h(__n, __hf, __eql, __a)
164 template<
typename _InputIterator>
170 : _M_h(__first, __last, __n, __hf, __eql, __a)
195 : _M_h(__uset._M_h, __a)
205 : _M_h(
std::move(__uset._M_h), __a)
224 : _M_h(__l, __n, __hf, __eql, __a)
236 template<
typename _InputIterator>
243 template<
typename _InputIterator>
291 {
return _M_h.get_allocator(); }
298 {
return _M_h.empty(); }
303 {
return _M_h.size(); }
308 {
return _M_h.max_size(); }
319 {
return _M_h.begin(); }
323 {
return _M_h.begin(); }
333 {
return _M_h.end(); }
337 {
return _M_h.end(); }
346 {
return _M_h.begin(); }
354 {
return _M_h.end(); }
373 template<
typename... _Args>
376 {
return _M_h.emplace(std::forward<_Args>(__args)...); }
399 template<
typename... _Args>
402 {
return _M_h.emplace_hint(__pos, std::forward<_Args>(__args)...); }
420 {
return _M_h.insert(__x); }
424 {
return _M_h.insert(std::move(__x)); }
449 {
return _M_h.insert(__hint, __x); }
453 {
return _M_h.insert(__hint, std::move(__x)); }
465 template<
typename _InputIterator>
467 insert(_InputIterator __first, _InputIterator __last)
468 { _M_h.insert(__first, __last); }
479 { _M_h.insert(__l); }
481 #if __cplusplus > 201402L 486 __glibcxx_assert(__pos !=
end());
487 return _M_h.extract(__pos);
493 {
return _M_h.extract(__key); }
498 {
return _M_h._M_reinsert_node(std::move(__nh)); }
503 {
return _M_h._M_reinsert_node(std::move(__nh)).position; }
522 {
return _M_h.erase(__position); }
527 {
return _M_h.erase(__position); }
544 {
return _M_h.erase(__x); }
562 {
return _M_h.erase(__first, __last); }
585 noexcept( noexcept(_M_h.swap(__x._M_h)) )
586 { _M_h.swap(__x._M_h); }
588 #if __cplusplus > 201402L 589 template<
typename,
typename,
typename>
590 friend class _Hash_merge_helper;
592 template<
typename _H2,
typename _P2>
596 using _Merge_helper = _Hash_merge_helper<unordered_set, _H2, _P2>;
597 _M_h._M_merge_unique(_Merge_helper::_S_get_table(__source));
600 template<
typename _H2,
typename _P2>
602 merge(unordered_set<_Value, _H2, _P2, _Alloc>&& __source)
605 template<
typename _H2,
typename _P2>
607 merge(unordered_multiset<_Value, _H2, _P2, _Alloc>& __source)
609 using _Merge_helper = _Hash_merge_helper<unordered_set, _H2, _P2>;
610 _M_h._M_merge_unique(_Merge_helper::_S_get_table(__source));
613 template<
typename _H2,
typename _P2>
615 merge(unordered_multiset<_Value, _H2, _P2, _Alloc>&& __source)
625 {
return _M_h.hash_function(); }
631 {
return _M_h.key_eq(); }
649 {
return _M_h.find(__x); }
653 {
return _M_h.find(__x); }
667 {
return _M_h.count(__x); }
680 {
return _M_h.equal_range(__x); }
684 {
return _M_h.equal_range(__x); }
692 {
return _M_h.bucket_count(); }
697 {
return _M_h.max_bucket_count(); }
706 {
return _M_h.bucket_size(__n); }
715 {
return _M_h.bucket(__key); }
726 {
return _M_h.begin(__n); }
730 {
return _M_h.begin(__n); }
734 {
return _M_h.cbegin(__n); }
746 {
return _M_h.end(__n); }
750 {
return _M_h.end(__n); }
754 {
return _M_h.cend(__n); }
762 {
return _M_h.load_factor(); }
768 {
return _M_h.max_load_factor(); }
776 { _M_h.max_load_factor(__z); }
787 { _M_h.rehash(__n); }
798 { _M_h.reserve(__n); }
800 template<
typename _Value1,
typename _Hash1,
typename _Pred1,
826 template<
class _Value,
827 class _Hash = hash<_Value>,
830 class unordered_multiset
832 typedef __umset_hashtable<_Value, _Hash, _Pred, _Alloc> _Hashtable;
841 typedef typename _Hashtable::hasher
hasher;
860 #if __cplusplus > 201402L 861 using node_type =
typename _Hashtable::node_type;
881 : _M_h(__n, __hf, __eql, __a)
897 template<
typename _InputIterator>
903 : _M_h(__first, __last, __n, __hf, __eql, __a)
928 : _M_h(__l, __n, __hf, __eql, __a)
955 : _M_h(__umset._M_h, __a)
965 : _M_h(
std::move(__umset._M_h), __a)
977 template<
typename _InputIterator>
984 template<
typename _InputIterator>
1024 {
return _M_h.get_allocator(); }
1031 {
return _M_h.empty(); }
1036 {
return _M_h.size(); }
1041 {
return _M_h.max_size(); }
1052 {
return _M_h.begin(); }
1056 {
return _M_h.begin(); }
1066 {
return _M_h.end(); }
1070 {
return _M_h.end(); }
1079 {
return _M_h.begin(); }
1087 {
return _M_h.end(); }
1098 template<
typename... _Args>
1101 {
return _M_h.emplace(std::forward<_Args>(__args)...); }
1120 template<
typename... _Args>
1123 {
return _M_h.emplace_hint(__pos, std::forward<_Args>(__args)...); }
1135 {
return _M_h.insert(__x); }
1139 {
return _M_h.insert(std::move(__x)); }
1161 {
return _M_h.insert(__hint, __x); }
1165 {
return _M_h.insert(__hint, std::move(__x)); }
1176 template<
typename _InputIterator>
1178 insert(_InputIterator __first, _InputIterator __last)
1179 { _M_h.insert(__first, __last); }
1190 { _M_h.insert(__l); }
1192 #if __cplusplus > 201402L 1197 __glibcxx_assert(__pos !=
end());
1198 return _M_h.extract(__pos);
1204 {
return _M_h.extract(__key); }
1209 {
return _M_h._M_reinsert_node_multi(
cend(), std::move(__nh)); }
1214 {
return _M_h._M_reinsert_node_multi(__hint, std::move(__nh)); }
1234 {
return _M_h.erase(__position); }
1239 {
return _M_h.erase(__position); }
1257 {
return _M_h.erase(__x); }
1277 {
return _M_h.erase(__first, __last); }
1301 noexcept( noexcept(_M_h.swap(__x._M_h)) )
1302 { _M_h.swap(__x._M_h); }
1304 #if __cplusplus > 201402L 1305 template<
typename,
typename,
typename>
1306 friend class _Hash_merge_helper;
1308 template<
typename _H2,
typename _P2>
1313 = _Hash_merge_helper<unordered_multiset, _H2, _P2>;
1314 _M_h._M_merge_multi(_Merge_helper::_S_get_table(__source));
1317 template<
typename _H2,
typename _P2>
1319 merge(unordered_multiset<_Value, _H2, _P2, _Alloc>&& __source)
1320 { merge(__source); }
1322 template<
typename _H2,
typename _P2>
1324 merge(unordered_set<_Value, _H2, _P2, _Alloc>& __source)
1327 = _Hash_merge_helper<unordered_multiset, _H2, _P2>;
1328 _M_h._M_merge_multi(_Merge_helper::_S_get_table(__source));
1331 template<
typename _H2,
typename _P2>
1333 merge(unordered_set<_Value, _H2, _P2, _Alloc>&& __source)
1334 { merge(__source); }
1343 {
return _M_h.hash_function(); }
1349 {
return _M_h.key_eq(); }
1367 {
return _M_h.find(__x); }
1371 {
return _M_h.find(__x); }
1381 {
return _M_h.count(__x); }
1392 {
return _M_h.equal_range(__x); }
1396 {
return _M_h.equal_range(__x); }
1404 {
return _M_h.bucket_count(); }
1409 {
return _M_h.max_bucket_count(); }
1418 {
return _M_h.bucket_size(__n); }
1426 bucket(
const key_type& __key)
const 1427 {
return _M_h.bucket(__key); }
1438 {
return _M_h.begin(__n); }
1442 {
return _M_h.begin(__n); }
1446 {
return _M_h.cbegin(__n); }
1458 {
return _M_h.end(__n); }
1462 {
return _M_h.end(__n); }
1466 {
return _M_h.cend(__n); }
1474 {
return _M_h.load_factor(); }
1480 {
return _M_h.max_load_factor(); }
1488 { _M_h.max_load_factor(__z); }
1499 { _M_h.rehash(__n); }
1510 { _M_h.reserve(__n); }
1512 template<
typename _Value1,
typename _Hash1,
typename _Pred1,
1519 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1521 swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1522 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
1523 noexcept(noexcept(__x.swap(__y)))
1526 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1528 swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1529 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1530 noexcept(noexcept(__x.swap(__y)))
1533 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1535 operator==(
const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1536 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
1537 {
return __x._M_h._M_equal(__y._M_h); }
1539 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1541 operator!=(
const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1542 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
1543 {
return !(__x == __y); }
1545 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1547 operator==(
const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1548 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1549 {
return __x._M_h._M_equal(__y._M_h); }
1551 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1553 operator!=(
const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1554 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1555 {
return !(__x == __y); }
1557 _GLIBCXX_END_NAMESPACE_CONTAINER
1559 #if __cplusplus > 201402L 1560 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1562 template<
typename _Val,
typename _Hash1,
typename _Eq1,
typename _Alloc,
1563 typename _Hash2,
typename _Eq2>
1564 struct _Hash_merge_helper<
1565 _GLIBCXX_STD_C::unordered_set<_Val, _Hash1, _Eq1, _Alloc>, _Hash2, _Eq2>
1568 template<
typename... _Tp>
1569 using unordered_set = _GLIBCXX_STD_C::unordered_set<_Tp...>;
1570 template<
typename... _Tp>
1571 using unordered_multiset = _GLIBCXX_STD_C::unordered_multiset<_Tp...>;
1573 friend unordered_set<_Val, _Hash1, _Eq1, _Alloc>;
1576 _S_get_table(unordered_set<_Val, _Hash2, _Eq2, _Alloc>& __set)
1577 {
return __set._M_h; }
1580 _S_get_table(unordered_multiset<_Val, _Hash2, _Eq2, _Alloc>& __set)
1581 {
return __set._M_h; }
1585 template<
typename _Val,
typename _Hash1,
typename _Eq1,
typename _Alloc,
1586 typename _Hash2,
typename _Eq2>
1587 struct _Hash_merge_helper<
1588 _GLIBCXX_STD_C::unordered_multiset<_Val, _Hash1, _Eq1, _Alloc>,
1592 template<
typename... _Tp>
1593 using unordered_set = _GLIBCXX_STD_C::unordered_set<_Tp...>;
1594 template<
typename... _Tp>
1595 using unordered_multiset = _GLIBCXX_STD_C::unordered_multiset<_Tp...>;
1597 friend unordered_multiset<_Val, _Hash1, _Eq1, _Alloc>;
1600 _S_get_table(unordered_set<_Val, _Hash2, _Eq2, _Alloc>& __set)
1601 {
return __set._M_h; }
1604 _S_get_table(unordered_multiset<_Val, _Hash2, _Eq2, _Alloc>& __set)
1605 {
return __set._M_h; }
1607 _GLIBCXX_END_NAMESPACE_VERSION
_Hashtable::value_type value_type
Public typedefs.
_Hashtable::const_pointer const_pointer
Iterator-related typedefs.
iterator emplace_hint(const_iterator __pos, _Args &&... __args)
Inserts an element into the unordered_multiset.
void insert(initializer_list< value_type > __l)
Attempts to insert a list of elements into the unordered_set.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
_Hashtable::const_iterator const_iterator
Iterator-related typedefs.
_Hashtable::iterator iterator
Iterator-related typedefs.
float load_factor() const noexcept
Returns the average number of elements per bucket.
iterator erase(const_iterator __first, const_iterator __last)
Erases a [__first,__last) range of elements from an unordered_set.
iterator begin() noexcept
const_local_iterator end(size_type __n) const
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
const_iterator cend() const noexcept
iterator erase(iterator __position)
Erases an element from an unordered_multiset.
void insert(_InputIterator __first, _InputIterator __last)
A template function that attempts to insert a range of elements.
unordered_set(size_type __n, const hasher &__hf=hasher(), const key_equal &__eql=key_equal(), const allocator_type &__a=allocator_type())
Default constructor creates no elements.
size_type max_size() const noexcept
Returns the maximum size of the unordered_set.
size_type erase(const key_type &__x)
Erases elements according to the provided key.
float max_load_factor() const noexcept
Returns a positive number that the unordered_set tries to keep the load factor less than or equal to...
unordered_set()=default
Default constructor.
std::pair< iterator, bool > emplace(_Args &&... __args)
Attempts to build and insert an element into the unordered_set.
const_iterator cbegin() const noexcept
_Hashtable::const_local_iterator const_local_iterator
Iterator-related typedefs.
_Hashtable::allocator_type allocator_type
Public typedefs.
hasher hash_function() const
Returns the hash functor object with which the unordered_multiset was constructed.
void insert(_InputIterator __first, _InputIterator __last)
A template function that inserts a range of elements.
void max_load_factor(float __z)
Change the unordered_set maximum load factor.
const_iterator begin() const noexcept
bool empty() const noexcept
Returns true if the unordered_set is empty.
const_iterator cbegin() const noexcept
iterator insert(value_type &&__x)
Inserts an element into the unordered_multiset.
iterator erase(const_iterator __first, const_iterator __last)
Erases a [__first,__last) range of elements from an unordered_multiset.
const_iterator find(const key_type &__x) const
Tries to locate an element in an unordered_multiset.
iterator find(const key_type &__x)
Tries to locate an element in an unordered_set.
const_local_iterator cend(size_type __n) const
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
const_local_iterator end(size_type __n) const
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
_Hashtable::key_equal key_equal
Public typedefs.
_Hashtable::value_type value_type
Public typedefs.
size_type size() const noexcept
Returns the size of the unordered_set.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
const_iterator begin() const noexcept
hasher hash_function() const
Returns the hash functor object with which the unordered_set was constructed.
The standard allocator, as per [20.4].
_Hashtable::reference reference
Iterator-related typedefs.
void swap(unordered_set &__x) noexcept(noexcept(_M_h.swap(__x._M_h)))
Swaps data with another unordered_set.
_Hashtable::key_equal key_equal
Public typedefs.
const_local_iterator begin(size_type __n) const
Returns a read-only (constant) iterator pointing to the first bucket element.
const_iterator end() const noexcept
size_type max_size() const noexcept
Returns the maximum size of the unordered_multiset.
_Hashtable::difference_type difference_type
Iterator-related typedefs.
size_type size() const noexcept
Returns the size of the unordered_multiset.
_Hashtable::size_type size_type
Iterator-related typedefs.
const_iterator end() const noexcept
unordered_set & operator=(const unordered_set &)=default
Copy assignment operator.
_Hashtable::local_iterator local_iterator
Iterator-related typedefs.
void rehash(size_type __n)
May rehash the unordered_set.
size_type count(const key_type &__x) const
Finds the number of elements.
size_type max_bucket_count() const noexcept
Returns the maximum number of buckets of the unordered_set.
std::pair< iterator, bool > insert(value_type &&__x)
Attempts to insert an element into the unordered_set.
Struct holding two objects of arbitrary type.
_Hashtable::pointer pointer
Iterator-related typedefs.
One of the comparison functors.
size_type erase(const key_type &__x)
Erases elements according to the provided key.
const_iterator cend() const noexcept
unordered_multiset & operator=(const unordered_multiset &)=default
Copy assignment operator.
_Hashtable::key_type key_type
Public typedefs.
_Hashtable::const_local_iterator const_local_iterator
Iterator-related typedefs.
Default ranged hash function H. In principle it should be a function object composed from objects of ...
unordered_set(initializer_list< value_type > __l, size_type __n=0, const hasher &__hf=hasher(), const key_equal &__eql=key_equal(), const allocator_type &__a=allocator_type())
Builds an unordered_set from an initializer_list.
iterator insert(const_iterator __hint, const value_type &__x)
Inserts an element into the unordered_multiset.
unordered_set(const allocator_type &__a)
Creates an unordered_set with no elements.
allocator_type get_allocator() const noexcept
Returns the allocator object used by the unordered_set.
unordered_multiset(initializer_list< value_type > __l, size_type __n=0, const hasher &__hf=hasher(), const key_equal &__eql=key_equal(), const allocator_type &__a=allocator_type())
Builds an unordered_multiset from an initializer_list.
_Hashtable::iterator iterator
Iterator-related typedefs.
unordered_multiset(const allocator_type &__a)
Creates an unordered_multiset with no elements.
void reserve(size_type __n)
Prepare the unordered_multiset for a specified number of elements.
_Hashtable::hasher hasher
Public typedefs.
unordered_set(_InputIterator __first, _InputIterator __last, size_type __n=0, const hasher &__hf=hasher(), const key_equal &__eql=key_equal(), const allocator_type &__a=allocator_type())
Builds an unordered_set from a range.
unordered_multiset & operator=(initializer_list< value_type > __l)
Unordered_multiset list assignment operator.
key_equal key_eq() const
Returns the key comparison object with which the unordered_multiset was constructed.
float load_factor() const noexcept
Returns the average number of elements per bucket.
const_local_iterator cbegin(size_type __n) const
Returns a read-only (constant) iterator pointing to the first bucket element.
_Hashtable::const_reference const_reference
Iterator-related typedefs.
_Hashtable::const_reference const_reference
Iterator-related typedefs.
ISO C++ entities toplevel namespace is std.
_Hashtable::local_iterator local_iterator
Iterator-related typedefs.
A standard container composed of unique keys (containing at most one of each key value) in which the ...
iterator emplace(_Args &&... __args)
Builds and insert an element into the unordered_multiset.
iterator insert(const_iterator __hint, value_type &&__x)
Attempts to insert an element into the unordered_set.
local_iterator end(size_type __n)
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
const_local_iterator cend(size_type __n) const
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
local_iterator end(size_type __n)
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
iterator erase(iterator __position)
Erases an element from an unordered_set.
allocator_type get_allocator() const noexcept
Returns the allocator object used by the unordered_multiset.
void rehash(size_type __n)
May rehash the unordered_multiset.
local_iterator begin(size_type __n)
Returns a read-only (constant) iterator pointing to the first bucket element.
local_iterator begin(size_type __n)
Returns a read-only (constant) iterator pointing to the first bucket element.
_Hashtable::hasher hasher
Public typedefs.
size_type max_bucket_count() const noexcept
Returns the maximum number of buckets of the unordered_multiset.
_Hashtable::allocator_type allocator_type
Public typedefs.
bool empty() const noexcept
Returns true if the unordered_multiset is empty.
_Hashtable::const_iterator const_iterator
Iterator-related typedefs.
key_equal key_eq() const
Returns the key comparison object with which the unordered_set was constructed.
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
Primary class template hash.
A standard container composed of equivalent keys (possibly containing multiple of each key value) in ...
_Hashtable::size_type size_type
Iterator-related typedefs.
iterator insert(const_iterator __hint, const value_type &__x)
Attempts to insert an element into the unordered_set.
size_type bucket_count() const noexcept
Returns the number of buckets of the unordered_multiset.
Default range hashing function: use division to fold a large number into the range [0...
unordered_multiset(size_type __n, const hasher &__hf=hasher(), const key_equal &__eql=key_equal(), const allocator_type &__a=allocator_type())
Default constructor creates no elements.
iterator find(const key_type &__x)
Tries to locate an element in an unordered_multiset.
iterator erase(const_iterator __position)
Erases an element from an unordered_multiset.
void max_load_factor(float __z)
Change the unordered_multiset maximum load factor.
_Hashtable::pointer pointer
Iterator-related typedefs.
_Hashtable::reference reference
Iterator-related typedefs.
float max_load_factor() const noexcept
Returns a positive number that the unordered_multiset tries to keep the load factor less than or equa...
_Hashtable::key_type key_type
Public typedefs.
iterator begin() noexcept
unordered_multiset(_InputIterator __first, _InputIterator __last, size_type __n=0, const hasher &__hf=hasher(), const key_equal &__eql=key_equal(), const allocator_type &__a=allocator_type())
Builds an unordered_multiset from a range.
iterator insert(const value_type &__x)
Inserts an element into the unordered_multiset.
iterator insert(const_iterator __hint, value_type &&__x)
Inserts an element into the unordered_multiset.
Default value for rehash policy. Bucket size is (usually) the smallest prime that keeps the load fact...
const_iterator find(const key_type &__x) const
Tries to locate an element in an unordered_set.
unordered_set & operator=(initializer_list< value_type > __l)
Unordered_set list assignment operator.
std::pair< iterator, bool > insert(const value_type &__x)
Attempts to insert an element into the unordered_set.
iterator emplace_hint(const_iterator __pos, _Args &&... __args)
Attempts to insert an element into the unordered_set.
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
void insert(initializer_list< value_type > __l)
Inserts a list of elements into the unordered_multiset.
unordered_multiset()=default
Default constructor.
_Hashtable::difference_type difference_type
Iterator-related typedefs.
const_local_iterator begin(size_type __n) const
Returns a read-only (constant) iterator pointing to the first bucket element.
size_type count(const key_type &__x) const
Finds the number of elements.
void swap(unordered_multiset &__x) noexcept(noexcept(_M_h.swap(__x._M_h)))
Swaps data with another unordered_multiset.
_Hashtable::const_pointer const_pointer
Iterator-related typedefs.
size_type bucket_count() const noexcept
Returns the number of buckets of the unordered_set.
iterator erase(const_iterator __position)
Erases an element from an unordered_set.
void reserve(size_type __n)
Prepare the unordered_set for a specified number of elements.
const_local_iterator cbegin(size_type __n) const
Returns a read-only (constant) iterator pointing to the first bucket element.