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,
64 __detail::_Mod_range_hashing,
65 __detail::_Default_ranged_hash,
66 __detail::_Prime_rehash_policy, _Tr>;
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;
145 const hasher& __hf =
hasher(),
148 : _M_h(__n, __hf, __eql, __a)
164 template<
typename _InputIterator>
167 const hasher& __hf =
hasher(),
170 : _M_h(__first, __last, __n, __hf, __eql, __a)
194 const allocator_type& __a)
195 : _M_h(__uset._M_h, __a)
204 const allocator_type& __a)
205 : _M_h(std::move(__uset._M_h), __a)
221 const hasher& __hf =
hasher(),
224 : _M_h(__l, __n, __hf, __eql, __a)
232 const allocator_type& __a)
236 template<
typename _InputIterator>
239 const allocator_type& __a)
243 template<
typename _InputIterator>
245 size_type __n,
const hasher& __hf,
246 const allocator_type& __a)
252 const allocator_type& __a)
257 size_type __n,
const hasher& __hf,
258 const allocator_type& __a)
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)); }
448 insert(const_iterator __hint,
const value_type& __x)
449 {
return _M_h.insert(__hint, __x); }
452 insert(const_iterator __hint, value_type&& __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 484 extract(const_iterator __pos)
486 __glibcxx_assert(__pos !=
end());
487 return _M_h.extract(__pos);
492 extract(
const key_type& __key)
493 {
return _M_h.extract(__key); }
498 {
return _M_h._M_reinsert_node(std::move(__nh)); }
502 insert(const_iterator, node_type&& __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); }
561 erase(const_iterator __first, const_iterator __last)
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>
605 template<
typename _H2,
typename _P2>
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>
625 {
return _M_h.hash_function(); }
631 {
return _M_h.key_eq(); }
649 {
return _M_h.find(__x); }
652 find(
const key_type& __x)
const 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(); }
705 bucket_size(size_type __n)
const 706 {
return _M_h.bucket_size(__n); }
714 bucket(
const key_type& __key)
const 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,
841 typedef typename _Hashtable::hasher
hasher;
860 #if __cplusplus > 201402L 861 using node_type =
typename _Hashtable::node_type;
878 const hasher& __hf =
hasher(),
881 : _M_h(__n, __hf, __eql, __a)
897 template<
typename _InputIterator>
900 const hasher& __hf =
hasher(),
903 : _M_h(__first, __last, __n, __hf, __eql, __a)
925 const hasher& __hf =
hasher(),
928 : _M_h(__l, __n, __hf, __eql, __a)
954 const allocator_type& __a)
955 : _M_h(__umset._M_h, __a)
964 const allocator_type& __a)
965 : _M_h(std::move(__umset._M_h), __a)
973 const allocator_type& __a)
977 template<
typename _InputIterator>
980 const allocator_type& __a)
984 template<
typename _InputIterator>
986 size_type __n,
const hasher& __hf,
987 const allocator_type& __a)
993 const allocator_type& __a)
998 size_type __n,
const hasher& __hf,
999 const allocator_type& __a)
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)); }
1160 insert(const_iterator __hint,
const value_type& __x)
1161 {
return _M_h.insert(__hint, __x); }
1164 insert(const_iterator __hint, value_type&& __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 1195 extract(const_iterator __pos)
1197 __glibcxx_assert(__pos !=
end());
1198 return _M_h.extract(__pos);
1203 extract(
const key_type& __key)
1204 {
return _M_h.extract(__key); }
1209 {
return _M_h._M_reinsert_node_multi(
cend(), std::move(__nh)); }
1213 insert(const_iterator __hint, node_type&& __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); }
1276 erase(const_iterator __first, const_iterator __last)
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>
1320 { merge(__source); }
1322 template<
typename _H2,
typename _P2>
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>
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(); }
1417 bucket_size(size_type __n)
const 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); }
1440 const_local_iterator
1442 {
return _M_h.begin(__n); }
1444 const_local_iterator
1446 {
return _M_h.cbegin(__n); }
1458 {
return _M_h.end(__n); }
1460 const_local_iterator
1462 {
return _M_h.end(__n); }
1464 const_local_iterator
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>
1523 noexcept(noexcept(__x.
swap(__y)))
1526 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1530 noexcept(noexcept(__x.
swap(__y)))
1533 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1537 {
return __x._M_h._M_equal(__y._M_h); }
1539 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1543 {
return !(__x == __y); }
1545 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
1549 {
return __x._M_h._M_equal(__y._M_h); }
1551 template<
class _Value,
class _Hash,
class _Pred,
class _Alloc>
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>
1577 {
return __set._M_h; }
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<
1592 template<
typename... _Tp>
1593 using unordered_set = _GLIBCXX_STD_C::unordered_set<_Tp...>;
1594 template<
typename... _Tp>
1601 {
return __set._M_h; }
1605 {
return __set._M_h; }
1607 _GLIBCXX_END_NAMESPACE_VERSION
One of the comparison functors.
float load_factor() const noexcept
Returns the average number of elements per bucket.
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::const_pointer const_pointer
Iterator-related typedefs.
iterator insert(value_type &&__x)
Inserts an element into the unordered_multiset.
size_type bucket_count() const noexcept
Returns the number of buckets of the unordered_set.
hasher hash_function() const
Returns the hash functor object with which the unordered_set was constructed.
const_local_iterator cend(size_type __n) const
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
_Hashtable::const_local_iterator const_local_iterator
Iterator-related typedefs.
_Hashtable::const_reference const_reference
Iterator-related typedefs.
const_iterator cbegin() const noexcept
size_type size() const noexcept
Returns the size of the unordered_set.
_Hashtable::reference reference
Iterator-related typedefs.
The standard allocator, as per [20.4].
iterator find(const key_type &__x)
Tries to locate an element in an unordered_multiset.
_Hashtable::hasher hasher
Public typedefs.
const_iterator cend() const noexcept
iterator begin() noexcept
_Hashtable::key_type key_type
Public typedefs.
const_iterator cend() const noexcept
iterator insert(const_iterator __hint, const value_type &__x)
Inserts an element into the unordered_multiset.
float max_load_factor() const noexcept
Returns a positive number that the unordered_multiset tries to keep the load factor less than or equa...
Default ranged hash function H. In principle it should be a function object composed from objects of ...
_Hashtable::hasher hasher
Public typedefs.
size_type max_bucket_count() const noexcept
Returns the maximum number of buckets of the unordered_multiset.
void insert(_InputIterator __first, _InputIterator __last)
A template function that inserts a range of elements.
_Hashtable::const_iterator const_iterator
Iterator-related typedefs.
size_type size() const noexcept
Returns the size of the unordered_multiset.
local_iterator end(size_type __n)
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
_Hashtable::const_pointer const_pointer
Iterator-related typedefs.
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.
void insert(_InputIterator __first, _InputIterator __last)
A template function that attempts to insert a range of elements.
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.
_Hashtable::local_iterator local_iterator
Iterator-related typedefs.
iterator insert(const_iterator __hint, value_type &&__x)
Attempts to insert an element into the unordered_set.
unordered_set()=default
Default constructor.
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...
A standard container composed of equivalent keys (possibly containing multiple of each key value) in ...
_Hashtable::key_equal key_equal
Public typedefs.
void insert(initializer_list< value_type > __l)
Inserts a list of elements into the unordered_multiset.
hasher hash_function() const
Returns the hash functor object with which the unordered_multiset was constructed.
iterator emplace_hint(const_iterator __pos, _Args &&...__args)
Inserts an element into the unordered_multiset.
const_iterator find(const key_type &__x) const
Tries to locate an element in an unordered_multiset.
std::pair< iterator, bool > emplace(_Args &&...__args)
Attempts to build and insert an element into the unordered_set.
const_iterator begin() const noexcept
const_local_iterator cbegin(size_type __n) const
Returns a read-only (constant) iterator pointing to the first bucket element.
const_local_iterator begin(size_type __n) const
Returns a read-only (constant) iterator pointing to the first bucket element.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
local_iterator begin(size_type __n)
Returns a read-only (constant) iterator pointing to the first bucket element.
iterator emplace(_Args &&...__args)
Builds and insert an element into the unordered_multiset.
iterator erase(const_iterator __first, const_iterator __last)
Erases a [__first,__last) range of elements from an unordered_set.
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.
_Hashtable::allocator_type allocator_type
Public typedefs.
iterator erase(iterator __position)
Erases an element from an unordered_multiset.
_Hashtable::difference_type difference_type
Iterator-related typedefs.
iterator erase(const_iterator __position)
Erases an element from an unordered_multiset.
_Hashtable::key_type key_type
Public typedefs.
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.
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
ISO C++ entities toplevel namespace is std.
void insert(initializer_list< value_type > __l)
Attempts to insert a list of elements into the unordered_set.
iterator insert(const value_type &__x)
Inserts an element into the unordered_multiset.
iterator begin() noexcept
_Hashtable::pointer pointer
Iterator-related typedefs.
_Hashtable::value_type value_type
Public typedefs.
const_local_iterator end(size_type __n) const
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
iterator find(const key_type &__x)
Tries to locate an element in an unordered_set.
void rehash(size_type __n)
May rehash the unordered_set.
const_local_iterator begin(size_type __n) const
Returns a read-only (constant) iterator pointing to the first bucket element.
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::size_type size_type
Iterator-related typedefs.
_Hashtable::reference reference
Iterator-related typedefs.
_Hashtable::iterator iterator
Iterator-related typedefs.
size_type erase(const key_type &__x)
Erases elements according to the provided key.
key_equal key_eq() const
Returns the key comparison object with which the unordered_set was constructed.
unordered_set & operator=(initializer_list< value_type > __l)
Unordered_set list assignment operator.
void max_load_factor(float __z)
Change the unordered_set maximum load factor.
_Hashtable::value_type value_type
Public typedefs.
local_iterator end(size_type __n)
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
const_iterator find(const key_type &__x) const
Tries to locate an element in an unordered_set.
_Hashtable::const_iterator const_iterator
Iterator-related typedefs.
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
size_type max_size() const noexcept
Returns the maximum size of the unordered_multiset.
bool empty() const noexcept
Returns true if the unordered_set is empty.
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.
Struct holding two objects of arbitrary type.
_Hashtable::iterator iterator
Iterator-related typedefs.
iterator emplace_hint(const_iterator __pos, _Args &&...__args)
Attempts to insert an element into the unordered_set.
Default value for rehash policy. Bucket size is (usually) the smallest prime that keeps the load fact...
void max_load_factor(float __z)
Change the unordered_multiset maximum load factor.
const_iterator begin() const noexcept
local_iterator begin(size_type __n)
Returns a read-only (constant) iterator pointing to the first bucket element.
unordered_set & operator=(const unordered_set &)=default
Copy assignment operator.
void reserve(size_type __n)
Prepare the unordered_set for a specified number of elements.
_Hashtable::pointer pointer
Iterator-related typedefs.
void swap(unordered_multiset &__x) noexcept(noexcept(_M_h.swap(__x._M_h)))
Swaps data with another unordered_multiset.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
iterator erase(iterator __position)
Erases an element from an unordered_set.
const_local_iterator end(size_type __n) const
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
const_iterator end() const noexcept
_Hashtable::const_local_iterator const_local_iterator
Iterator-related typedefs.
size_type max_bucket_count() const noexcept
Returns the maximum number of buckets of the unordered_set.
_Hashtable::local_iterator local_iterator
Iterator-related typedefs.
bool empty() const noexcept
Returns true if the unordered_multiset is empty.
unordered_set(const allocator_type &__a)
Creates an unordered_set with no elements.
Default range hashing function: use division to fold a large number into the range [0...
iterator insert(const_iterator __hint, const value_type &__x)
Attempts to insert an element into the unordered_set.
_Hashtable::const_reference const_reference
Iterator-related typedefs.
allocator_type get_allocator() const noexcept
Returns the allocator object used by the unordered_multiset.
size_type count(const key_type &__x) const
Finds the number of elements.
allocator_type get_allocator() const noexcept
Returns the allocator object used by the unordered_set.
void swap(unordered_set &__x) noexcept(noexcept(_M_h.swap(__x._M_h)))
Swaps data with another unordered_set.
size_type count(const key_type &__x) const
Finds the number of elements.
_Hashtable::difference_type difference_type
Iterator-related typedefs.
size_type max_size() const noexcept
Returns the maximum size of the unordered_set.
_Hashtable::key_equal key_equal
Public typedefs.
void rehash(size_type __n)
May rehash the unordered_multiset.
std::pair< iterator, bool > insert(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.
const_iterator end() const noexcept
key_equal key_eq() const
Returns the key comparison object with which the unordered_multiset was constructed.
const_iterator cbegin() const noexcept
size_type erase(const key_type &__x)
Erases elements according to the provided key.
Primary class template hash.
A standard container composed of unique keys (containing at most one of each key value) in which the ...
const_local_iterator cend(size_type __n) const
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
_Hashtable::allocator_type allocator_type
Public typedefs.
_Hashtable::size_type size_type
Iterator-related typedefs.
unordered_multiset & operator=(initializer_list< value_type > __l)
Unordered_multiset list assignment operator.
iterator erase(const_iterator __first, const_iterator __last)
Erases a [__first,__last) range of elements from an unordered_multiset.
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.
std::pair< iterator, bool > insert(const value_type &__x)
Attempts to insert an element into the unordered_set.
iterator erase(const_iterator __position)
Erases an element from an unordered_set.
iterator insert(const_iterator __hint, value_type &&__x)
Inserts an element into the unordered_multiset.