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.

412 lines
10 KiB

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