checkers.h
Go to the documentation of this file.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 #ifndef _GLIBCXX_PARALLEL_CHECKERS_H
00033 #define _GLIBCXX_PARALLEL_CHECKERS_H 1
00034
00035 #include <functional>
00036 #include <cstdio>
00037 #include <bits/stl_algobase.h>
00038
00039 namespace __gnu_parallel
00040 {
00041
00042
00043
00044
00045
00046
00047
00048
00049 template<typename InputIterator, typename Comparator>
00050 bool
00051 is_sorted(InputIterator begin, InputIterator end,
00052 Comparator comp
00053 = std::less<typename std::iterator_traits<InputIterator>::
00054 value_type>())
00055 {
00056 if (begin == end)
00057 return true;
00058
00059 InputIterator current(begin), recent(begin);
00060
00061 unsigned long long position = 1;
00062 for (current++; current != end; current++)
00063 {
00064 if (comp(*current, *recent))
00065 {
00066 printf("is_sorted: check failed before position %i.\n",
00067 position);
00068 return false;
00069 }
00070 recent = current;
00071 position++;
00072 }
00073
00074 return true;
00075 }
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 template<typename InputIterator, typename Comparator>
00088 bool
00089 is_sorted_failure(InputIterator begin, InputIterator end,
00090 InputIterator& first_failure,
00091 Comparator comp
00092 = std::less<typename std::iterator_traits<InputIterator>::
00093 value_type>())
00094 {
00095 if (begin == end)
00096 return true;
00097
00098 InputIterator current(begin), recent(begin);
00099
00100 unsigned long long position = 1;
00101 for (current++; current != end; current++)
00102 {
00103 if (comp(*current, *recent))
00104 {
00105 first_failure = current;
00106 printf("is_sorted: check failed before position %lld.\n",
00107 position);
00108 return false;
00109 }
00110 recent = current;
00111 position++;
00112 }
00113
00114 first_failure = end;
00115 return true;
00116 }
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 template<typename InputIterator, typename Comparator>
00127 bool
00128
00129 is_sorted_print_failures(InputIterator begin, InputIterator end,
00130 Comparator comp
00131 = std::less<typename std::iterator_traits
00132 <InputIterator>::value_type>())
00133 {
00134 if (begin == end)
00135 return true;
00136
00137 InputIterator recent(begin);
00138 bool ok = true;
00139
00140 for (InputIterator pos(begin + 1); pos != end; pos++)
00141 {
00142 if (comp(*pos, *recent))
00143 {
00144 printf("%ld: %d %d %d %d\n", pos - begin, *(pos - 2),
00145 *(pos- 1), *pos, *(pos + 1));
00146 ok = false;
00147 }
00148 recent = pos;
00149 }
00150 return ok;
00151 }
00152 }
00153
00154 #endif