Leaked source code of windows server 2003
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.

308 lines
10 KiB

  1. // set standard header
  2. #ifndef _SET_
  3. #define _SET_
  4. #include <functional>
  5. #include <xtree>
  6. #ifdef _MSC_VER
  7. #pragma pack(push,8)
  8. #endif /* _MSC_VER */
  9. _STD_BEGIN
  10. // TEMPLATE CLASS set
  11. template<class _K, class _Pr = less<_K>,
  12. class _A = allocator<_K> >
  13. class set {
  14. public:
  15. typedef set<_K, _Pr, _A> _Myt;
  16. typedef _K value_type;
  17. struct _Kfn : public unary_function<value_type, _K> {
  18. const _K& operator()(const value_type& _X) const
  19. {return (_X); }
  20. };
  21. typedef _Pr value_compare;
  22. typedef _K key_type;
  23. typedef _Pr key_compare;
  24. typedef _A allocator_type;
  25. typedef _Tree<_K, value_type, _Kfn, _Pr, _A> _Imp;
  26. typedef typename _Imp::size_type size_type;
  27. typedef typename _Imp::difference_type difference_type;
  28. typedef typename _Imp::reference reference;
  29. typedef typename _Imp::const_reference const_reference;
  30. typedef typename _Imp::iterator iterator;
  31. typedef typename _Imp::const_iterator const_iterator;
  32. typedef typename _Imp::reverse_iterator reverse_iterator;
  33. typedef typename _Imp::const_reverse_iterator const_reverse_iterator;
  34. typedef pair<iterator, bool> _Pairib;
  35. typedef pair<iterator, iterator> _Pairii;
  36. typedef pair<const_iterator, const_iterator> _Paircc;
  37. explicit set(const _Pr& _Pred = _Pr(), const _A& _Al = _A())
  38. : _Tr(_Pred, false, _Al) {}
  39. typedef const value_type *_It;
  40. set(_It _F, _It _L, const _Pr& _Pred = _Pr(),
  41. const _A& _Al = _A())
  42. : _Tr(_Pred, false, _Al)
  43. {for (; _F != _L; ++_F)
  44. _Tr.insert(*_F); }
  45. _Myt& operator=(const _Myt& _X)
  46. {_Tr = _X._Tr;
  47. return (*this); }
  48. iterator begin()
  49. {return (_Tr.begin()); }
  50. const_iterator begin() const
  51. {return (_Tr.begin()); }
  52. iterator end()
  53. {return (_Tr.end()); }
  54. const_iterator end() const
  55. {return (_Tr.end()); }
  56. reverse_iterator rbegin()
  57. {return (_Tr.rbegin()); }
  58. const_reverse_iterator rbegin() const
  59. {return (_Tr.rbegin()); }
  60. reverse_iterator rend()
  61. {return (_Tr.rend()); }
  62. const_reverse_iterator rend() const
  63. {return (_Tr.rend()); }
  64. size_type size() const
  65. {return (_Tr.size()); }
  66. size_type max_size() const
  67. {return (_Tr.max_size()); }
  68. bool empty() const
  69. {return (_Tr.empty()); }
  70. _A get_allocator() const
  71. {return (_Tr.get_allocator()); }
  72. _Pairib insert(const value_type& _X)
  73. {_Imp::_Pairib _Ans = _Tr.insert(_X);
  74. return (_Pairib(_Ans.first, _Ans.second)); }
  75. iterator insert(iterator _P, const value_type& _X)
  76. {return (_Tr.insert((_Imp::iterator&)_P, _X)); }
  77. void insert(_It _F, _It _L)
  78. {for (; _F != _L; ++_F)
  79. _Tr.insert(*_F); }
  80. iterator erase(iterator _P)
  81. {return (_Tr.erase((_Imp::iterator&)_P)); }
  82. iterator erase(iterator _F, iterator _L)
  83. {return (_Tr.erase((_Imp::iterator&)_F,
  84. (_Imp::iterator&)_L)); }
  85. size_type erase(const _K& _Kv)
  86. {return (_Tr.erase(_Kv)); }
  87. void clear()
  88. {_Tr.clear(); }
  89. void swap(_Myt& _X)
  90. {std::swap(_Tr, _X._Tr); }
  91. friend void swap(_Myt& _X, _Myt& _Y)
  92. {_X.swap(_Y); }
  93. key_compare key_comp() const
  94. {return (_Tr.key_comp()); }
  95. value_compare value_comp() const
  96. {return (_Tr.key_comp()); }
  97. const_iterator find(const _K& _Kv) const
  98. {return (_Tr.find(_Kv)); }
  99. iterator find(const _K& _Kv)
  100. {return (_Tr.find(_Kv)); }
  101. size_type count(const _K& _Kv) const
  102. {return (_Tr.count(_Kv)); }
  103. iterator lower_bound(const _K& _Kv)
  104. {return (_Tr.lower_bound(_Kv)); }
  105. const_iterator lower_bound(const _K& _Kv) const
  106. {return (_Tr.lower_bound(_Kv)); }
  107. iterator upper_bound(const _K& _Kv)
  108. {return (_Tr.upper_bound(_Kv)); }
  109. const_iterator upper_bound(const _K& _Kv) const
  110. {return (_Tr.upper_bound(_Kv)); }
  111. _Pairii equal_range(const _K& _Kv)
  112. {return (_Tr.equal_range(_Kv)); }
  113. _Paircc equal_range(const _K& _Kv) const
  114. {return (_Tr.equal_range(_Kv)); }
  115. protected:
  116. _Imp _Tr;
  117. };
  118. // set TEMPLATE OPERATORS
  119. template<class _K, class _Pr, class _A> inline
  120. bool operator==(const set<_K, _Pr, _A>& _X,
  121. const set<_K, _Pr, _A>& _Y)
  122. {return (_X.size() == _Y.size()
  123. && equal(_X.begin(), _X.end(), _Y.begin())); }
  124. template<class _K, class _Pr, class _A> inline
  125. bool operator!=(const set<_K, _Pr, _A>& _X,
  126. const set<_K, _Pr, _A>& _Y)
  127. {return (!(_X == _Y)); }
  128. template<class _K, class _Pr, class _A> inline
  129. bool operator<(const set<_K, _Pr, _A>& _X,
  130. const set<_K, _Pr, _A>& _Y)
  131. {return (lexicographical_compare(_X.begin(), _X.end(),
  132. _Y.begin(), _Y.end())); }
  133. template<class _K, class _Pr, class _A> inline
  134. bool operator>(const set<_K, _Pr, _A>& _X,
  135. const set<_K, _Pr, _A>& _Y)
  136. {return (_Y < _X); }
  137. template<class _K, class _Pr, class _A> inline
  138. bool operator<=(const set<_K, _Pr, _A>& _X,
  139. const set<_K, _Pr, _A>& _Y)
  140. {return (!(_Y < _X)); }
  141. template<class _K, class _Pr, class _A> inline
  142. bool operator>=(const set<_K, _Pr, _A>& _X,
  143. const set<_K, _Pr, _A>& _Y)
  144. {return (!(_X < _Y)); }
  145. // TEMPLATE CLASS multiset
  146. template<class _K, class _Pr = less<_K>,
  147. class _A = allocator<_K> >
  148. class multiset {
  149. public:
  150. typedef multiset<_K, _Pr, _A> _Myt;
  151. typedef _K value_type;
  152. struct _Kfn : public unary_function<value_type, _K> {
  153. const _K& operator()(const value_type& _X) const
  154. {return (_X); }
  155. };
  156. typedef _Pr value_compare;
  157. typedef _K key_type;
  158. typedef _Pr key_compare;
  159. typedef _A allocator_type;
  160. typedef _Tree<_K, value_type, _Kfn, _Pr, _A> _Imp;
  161. typedef typename _Imp::size_type size_type;
  162. typedef typename _Imp::difference_type difference_type;
  163. typedef typename _Imp::reference reference;
  164. typedef typename _Imp::const_reference const_reference;
  165. typedef typename _Imp::iterator iterator;
  166. typedef typename _Imp::const_iterator const_iterator;
  167. typedef typename _Imp::reverse_iterator reverse_iterator;
  168. typedef typename _Imp::const_reverse_iterator const_reverse_iterator;
  169. typedef pair<iterator, iterator> _Pairii;
  170. typedef pair<const_iterator, const_iterator> _Paircc;
  171. explicit multiset(const _Pr& _Pred = _Pr(),
  172. const _A& _Al = _A())
  173. : _Tr(_Pred, true, _Al) {}
  174. typedef const value_type *_It;
  175. multiset(_It _F, _It _L, const _Pr& _Pred = _Pr(),
  176. const _A& _Al = _A())
  177. : _Tr(_Pred, true, _Al)
  178. {for (; _F != _L; ++_F)
  179. _Tr.insert(*_F); }
  180. _Myt& operator=(const _Myt& _X)
  181. {_Tr = _X._Tr;
  182. return (*this); }
  183. iterator begin()
  184. {return (_Tr.begin()); }
  185. const_iterator begin() const
  186. {return (_Tr.begin()); }
  187. iterator end()
  188. {return (_Tr.end()); }
  189. const_iterator end() const
  190. {return (_Tr.end()); }
  191. reverse_iterator rbegin()
  192. {return (_Tr.rbegin()); }
  193. const_reverse_iterator rbegin() const
  194. {return (_Tr.rbegin()); }
  195. reverse_iterator rend()
  196. {return (_Tr.rend()); }
  197. const_reverse_iterator rend() const
  198. {return (_Tr.rend()); }
  199. size_type size() const
  200. {return (_Tr.size()); }
  201. size_type max_size() const
  202. {return (_Tr.max_size()); }
  203. bool empty() const
  204. {return (_Tr.empty()); }
  205. _A get_allocator() const
  206. {return (_Tr.get_allocator()); }
  207. iterator insert(const value_type& _X)
  208. {return (_Tr.insert(_X).first); }
  209. iterator insert(iterator _P, const value_type& _X)
  210. {return (_Tr.insert((_Imp::iterator&)_P, _X)); }
  211. void insert(_It _F, _It _L)
  212. {for (; _F != _L; ++_F)
  213. _Tr.insert(*_F); }
  214. iterator erase(iterator _P)
  215. {return (_Tr.erase((_Imp::iterator&)_P)); }
  216. iterator erase(iterator _F, iterator _L)
  217. {return (_Tr.erase((_Imp::iterator&)_F,
  218. (_Imp::iterator&)_L)); }
  219. size_type erase(const _K& _Kv)
  220. {return (_Tr.erase(_Kv)); }
  221. void clear()
  222. {_Tr.clear(); }
  223. void swap(_Myt& _X)
  224. {std::swap(_Tr, _X._Tr); }
  225. friend void swap(_Myt& _X, _Myt& _Y)
  226. {_X.swap(_Y); }
  227. key_compare key_comp() const
  228. {return (_Tr.key_comp()); }
  229. value_compare value_comp() const
  230. {return (_Tr.key_comp()); }
  231. iterator find(const _K& _Kv)
  232. {return (_Tr.find(_Kv)); }
  233. const_iterator find(const _K& _Kv) const
  234. {return (_Tr.find(_Kv)); }
  235. size_type count(const _K& _Kv) const
  236. {return (_Tr.count(_Kv)); }
  237. iterator lower_bound(const _K& _Kv)
  238. {return (_Tr.lower_bound(_Kv)); }
  239. const_iterator lower_bound(const _K& _Kv) const
  240. {return (_Tr.lower_bound(_Kv)); }
  241. iterator upper_bound(const _K& _Kv)
  242. {return (_Tr.upper_bound(_Kv)); }
  243. const_iterator upper_bound(const _K& _Kv) const
  244. {return (_Tr.upper_bound(_Kv)); }
  245. _Pairii equal_range(const _K& _Kv)
  246. {return (_Tr.equal_range(_Kv)); }
  247. _Paircc equal_range(const _K& _Kv) const
  248. {return (_Tr.equal_range(_Kv)); }
  249. protected:
  250. _Imp _Tr;
  251. };
  252. // multiset TEMPLATE OPERATORS
  253. template<class _K, class _Pr, class _A> inline
  254. bool operator==(const multiset<_K, _Pr, _A>& _X,
  255. const multiset<_K, _Pr, _A>& _Y)
  256. {return (_X.size() == _Y.size()
  257. && equal(_X.begin(), _X.end(), _Y.begin())); }
  258. template<class _K, class _Pr, class _A> inline
  259. bool operator!=(const multiset<_K, _Pr, _A>& _X,
  260. const multiset<_K, _Pr, _A>& _Y)
  261. {return (!(_X == _Y)); }
  262. template<class _K, class _Pr, class _A> inline
  263. bool operator<(const multiset<_K, _Pr, _A>& _X,
  264. const multiset<_K, _Pr, _A>& _Y)
  265. {return (lexicographical_compare(_X.begin(), _X.end(),
  266. _Y.begin(), _Y.end())); }
  267. template<class _K, class _Pr, class _A> inline
  268. bool operator>(const multiset<_K, _Pr, _A>& _X,
  269. const multiset<_K, _Pr, _A>& _Y)
  270. {return (_Y < _X); }
  271. template<class _K, class _Pr, class _A> inline
  272. bool operator<=(const multiset<_K, _Pr, _A>& _X,
  273. const multiset<_K, _Pr, _A>& _Y)
  274. {return (!(_Y < _X)); }
  275. template<class _K, class _Pr, class _A> inline
  276. bool operator>=(const multiset<_K, _Pr, _A>& _X,
  277. const multiset<_K, _Pr, _A>& _Y)
  278. {return (!(_X < _Y)); }
  279. _STD_END
  280. #ifdef _MSC_VER
  281. #pragma pack(pop)
  282. #endif /* _MSC_VER */
  283. #endif /* _SET_ */
  284. /*
  285. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  286. * Consult your license regarding permissions and restrictions.
  287. */
  288. /*
  289. * This file is derived from software bearing the following
  290. * restrictions:
  291. *
  292. * Copyright (c) 1994
  293. * Hewlett-Packard Company
  294. *
  295. * Permission to use, copy, modify, distribute and sell this
  296. * software and its documentation for any purpose is hereby
  297. * granted without fee, provided that the above copyright notice
  298. * appear in all copies and that both that copyright notice and
  299. * this permission notice appear in supporting documentation.
  300. * Hewlett-Packard Company makes no representations about the
  301. * suitability of this software for any purpose. It is provided
  302. * "as is" without express or implied warranty.
  303. */