00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #ifndef __SGI_STL_COMPAT
00070 #define __SGI_STL_COMPAT
00071
00072
00073 #if defined(__GNUC__)
00074 #define ported_from_sgi std
00075 #else
00076
00077 #include <utility>
00078 #include <algorithm>
00079 #include <iterator>
00080 #include <functional>
00081
00082
00083
00084 #ifdef _MSC_VER
00085
00086
00087 #if _MSC_VER < 1300
00088 namespace std
00089 {
00090 template<class T> const T &min(const T &x, const T &y)
00091 {
00092 if (x<y) return x;
00093 else return y;
00094 }
00095 template<class T> const T &max(const T &x, const T &y)
00096 {
00097 if (x>y) return x;
00098 else return y;
00099 }
00100 };
00101 #endif
00102 #endif
00103
00104 namespace std
00105 {
00106
00107 template <class _ForwardIterator, class _Tp>
00108 void
00109 iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
00110 {
00111 while (__first != __last)
00112 *__first++ = __value++;
00113 }
00114
00115 template <class _Base, class _Integer>
00116 _Base power(_Base __x, _Integer __n)
00117 {
00118 if (__n == 0) return 1;
00119 else {
00120 while ((__n & 1) == 0) {
00121 __n >>= 1;
00122 __x = __x * __x;
00123 }
00124
00125 _Base __result = __x;
00126 __n >>= 1;
00127 while (__n != 0) {
00128 __x = __x * __x;
00129 if ((__n & 1) != 0)
00130 __result = __result * __x;
00131 __n >>= 1;
00132 }
00133 return __result;
00134 }
00135 }
00136
00137
00138
00139 template <class _ForwardIter, class _OutputIter, class _Distance>
00140 _OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
00141 _OutputIter __out, const _Distance __n)
00142 {
00143 _Distance __remaining = __last - __first;
00144 _Distance __m = std::min(__n, __remaining);
00145
00146 while (__m > 0) {
00147 if (__random_number(__remaining) < __m) {
00148 *__out = *__first;
00149 ++__out;
00150 --__m;
00151 }
00152
00153 --__remaining;
00154 ++__first;
00155 }
00156 return __out;
00157 }
00158
00159 template <class _ForwardIter, class _OutputIter, class _Distance,
00160 class _RandomNumberGenerator>
00161 _OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
00162 _OutputIter __out, const _Distance __n,
00163 _RandomNumberGenerator& __rand)
00164 {
00165 _Distance __remaining = __last - __first;
00166 _Distance __m = std::min(__n, __remaining);
00167
00168 while (__m > 0) {
00169 if (__rand(__remaining) < __m) {
00170 *__out = *__first;
00171 ++__out;
00172 --__m;
00173 }
00174
00175 --__remaining;
00176 ++__first;
00177 }
00178 return __out;
00179 }
00180
00181 template <class _InputIter, class _RandomAccessIter, class _Distance>
00182 _RandomAccessIter __random_sample(_InputIter __first, _InputIter __last,
00183 _RandomAccessIter __out,
00184 const _Distance __n)
00185 {
00186 _Distance __m = 0;
00187 _Distance __t = __n;
00188 for ( ; __first != __last && __m < __n; ++__m, ++__first)
00189 __out[__m] = *__first;
00190
00191 while (__first != __last) {
00192 ++__t;
00193 _Distance __M = __random_number(__t);
00194 if (__M < __n)
00195 __out[__M] = *__first;
00196 ++__first;
00197 }
00198
00199 return __out + __m;
00200 }
00201
00202 template <class _InputIter, class _RandomAccessIter,
00203 class _RandomNumberGenerator, class _Distance>
00204 _RandomAccessIter __random_sample(_InputIter __first, _InputIter __last,
00205 _RandomAccessIter __out,
00206 _RandomNumberGenerator& __rand,
00207 const _Distance __n)
00208 {
00209 _Distance __m = 0;
00210 _Distance __t = __n;
00211 for ( ; __first != __last && __m < __n; ++__m, ++__first)
00212 __out[__m] = *__first;
00213
00214 while (__first != __last) {
00215 ++__t;
00216 _Distance __M = __rand(__t);
00217 if (__M < __n)
00218 __out[__M] = *__first;
00219 ++__first;
00220 }
00221
00222 return __out + __m;
00223 }
00224
00225 template <class _InputIter, class _RandomAccessIter>
00226 inline _RandomAccessIter
00227 random_sample(_InputIter __first, _InputIter __last,
00228 _RandomAccessIter __out_first, _RandomAccessIter __out_last)
00229 {
00230 return __random_sample(__first, __last,
00231 __out_first, __out_last - __out_first);
00232 }
00233
00234
00235 template <class _InputIter, class _RandomAccessIter,
00236 class _RandomNumberGenerator>
00237 inline _RandomAccessIter
00238 random_sample(_InputIter __first, _InputIter __last,
00239 _RandomAccessIter __out_first, _RandomAccessIter __out_last,
00240 _RandomNumberGenerator& __rand)
00241 {
00242 return __random_sample(__first, __last,
00243 __out_first, __rand,
00244 __out_last - __out_first);
00245 }
00246
00247
00248 template <class _ForwardIter>
00249 bool is_sorted(_ForwardIter __first, _ForwardIter __last)
00250 {
00251 if (__first == __last)
00252 return true;
00253
00254 _ForwardIter __next = __first;
00255 for (++__next; __next != __last; __first = __next, ++__next) {
00256 if (*__next < *__first)
00257 return false;
00258 }
00259
00260 return true;
00261 }
00262
00263 template <class _ForwardIter, class _StrictWeakOrdering>
00264 bool is_sorted(_ForwardIter __first, _ForwardIter __last,
00265 _StrictWeakOrdering __comp)
00266 {
00267 if (__first == __last)
00268 return true;
00269
00270 _ForwardIter __next = __first;
00271 for (++__next; __next != __last; __first = __next, ++__next) {
00272 if (__comp(*__next, *__first))
00273 return false;
00274 }
00275
00276 return true;
00277 }
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 template <class _Tp>
00295 struct _Identity : public unary_function<_Tp,_Tp>
00296 { const _Tp& operator()(const _Tp& __x) const { return __x; } };
00297
00298 template <class _Tp> struct identity : public _Identity<_Tp> {};
00299
00300
00301 template <class Pair, class U>
00302
00303 struct __select1st_hint : public unary_function<Pair, U>
00304 { const U& operator () (const Pair& x) const { return x.first; } };
00305
00306 template <class Pair>
00307 struct select1st : public unary_function<Pair, typename Pair::first_type>
00308 {
00309 const typename Pair::first_type& operator()(const Pair& x) const
00310 { return x.first; }
00311 };
00312
00313 template <class Pair>
00314 struct select2nd : public unary_function<Pair, typename Pair::second_type>
00315 {
00316 const typename Pair::second_type& operator()(const Pair& x) const
00317 { return x.second; }
00318 };
00319
00320
00321 };
00322
00323 #endif
00324
00325 #endif
00326
00327