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 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027
00028
00029 #include "Array.h"
00030 #include "Array.cc"
00031 #define INLINE_ASCENDING_SORT
00032 #define INLINE_DESCENDING_SORT
00033 #include "oct-sort.cc"
00034
00035
00036
00037 template<bool desc>
00038 static void do_bool_partition (bool *data, octave_idx_type nel)
00039 {
00040 octave_idx_type k = 0;
00041 for (octave_idx_type i = 0; i < nel; i++)
00042 if (data[i] == desc)
00043 data[k++] = desc;
00044 for (octave_idx_type i = k; i < nel; i++)
00045 data[i] = ! desc;
00046 }
00047
00048 template<bool desc>
00049 static void do_bool_partition (bool *data, octave_idx_type *idx,
00050 octave_idx_type nel)
00051 {
00052
00053
00054 OCTAVE_LOCAL_BUFFER (octave_idx_type, jdx, nel);
00055 octave_idx_type k = 0, l = 0;
00056 for (octave_idx_type i = 0; i < nel; i++)
00057 {
00058 if (data[i] == desc)
00059 {
00060 data[k] = desc;
00061 idx[k++] = idx[i];
00062 }
00063 else
00064 jdx[l++] = idx[i];
00065 }
00066
00067 for (octave_idx_type i = k; i < nel; i++)
00068 {
00069 data[i] = ! desc;
00070 idx[i] = jdx[i-k];
00071 }
00072 }
00073
00074 template <> template <>
00075 void
00076 octave_sort<bool>::sort (bool *data, octave_idx_type nel,
00077 std::less<bool>)
00078 {
00079 do_bool_partition<false> (data, nel);
00080 }
00081
00082 template <> template <>
00083 void
00084 octave_sort<bool>::sort (bool *data, octave_idx_type nel,
00085 std::greater<bool>)
00086 {
00087 do_bool_partition<true> (data, nel);
00088 }
00089
00090 template <> template <>
00091 void
00092 octave_sort<bool>::sort (bool *data, octave_idx_type *idx, octave_idx_type nel,
00093 std::less<bool>)
00094 {
00095 do_bool_partition<false> (data, idx, nel);
00096 }
00097
00098 template <> template <>
00099 void
00100 octave_sort<bool>::sort (bool *data, octave_idx_type *idx, octave_idx_type nel,
00101 std::greater<bool>)
00102 {
00103 do_bool_partition<true> (data, idx, nel);
00104 }
00105
00106 INSTANTIATE_ARRAY_SORT (bool);
00107
00108 INSTANTIATE_ARRAY (bool, OCTAVE_API);
00109
00110 template OCTAVE_API std::ostream& operator << (std::ostream&, const Array<bool>&);
00111
00112 #include "DiagArray2.h"
00113 #include "DiagArray2.cc"
00114
00115 template class OCTAVE_API DiagArray2<bool>;