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.

213 lines
6.2 KiB

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