Mercurial > hg > octave-lyh
diff 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 |
line wrap: on
line diff
--- a/liboctave/oct-sort.h +++ b/liboctave/oct-sort.h @@ -114,7 +114,7 @@ octave_sort (compare_fcn_type); - ~octave_sort (void) { merge_freemem (); } + ~octave_sort (void); void set_compare (compare_fcn_type comp) { compare = comp; } @@ -138,6 +138,16 @@ bool is_sorted_rows (const T *data, octave_idx_type rows, octave_idx_type cols); + // Do a binary lookup in a sorted array. + octave_idx_type lookup (const T *data, octave_idx_type nel, + const T& value); + + // Ditto, but for an array of values, specializing on long runs. + // Adds offset to all indices. + void lookup (const T *data, octave_idx_type nel, + const T* values, octave_idx_type nvalues, + octave_idx_type *idx, octave_idx_type offset = 0); + static bool ascending_compare (typename ref_param<T>::type, typename ref_param<T>::type); @@ -187,7 +197,7 @@ compare_fcn_type compare; - MergeState ms; + MergeState *ms; template <class Comp> @@ -277,6 +287,15 @@ bool is_sorted_rows (const T *data, octave_idx_type rows, octave_idx_type cols, Comp comp); + template <class Comp> + octave_idx_type lookup (const T *data, octave_idx_type nel, + const T& value, Comp comp); + + template <class Comp> + void lookup (const T *data, octave_idx_type nel, + const T* values, octave_idx_type nvalues, + octave_idx_type *idx, octave_idx_type offset, Comp comp); + }; template <class T>