unordered_set.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. // TR1 unordered_set implementation -*- C++ -*-
  2. // Copyright (C) 2010-2018 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file tr1/unordered_set.h
  21. * This is an internal header file, included by other library headers.
  22. * Do not attempt to use it directly. @headername{tr1/unordered_set}
  23. */
  24. namespace std _GLIBCXX_VISIBILITY(default)
  25. {
  26. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  27. namespace tr1
  28. {
  29. // NB: When we get typedef templates these class definitions
  30. // will be unnecessary.
  31. template<class _Value,
  32. class _Hash = hash<_Value>,
  33. class _Pred = std::equal_to<_Value>,
  34. class _Alloc = std::allocator<_Value>,
  35. bool __cache_hash_code = false>
  36. class __unordered_set
  37. : public _Hashtable<_Value, _Value, _Alloc,
  38. std::_Identity<_Value>, _Pred,
  39. _Hash, __detail::_Mod_range_hashing,
  40. __detail::_Default_ranged_hash,
  41. __detail::_Prime_rehash_policy,
  42. __cache_hash_code, true, true>
  43. {
  44. typedef _Hashtable<_Value, _Value, _Alloc,
  45. std::_Identity<_Value>, _Pred,
  46. _Hash, __detail::_Mod_range_hashing,
  47. __detail::_Default_ranged_hash,
  48. __detail::_Prime_rehash_policy,
  49. __cache_hash_code, true, true>
  50. _Base;
  51. public:
  52. typedef typename _Base::size_type size_type;
  53. typedef typename _Base::hasher hasher;
  54. typedef typename _Base::key_equal key_equal;
  55. typedef typename _Base::allocator_type allocator_type;
  56. explicit
  57. __unordered_set(size_type __n = 10,
  58. const hasher& __hf = hasher(),
  59. const key_equal& __eql = key_equal(),
  60. const allocator_type& __a = allocator_type())
  61. : _Base(__n, __hf, __detail::_Mod_range_hashing(),
  62. __detail::_Default_ranged_hash(), __eql,
  63. std::_Identity<_Value>(), __a)
  64. { }
  65. template<typename _InputIterator>
  66. __unordered_set(_InputIterator __f, _InputIterator __l,
  67. size_type __n = 10,
  68. const hasher& __hf = hasher(),
  69. const key_equal& __eql = key_equal(),
  70. const allocator_type& __a = allocator_type())
  71. : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
  72. __detail::_Default_ranged_hash(), __eql,
  73. std::_Identity<_Value>(), __a)
  74. { }
  75. };
  76. template<class _Value,
  77. class _Hash = hash<_Value>,
  78. class _Pred = std::equal_to<_Value>,
  79. class _Alloc = std::allocator<_Value>,
  80. bool __cache_hash_code = false>
  81. class __unordered_multiset
  82. : public _Hashtable<_Value, _Value, _Alloc,
  83. std::_Identity<_Value>, _Pred,
  84. _Hash, __detail::_Mod_range_hashing,
  85. __detail::_Default_ranged_hash,
  86. __detail::_Prime_rehash_policy,
  87. __cache_hash_code, true, false>
  88. {
  89. typedef _Hashtable<_Value, _Value, _Alloc,
  90. std::_Identity<_Value>, _Pred,
  91. _Hash, __detail::_Mod_range_hashing,
  92. __detail::_Default_ranged_hash,
  93. __detail::_Prime_rehash_policy,
  94. __cache_hash_code, true, false>
  95. _Base;
  96. public:
  97. typedef typename _Base::size_type size_type;
  98. typedef typename _Base::hasher hasher;
  99. typedef typename _Base::key_equal key_equal;
  100. typedef typename _Base::allocator_type allocator_type;
  101. explicit
  102. __unordered_multiset(size_type __n = 10,
  103. const hasher& __hf = hasher(),
  104. const key_equal& __eql = key_equal(),
  105. const allocator_type& __a = allocator_type())
  106. : _Base(__n, __hf, __detail::_Mod_range_hashing(),
  107. __detail::_Default_ranged_hash(), __eql,
  108. std::_Identity<_Value>(), __a)
  109. { }
  110. template<typename _InputIterator>
  111. __unordered_multiset(_InputIterator __f, _InputIterator __l,
  112. typename _Base::size_type __n = 0,
  113. const hasher& __hf = hasher(),
  114. const key_equal& __eql = key_equal(),
  115. const allocator_type& __a = allocator_type())
  116. : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
  117. __detail::_Default_ranged_hash(), __eql,
  118. std::_Identity<_Value>(), __a)
  119. { }
  120. };
  121. template<class _Value, class _Hash, class _Pred, class _Alloc,
  122. bool __cache_hash_code>
  123. inline void
  124. swap(__unordered_set<_Value, _Hash, _Pred, _Alloc, __cache_hash_code>& __x,
  125. __unordered_set<_Value, _Hash, _Pred, _Alloc, __cache_hash_code>& __y)
  126. { __x.swap(__y); }
  127. template<class _Value, class _Hash, class _Pred, class _Alloc,
  128. bool __cache_hash_code>
  129. inline void
  130. swap(__unordered_multiset<_Value, _Hash, _Pred,
  131. _Alloc, __cache_hash_code>& __x,
  132. __unordered_multiset<_Value, _Hash, _Pred,
  133. _Alloc, __cache_hash_code>& __y)
  134. { __x.swap(__y); }
  135. /**
  136. * @brief A standard container composed of unique keys (containing
  137. * at most one of each key value) in which the elements' keys are
  138. * the elements themselves.
  139. *
  140. * @ingroup unordered_associative_containers
  141. *
  142. * Meets the requirements of a <a href="tables.html#65">container</a>, and
  143. * <a href="tables.html#xx">unordered associative container</a>
  144. *
  145. * @param Value Type of key objects.
  146. * @param Hash Hashing function object type, defaults to hash<Value>.
  147. * @param Pred Predicate function object type, defaults to equal_to<Value>.
  148. * @param Alloc Allocator type, defaults to allocator<Key>.
  149. */
  150. template<class _Value,
  151. class _Hash = hash<_Value>,
  152. class _Pred = std::equal_to<_Value>,
  153. class _Alloc = std::allocator<_Value> >
  154. class unordered_set
  155. : public __unordered_set<_Value, _Hash, _Pred, _Alloc>
  156. {
  157. typedef __unordered_set<_Value, _Hash, _Pred, _Alloc> _Base;
  158. public:
  159. typedef typename _Base::value_type value_type;
  160. typedef typename _Base::size_type size_type;
  161. typedef typename _Base::hasher hasher;
  162. typedef typename _Base::key_equal key_equal;
  163. typedef typename _Base::allocator_type allocator_type;
  164. explicit
  165. unordered_set(size_type __n = 10,
  166. const hasher& __hf = hasher(),
  167. const key_equal& __eql = key_equal(),
  168. const allocator_type& __a = allocator_type())
  169. : _Base(__n, __hf, __eql, __a)
  170. { }
  171. template<typename _InputIterator>
  172. unordered_set(_InputIterator __f, _InputIterator __l,
  173. size_type __n = 10,
  174. const hasher& __hf = hasher(),
  175. const key_equal& __eql = key_equal(),
  176. const allocator_type& __a = allocator_type())
  177. : _Base(__f, __l, __n, __hf, __eql, __a)
  178. { }
  179. };
  180. /**
  181. * @brief A standard container composed of equivalent keys
  182. * (possibly containing multiple of each key value) in which the
  183. * elements' keys are the elements themselves.
  184. *
  185. * @ingroup unordered_associative_containers
  186. *
  187. * Meets the requirements of a <a href="tables.html#65">container</a>, and
  188. * <a href="tables.html#xx">unordered associative container</a>
  189. *
  190. * @param Value Type of key objects.
  191. * @param Hash Hashing function object type, defaults to hash<Value>.
  192. * @param Pred Predicate function object type, defaults to equal_to<Value>.
  193. * @param Alloc Allocator type, defaults to allocator<Key>.
  194. */
  195. template<class _Value,
  196. class _Hash = hash<_Value>,
  197. class _Pred = std::equal_to<_Value>,
  198. class _Alloc = std::allocator<_Value> >
  199. class unordered_multiset
  200. : public __unordered_multiset<_Value, _Hash, _Pred, _Alloc>
  201. {
  202. typedef __unordered_multiset<_Value, _Hash, _Pred, _Alloc> _Base;
  203. public:
  204. typedef typename _Base::value_type value_type;
  205. typedef typename _Base::size_type size_type;
  206. typedef typename _Base::hasher hasher;
  207. typedef typename _Base::key_equal key_equal;
  208. typedef typename _Base::allocator_type allocator_type;
  209. explicit
  210. unordered_multiset(size_type __n = 10,
  211. const hasher& __hf = hasher(),
  212. const key_equal& __eql = key_equal(),
  213. const allocator_type& __a = allocator_type())
  214. : _Base(__n, __hf, __eql, __a)
  215. { }
  216. template<typename _InputIterator>
  217. unordered_multiset(_InputIterator __f, _InputIterator __l,
  218. typename _Base::size_type __n = 0,
  219. const hasher& __hf = hasher(),
  220. const key_equal& __eql = key_equal(),
  221. const allocator_type& __a = allocator_type())
  222. : _Base(__f, __l, __n, __hf, __eql, __a)
  223. { }
  224. };
  225. template<class _Value, class _Hash, class _Pred, class _Alloc>
  226. inline void
  227. swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
  228. unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
  229. { __x.swap(__y); }
  230. template<class _Value, class _Hash, class _Pred, class _Alloc>
  231. inline void
  232. swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
  233. unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
  234. { __x.swap(__y); }
  235. }
  236. _GLIBCXX_END_NAMESPACE_VERSION
  237. }