3 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file parallel/checkers.h
26 * @brief Routines for checking the correctness of algorithm results.
27 * This file is a GNU parallel extension to the Standard C++ Library.
30 // Written by Johannes Singler.
32 #ifndef _GLIBCXX_PARALLEL_CHECKERS_H
33 #define _GLIBCXX_PARALLEL_CHECKERS_H 1
37 #include <bits/stl_algobase.h>
39 namespace __gnu_parallel
42 * @brief Check whether @__c [__begin, @__c __end) is sorted according
44 * @param __begin Begin iterator of sequence.
45 * @param __end End iterator of sequence.
46 * @param __comp Comparator.
47 * @return @__c true if sorted, @__c false otherwise.
49 // XXX Compare default template argument
50 template<typename _IIter, typename _Compare>
52 __is_sorted(_IIter __begin, _IIter __end,
54 = std::less<typename std::iterator_traits<_IIter>::
60 _IIter __current(__begin), __recent(__begin);
62 unsigned long long __position = 1;
63 for (__current++; __current != __end; __current++)
65 if (__comp(*__current, *__recent))
67 printf("__is_sorted: check failed before position %__i.\n",
79 * @brief Check whether @__c [__begin, @__c __end) is sorted according to
81 * Prints the position in case an unordered pair is found.
82 * @param __begin Begin iterator of sequence.
83 * @param __end End iterator of sequence.
84 * @param __first_failure The first failure is returned in this variable.
85 * @param __comp Comparator.
86 * @return @__c true if sorted, @__c false otherwise.
88 // XXX Compare default template argument
89 template<typename _IIter, typename _Compare>
91 is_sorted_failure(_IIter __begin, _IIter __end,
92 _IIter& __first_failure,
94 = std::less<typename std::iterator_traits<_IIter>::
100 _IIter __current(__begin), __recent(__begin);
102 unsigned long long __position = 1;
103 for (__current++; __current != __end; __current++)
105 if (__comp(*__current, *__recent))
107 __first_failure = __current;
108 printf("__is_sorted: check failed before position %lld.\n",
112 __recent = __current;
116 __first_failure = __end;
121 * @brief Check whether @__c [__begin, @__c __end) is sorted according to
123 * Prints all unordered pair, including the surrounding two elements.
124 * @param __begin Begin iterator of sequence.
125 * @param __end End iterator of sequence.
126 * @param __comp Comparator.
127 * @return @__c true if sorted, @__c false otherwise.
129 template<typename _IIter, typename _Compare>
131 // XXX Compare default template argument
132 is_sorted_print_failures(_IIter __begin, _IIter __end,
134 = std::less<typename std::iterator_traits
135 <_IIter>::value_type>())
137 if (__begin == __end)
140 _IIter __recent(__begin);
143 for (_IIter __pos(__begin + 1); __pos != __end; __pos++)
145 if (__comp(*__pos, *__recent))
147 printf("%ld: %d %d %d %d\n", __pos - __begin, *(__pos - 2),
148 *(__pos- 1), *__pos, *(__pos + 1));
157 #endif /* _GLIBCXX_PARALLEL_CHECKERS_H */