Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
4 * Hewlett-Packard Company
6 * Copyright (c) 1996,1997
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
18 * Permission to use or copy this software for any purpose is hereby granted
19 * without fee, provided the above notices are retained on all copies.
20 * Permission to modify the code and to distribute modified code is granted,
21 * provided the above notices are retained, and a notice that the code was
22 * modified is included with the above copyright notice.
25 #ifndef _STLP_ALGOBASE_C
26 #define _STLP_ALGOBASE_C
28 # if !defined (_STLP_INTERNAL_ALGOBASE_H)
29 # include <stl/_algobase.h>
34 template <class _InputIter1, class _InputIter2>
35 bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
36 _InputIter2 __first2, _InputIter2 __last2) {
37 _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
38 _STLP_DEBUG_CHECK(__check_range(__first2, __last2))
39 for ( ; __first1 != __last1 && __first2 != __last2
40 ; ++__first1, ++__first2) {
41 if (*__first1 < *__first2)
43 if (*__first2 < *__first1)
46 return __first1 == __last1 && __first2 != __last2;
49 template <class _InputIter1, class _InputIter2, class _Compare>
50 bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
51 _InputIter2 __first2, _InputIter2 __last2,
53 _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
54 _STLP_DEBUG_CHECK(__check_range(__first2, __last2))
55 for ( ; __first1 != __last1 && __first2 != __last2
56 ; ++__first1, ++__first2) {
57 if (__comp(*__first1, *__first2))
59 if (__comp(*__first2, *__first1))
62 return __first1 == __last1 && __first2 != __last2;
65 # ifndef _STLP_NO_EXTENSIONS
67 template <class _InputIter1, class _InputIter2>
68 int __lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
69 _InputIter2 __first2, _InputIter2 __last2)
71 while (__first1 != __last1 && __first2 != __last2) {
72 if (*__first1 < *__first2)
74 if (*__first2 < *__first1)
79 if (__first2 == __last2) {
80 return !(__first1 == __last1);
88 template <class _InputIter1, class _InputIter2>
89 int lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
90 _InputIter2 __first2, _InputIter2 __last2)
92 _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
93 _STLP_DEBUG_CHECK(__check_range(__first2, __last2))
94 return __lexicographical_compare_3way(__first1, __last1, __first2, __last2);
98 template <class _RandomAccessIter, class _Tp>
99 _STLP_INLINE_LOOP _RandomAccessIter __find(_RandomAccessIter __first, _RandomAccessIter __last,
101 const random_access_iterator_tag &)
103 _STLP_DIFFERENCE_TYPE(_RandomAccessIter) __trip_count = (__last - __first) >> 2;
105 for ( ; __trip_count > 0 ; --__trip_count) {
106 if (*__first == __val) return __first;
109 if (*__first == __val) return __first;
112 if (*__first == __val) return __first;
115 if (*__first == __val) return __first;
119 switch(__last - __first) {
121 if (*__first == __val) return __first;
124 if (*__first == __val) return __first;
127 if (*__first == __val) return __first;
135 template <class _RandomAccessIter, class _Predicate>
136 _STLP_INLINE_LOOP _RandomAccessIter __find_if(_RandomAccessIter __first, _RandomAccessIter __last,
138 const random_access_iterator_tag &)
140 _STLP_DIFFERENCE_TYPE(_RandomAccessIter) __trip_count = (__last - __first) >> 2;
142 for ( ; __trip_count > 0 ; --__trip_count) {
143 if (__pred(*__first)) return __first;
146 if (__pred(*__first)) return __first;
149 if (__pred(*__first)) return __first;
152 if (__pred(*__first)) return __first;
156 switch(__last - __first) {
158 if (__pred(*__first)) return __first;
161 if (__pred(*__first)) return __first;
164 if (__pred(*__first)) return __first;
172 template <class _InputIter, class _Tp>
173 inline _InputIter __find(_InputIter __first, _InputIter __last,
175 const input_iterator_tag &)
177 while (__first != __last && !(*__first == __val))
182 template <class _InputIter, class _Predicate>
183 inline _InputIter __find_if(_InputIter __first, _STLP_MPW_EXTRA_CONST _InputIter __last,
185 const input_iterator_tag &)
187 while (__first != __last && !__pred(*__first))
192 template <class _InputIter, class _Predicate>
193 _InputIter find_if(_InputIter __first, _InputIter __last,
195 _STLP_DEBUG_CHECK(__check_range(__first, __last))
196 return __find_if(__first, __last, __pred, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
199 template <class _InputIter, class _Tp>
200 _InputIter find(_InputIter __first, _InputIter __last, const _Tp& __val)
202 _STLP_DEBUG_CHECK(__check_range(__first, __last))
203 return __find(__first, __last, __val, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
206 template <class _ForwardIter1, class _ForwardIter2, class _BinaryPred>
207 _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
208 _ForwardIter2 __first2, _ForwardIter2 __last2,
209 _BinaryPred __predicate)
211 _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
212 _STLP_DEBUG_CHECK(__check_range(__first2, __last2))
213 // Test for empty ranges
214 if (__first1 == __last1 || __first2 == __last2)
217 // Test for a pattern of length 1.
218 _ForwardIter2 __tmp(__first2);
220 if (__tmp == __last2) {
221 while (__first1 != __last1 && !__predicate(*__first1, *__first2))
228 _ForwardIter2 __p1, __p;
230 __p1 = __first2; ++__p1;
232 // _ForwardIter1 __current = __first1;
234 while (__first1 != __last1) {
235 while (__first1 != __last1) {
236 if (__predicate(*__first1, *__first2))
240 while (__first1 != __last1 && !__predicate(*__first1, *__first2))
242 if (__first1 == __last1)
246 _ForwardIter1 __current = __first1;
247 if (++__current == __last1) return __last1;
249 while (__predicate(*__current, *__p)) {
250 if (++__p == __last2)
252 if (++__current == __last1)
261 // find_first_of, with and without an explicitly supplied comparison function.
263 template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
264 _InputIter __find_first_of(_InputIter __first1, _InputIter __last1,
265 _ForwardIter __first2, _ForwardIter __last2,
266 _BinaryPredicate __comp) {
267 for ( ; __first1 != __last1; ++__first1)
268 for (_ForwardIter __iter = __first2; __iter != __last2; ++__iter)
269 if (__comp(*__first1, *__iter))
275 // find_end, with and without an explicitly supplied comparison function.
276 // Search [first2, last2) as a subsequence in [first1, last1), and return
277 // the *last* possible match. Note that find_end for bidirectional iterators
278 // is much faster than for forward iterators.
280 // find_end for forward iterators.
282 template <class _ForwardIter1, class _ForwardIter2,
283 class _BinaryPredicate>
284 _ForwardIter1 __find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
285 _ForwardIter2 __first2, _ForwardIter2 __last2,
286 const forward_iterator_tag &, const forward_iterator_tag &,
287 _BinaryPredicate __comp)
289 if (__first2 == __last2)
292 _ForwardIter1 __result = __last1;
294 _ForwardIter1 __new_result
295 = search(__first1, __last1, __first2, __last2, __comp);
296 if (__new_result == __last1)
299 __result = __new_result;
300 __first1 = __new_result;
307 // find_end for bidirectional iterators. Requires partial specialization.
308 #if defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION )
310 #if ! defined (_STLP_INTERNAL_ITERATOR_H)
312 # include <stl/_iterator.h>
313 _STLP_BEGIN_NAMESPACE
316 template <class _BidirectionalIter1, class _BidirectionalIter2,
317 class _BinaryPredicate>
319 __find_end(_BidirectionalIter1 __first1, _BidirectionalIter1 __last1,
320 _BidirectionalIter2 __first2, _BidirectionalIter2 __last2,
321 const bidirectional_iterator_tag &, const bidirectional_iterator_tag &,
322 _BinaryPredicate __comp)
324 typedef reverse_iterator<_BidirectionalIter1> _RevIter1;
325 typedef reverse_iterator<_BidirectionalIter2> _RevIter2;
327 _RevIter1 __rlast1(__first1);
328 _RevIter2 __rlast2(__first2);
329 _RevIter1 __rresult = search(_RevIter1(__last1), __rlast1,
330 _RevIter2(__last2), __rlast2,
333 if (__rresult == __rlast1)
336 _BidirectionalIter1 __result = __rresult.base();
337 advance(__result, -distance(__first2, __last2));
341 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
343 template <class _ForwardIter1, class _ForwardIter2,
344 class _BinaryPredicate>
346 find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
347 _ForwardIter2 __first2, _ForwardIter2 __last2,
348 _BinaryPredicate __comp)
350 _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
351 _STLP_DEBUG_CHECK(__check_range(__first2, __last2))
352 return __find_end(__first1, __last1, __first2, __last2,
353 # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
354 _STLP_ITERATOR_CATEGORY(__first1, _ForwardIter1),
355 _STLP_ITERATOR_CATEGORY(__first2, _ForwardIter2),
357 forward_iterator_tag(),
358 forward_iterator_tag(),
363 template <class _ForwardIter, class _Tp, class _Compare, class _Distance>
364 _ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last,
365 const _Tp& __val, _Compare __comp, _Distance*)
367 _Distance __len = distance(__first, __last);
369 _ForwardIter __middle;
374 advance(__middle, __half);
375 if (__comp(*__middle, __val)) {
378 __len = __len - __half - 1;
388 #endif /* _STLP_ALGOBASE_C */