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 to @c comp.
43 * @param begin Begin iterator of sequence.
44 * @param end End iterator of sequence.
45 * @param comp Comparator.
46 * @return @c true if sorted, @c false otherwise.
48 // XXX Comparator default template argument
49 template<typename InputIterator
, typename Comparator
>
51 is_sorted(InputIterator begin
, InputIterator end
,
53 = std::less
<typename
std::iterator_traits
<InputIterator
>::
59 InputIterator
current(begin
), recent(begin
);
61 unsigned long long position
= 1;
62 for (current
++; current
!= end
; current
++)
64 if (comp(*current
, *recent
))
66 printf("is_sorted: check failed before position %i.\n",
78 * @brief Check whether @c [begin, @c end) is sorted according to @c comp.
79 * Prints the position in case an unordered pair is found.
80 * @param begin Begin iterator of sequence.
81 * @param end End iterator of sequence.
82 * @param first_failure The first failure is returned in this variable.
83 * @param comp Comparator.
84 * @return @c true if sorted, @c false otherwise.
86 // XXX Comparator default template argument
87 template<typename InputIterator
, typename Comparator
>
89 is_sorted_failure(InputIterator begin
, InputIterator end
,
90 InputIterator
& first_failure
,
92 = std::less
<typename
std::iterator_traits
<InputIterator
>::
98 InputIterator
current(begin
), recent(begin
);
100 unsigned long long position
= 1;
101 for (current
++; current
!= end
; current
++)
103 if (comp(*current
, *recent
))
105 first_failure
= current
;
106 printf("is_sorted: check failed before position %lld.\n",
119 * @brief Check whether @c [begin, @c end) is sorted according to @c comp.
120 * Prints all unordered pair, including the surrounding two elements.
121 * @param begin Begin iterator of sequence.
122 * @param end End iterator of sequence.
123 * @param comp Comparator.
124 * @return @c true if sorted, @c false otherwise.
126 template<typename InputIterator
, typename Comparator
>
128 // XXX Comparator default template argument
129 is_sorted_print_failures(InputIterator begin
, InputIterator end
,
131 = std::less
<typename
std::iterator_traits
132 <InputIterator
>::value_type
>())
137 InputIterator
recent(begin
);
140 for (InputIterator
pos(begin
+ 1); pos
!= end
; pos
++)
142 if (comp(*pos
, *recent
))
144 printf("%ld: %d %d %d %d\n", pos
- begin
, *(pos
- 2),
145 *(pos
- 1), *pos
, *(pos
+ 1));
154 #endif /* _GLIBCXX_PARALLEL_CHECKERS_H */