Mercurial > hg > octave-lyh
comparison liboctave/oct-sort.h @ 8814:de16ebeef93d
improve lookup, provide Array<T>::lookup
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 19 Feb 2009 15:19:59 +0100 |
parents | d5af326a3ede |
children | 89b95972e178 |
comparison
equal
deleted
inserted
replaced
8813:70d06ed27c08 | 8814:de16ebeef93d |
---|---|
112 | 112 |
113 octave_sort (void); | 113 octave_sort (void); |
114 | 114 |
115 octave_sort (compare_fcn_type); | 115 octave_sort (compare_fcn_type); |
116 | 116 |
117 ~octave_sort (void) { merge_freemem (); } | 117 ~octave_sort (void); |
118 | 118 |
119 void set_compare (compare_fcn_type comp) { compare = comp; } | 119 void set_compare (compare_fcn_type comp) { compare = comp; } |
120 | 120 |
121 void set_compare (sortmode mode); | 121 void set_compare (sortmode mode); |
122 | 122 |
135 octave_idx_type rows, octave_idx_type cols); | 135 octave_idx_type rows, octave_idx_type cols); |
136 | 136 |
137 // Determine whether a matrix (as a contiguous block) is sorted by rows. | 137 // Determine whether a matrix (as a contiguous block) is sorted by rows. |
138 bool is_sorted_rows (const T *data, | 138 bool is_sorted_rows (const T *data, |
139 octave_idx_type rows, octave_idx_type cols); | 139 octave_idx_type rows, octave_idx_type cols); |
140 | |
141 // Do a binary lookup in a sorted array. | |
142 octave_idx_type lookup (const T *data, octave_idx_type nel, | |
143 const T& value); | |
144 | |
145 // Ditto, but for an array of values, specializing on long runs. | |
146 // Adds offset to all indices. | |
147 void lookup (const T *data, octave_idx_type nel, | |
148 const T* values, octave_idx_type nvalues, | |
149 octave_idx_type *idx, octave_idx_type offset = 0); | |
140 | 150 |
141 static bool ascending_compare (typename ref_param<T>::type, | 151 static bool ascending_compare (typename ref_param<T>::type, |
142 typename ref_param<T>::type); | 152 typename ref_param<T>::type); |
143 | 153 |
144 static bool descending_compare (typename ref_param<T>::type, | 154 static bool descending_compare (typename ref_param<T>::type, |
185 struct s_slice pending[MAX_MERGE_PENDING]; | 195 struct s_slice pending[MAX_MERGE_PENDING]; |
186 }; | 196 }; |
187 | 197 |
188 compare_fcn_type compare; | 198 compare_fcn_type compare; |
189 | 199 |
190 MergeState ms; | 200 MergeState *ms; |
191 | 201 |
192 | 202 |
193 template <class Comp> | 203 template <class Comp> |
194 void binarysort (T *data, octave_idx_type nel, | 204 void binarysort (T *data, octave_idx_type nel, |
195 octave_idx_type start, Comp comp); | 205 octave_idx_type start, Comp comp); |
274 Comp comp); | 284 Comp comp); |
275 | 285 |
276 template <class Comp> | 286 template <class Comp> |
277 bool is_sorted_rows (const T *data, octave_idx_type rows, | 287 bool is_sorted_rows (const T *data, octave_idx_type rows, |
278 octave_idx_type cols, Comp comp); | 288 octave_idx_type cols, Comp comp); |
289 | |
290 template <class Comp> | |
291 octave_idx_type lookup (const T *data, octave_idx_type nel, | |
292 const T& value, Comp comp); | |
293 | |
294 template <class Comp> | |
295 void lookup (const T *data, octave_idx_type nel, | |
296 const T* values, octave_idx_type nvalues, | |
297 octave_idx_type *idx, octave_idx_type offset, Comp comp); | |
279 | 298 |
280 }; | 299 }; |
281 | 300 |
282 template <class T> | 301 template <class T> |
283 class | 302 class |