Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
6.2 KiB

  1. // hash_set standard header
  2. #pragma once
  3. #ifndef _HASH_SET_
  4. #define _HASH_SET_
  5. #include <xhash>
  6. #pragma pack(push,8)
  7. #pragma warning(push,3)
  8. _STD_BEGIN
  9. // TEMPLATE CLASS _Hset_traits
  10. template<class _Kty, // key type (same as value type)
  11. class _Tr, // comparator predicate type
  12. class _Alloc, // actual allocator type (should be value allocator)
  13. bool _Mfl> // true if multiple equivalent keys are permitted
  14. class _Hset_traits
  15. { // traits required to make _Hash behave like a set
  16. public:
  17. typedef _Kty key_type;
  18. typedef _Kty value_type;
  19. typedef _Tr key_compare;
  20. typedef typename _Alloc::_TEMPLATE_MEMBER rebind<value_type>::other
  21. allocator_type;
  22. enum
  23. { // make multi parameter visible as an enum constant
  24. _Multi = _Mfl};
  25. _Hset_traits()
  26. : comp()
  27. { // construct with default comparator
  28. }
  29. _Hset_traits(const _Tr& _Traits)
  30. : comp(_Traits)
  31. { // construct with specified comparator
  32. }
  33. typedef key_compare value_compare;
  34. static const _Kty& _Kfn(const value_type& _Val)
  35. { // return entire value as key
  36. return (_Val);
  37. }
  38. _Tr comp; // the comparator predicate for keys
  39. };
  40. // TEMPLATE CLASS hash_set
  41. template<class _Kty,
  42. class _Tr = hash_compare<_Kty, less<_Kty> >,
  43. class _Alloc = allocator<_Kty> >
  44. class hash_set
  45. : public _Hash<_Hset_traits<_Kty, _Tr, _Alloc, false> >
  46. { // hash table of key values, unique keys
  47. public:
  48. typedef hash_set<_Kty, _Tr, _Alloc> _Myt;
  49. typedef _Hash<_Hset_traits<_Kty, _Tr, _Alloc, false> > _Mybase;
  50. typedef _Kty key_type;
  51. typedef _Tr key_compare;
  52. typedef typename _Mybase::value_compare value_compare;
  53. typedef typename _Mybase::allocator_type allocator_type;
  54. typedef typename _Mybase::size_type size_type;
  55. typedef typename _Mybase::difference_type difference_type;
  56. typedef typename _Mybase::pointer pointer;
  57. typedef typename _Mybase::const_pointer const_pointer;
  58. typedef typename _Mybase::reference reference;
  59. typedef typename _Mybase::const_reference const_reference;
  60. typedef typename _Mybase::iterator iterator;
  61. typedef typename _Mybase::const_iterator const_iterator;
  62. typedef typename _Mybase::reverse_iterator reverse_iterator;
  63. typedef typename _Mybase::const_reverse_iterator
  64. const_reverse_iterator;
  65. typedef typename _Mybase::value_type value_type;
  66. hash_set()
  67. : _Mybase(key_compare(), allocator_type())
  68. { // construct empty set from defaults
  69. }
  70. explicit hash_set(const key_compare& _Traits)
  71. : _Mybase(_Traits, allocator_type())
  72. { // construct empty set from comparator
  73. }
  74. hash_set(const key_compare& _Traits, const allocator_type& _Al)
  75. : _Mybase(_Traits, _Al)
  76. { // construct empty set from comparator and allocator
  77. }
  78. template<class _Iter>
  79. hash_set(_Iter _First, _Iter _Last)
  80. : _Mybase(key_compare(), allocator_type())
  81. { // construct set from sequence, defaults
  82. for (; _First != _Last; ++_First)
  83. this->insert(*_First);
  84. }
  85. template<class _Iter>
  86. hash_set(_Iter _First, _Iter _Last, const key_compare& _Traits)
  87. : _Mybase(_Traits, allocator_type())
  88. { // construct set from sequence, comparator
  89. for (; _First != _Last; ++_First)
  90. this->insert(*_First);
  91. }
  92. template<class _Iter>
  93. hash_set(_Iter _First, _Iter _Last, const key_compare& _Traits,
  94. const allocator_type& _Al)
  95. : _Mybase(_Traits, _Al)
  96. { // construct set from sequence, comparator, and allocator
  97. for (; _First != _Last; ++_First)
  98. this->insert(*_First);
  99. }
  100. };
  101. // TEMPLATE CLASS hash_multiset
  102. template<class _Kty,
  103. class _Tr = hash_compare<_Kty, less<_Kty> >,
  104. class _Alloc = allocator<_Kty> >
  105. class hash_multiset
  106. : public _Hash<_Hset_traits<_Kty, _Tr, _Alloc, true> >
  107. { // hash table of key values, non-unique keys
  108. public:
  109. typedef hash_multiset<_Kty, _Tr, _Alloc> _Myt;
  110. typedef _Hash<_Hset_traits<_Kty, _Tr, _Alloc, true> > _Mybase;
  111. typedef _Kty key_type;
  112. typedef _Tr key_compare;
  113. typedef typename _Mybase::value_compare value_compare;
  114. typedef typename _Mybase::allocator_type allocator_type;
  115. typedef typename _Mybase::size_type size_type;
  116. typedef typename _Mybase::difference_type difference_type;
  117. typedef typename _Mybase::pointer pointer;
  118. typedef typename _Mybase::const_pointer const_pointer;
  119. typedef typename _Mybase::reference reference;
  120. typedef typename _Mybase::const_reference const_reference;
  121. typedef typename _Mybase::iterator iterator;
  122. typedef typename _Mybase::const_iterator const_iterator;
  123. typedef typename _Mybase::reverse_iterator reverse_iterator;
  124. typedef typename _Mybase::const_reverse_iterator
  125. const_reverse_iterator;
  126. typedef typename _Mybase::value_type value_type;
  127. hash_multiset()
  128. : _Mybase(key_compare(), allocator_type())
  129. { // construct empty set from defaults
  130. }
  131. explicit hash_multiset(const key_compare& _Traits)
  132. : _Mybase(_Traits, allocator_type())
  133. { // construct empty set from comparator
  134. }
  135. hash_multiset(const key_compare& _Traits,
  136. const allocator_type& _Al)
  137. : _Mybase(_Traits, _Al)
  138. { // construct empty set from comparator and allocator
  139. }
  140. template<class _Iter>
  141. hash_multiset(_Iter _First, _Iter _Last)
  142. : _Mybase(key_compare(), allocator_type())
  143. { // construct from sequence, defaults
  144. for (; _First != _Last; ++_First)
  145. this->insert(*_First);
  146. }
  147. template<class _Iter>
  148. hash_multiset(_Iter _First, _Iter _Last, const key_compare& _Traits)
  149. : _Mybase(_Traits, allocator_type())
  150. { // construct from sequence, comparator
  151. for (; _First != _Last; ++_First)
  152. this->insert(*_First);
  153. }
  154. template<class _Iter>
  155. hash_multiset(_Iter _First, _Iter _Last, const key_compare& _Traits,
  156. const allocator_type& _Al)
  157. : _Mybase(_Traits, _Al)
  158. { // construct from sequence, comparator, and allocator
  159. for (; _First != _Last; ++_First)
  160. this->insert(*_First);
  161. }
  162. iterator insert(const value_type& _Val)
  163. { // insert a key value
  164. return (_Mybase::insert(_Val).first);
  165. }
  166. iterator insert(iterator _Where, const value_type& _Val)
  167. { // insert a key value, with hint
  168. return (_Mybase::insert(_Where, _Val));
  169. }
  170. template<class _Iter>
  171. void insert(_Iter _First, _Iter _Last)
  172. { // insert [_First, _Last), arbitrary iterators
  173. for (; _First != _Last; ++_First)
  174. insert(*_First);
  175. }
  176. };
  177. _STD_END
  178. #pragma warning(pop)
  179. #pragma pack(pop)
  180. #endif /* _HASH_SET_ */
  181. /*
  182. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  183. * Consult your license regarding permissions and restrictions.
  184. V3.10:0009 */