comparison liboctave/oct-sort.h @ 9921:7c8392a034e6

fix & improve lookup API
author Jaroslav Hajek <highegg@gmail.com>
date Sat, 05 Dec 2009 06:10:41 +0100
parents aea3a3a950e1
children 4c0cdbe0acca
comparison
equal deleted inserted replaced
9920:56fbe170d354 9921:7c8392a034e6
140 140
141 // Do a binary lookup in a sorted array. 141 // Do a binary lookup in a sorted array.
142 octave_idx_type lookup (const T *data, octave_idx_type nel, 142 octave_idx_type lookup (const T *data, octave_idx_type nel,
143 const T& value); 143 const T& value);
144 144
145 // Ditto, but for an array of values, specializing on long runs. 145 // Ditto, but for an array.
146 // Adds offset to all indices.
147 void lookup (const T *data, octave_idx_type nel, 146 void lookup (const T *data, octave_idx_type nel,
148 const T* values, octave_idx_type nvalues, 147 const T* values, octave_idx_type nvalues,
149 octave_idx_type *idx, octave_idx_type offset = 0); 148 octave_idx_type *idx);
150 149
151 // Lookup an array of values, only returning indices of 150 // A linear merge of two sorted tables. rev indicates the second table is
152 // exact matches. Non-matches are returned as -1. 151 // in reverse order.
153 void lookupm (const T *data, octave_idx_type nel, 152 void lookup_sorted (const T *data, octave_idx_type nel,
154 const T* values, octave_idx_type nvalues, 153 const T* values, octave_idx_type nvalues,
155 octave_idx_type *idx); 154 octave_idx_type *idx, bool rev = false);
156
157 // Lookup an array of values, only indicating exact matches.
158 void lookupb (const T *data, octave_idx_type nel,
159 const T* values, octave_idx_type nvalues,
160 bool *match);
161 155
162 // Rearranges the array so that the elements with indices 156 // Rearranges the array so that the elements with indices
163 // lo..up-1 are in their correct place. 157 // lo..up-1 are in their correct place.
164 void nth_element (T *data, octave_idx_type nel, 158 void nth_element (T *data, octave_idx_type nel,
165 octave_idx_type lo, octave_idx_type up = -1); 159 octave_idx_type lo, octave_idx_type up = -1);
314 const T& value, Comp comp); 308 const T& value, Comp comp);
315 309
316 template <class Comp> 310 template <class Comp>
317 void lookup (const T *data, octave_idx_type nel, 311 void lookup (const T *data, octave_idx_type nel,
318 const T* values, octave_idx_type nvalues, 312 const T* values, octave_idx_type nvalues,
319 octave_idx_type *idx, octave_idx_type offset, Comp comp); 313 octave_idx_type *idx, Comp comp);
320 314
321 template <class Comp> 315 template <class Comp>
322 void lookupm (const T *data, octave_idx_type nel, 316 void lookup_sorted (const T *data, octave_idx_type nel,
323 const T* values, octave_idx_type nvalues, 317 const T* values, octave_idx_type nvalues,
324 octave_idx_type *idx, Comp comp); 318 octave_idx_type *idx, bool rev, Comp comp);
325
326 template <class Comp>
327 void lookupb (const T *data, octave_idx_type nel,
328 const T* values, octave_idx_type nvalues,
329 bool *match, Comp comp);
330 319
331 template <class Comp> 320 template <class Comp>
332 void nth_element (T *data, octave_idx_type nel, 321 void nth_element (T *data, octave_idx_type nel,
333 octave_idx_type lo, octave_idx_type up, 322 octave_idx_type lo, octave_idx_type up,
334 Comp comp); 323 Comp comp);