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