Mercurial > hg > octave-nkf
diff liboctave/dim-vector.h @ 10645:8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 20 May 2010 15:10:34 +0200 |
parents | ec3cec8277df |
children | 0ba9bd294421 |
line wrap: on
line diff
--- a/liboctave/dim-vector.h +++ b/liboctave/dim-vector.h @@ -612,7 +612,7 @@ // Compute a linear index from an index tuple. - octave_idx_type compute_index (const octave_idx_type *idx) + octave_idx_type compute_index (const octave_idx_type *idx) const { octave_idx_type k = 0; for (int i = length () - 1; i >= 0; i--) @@ -621,11 +621,22 @@ return k; } + // Ditto, but the tuple may be incomplete (nidx < length ()). + + octave_idx_type compute_index (const octave_idx_type *idx, int nidx) const + { + octave_idx_type k = 0; + for (int i = nidx - 1; i >= 0; i--) + k = k * rep[i] + idx[i]; + + return k; + } + // Increment a multi-dimensional index tuple, optionally starting // from an offset position and return the index of the last index // position that was changed, or length () if just cycled over. - int increment_index (octave_idx_type *idx, int start = 0) + int increment_index (octave_idx_type *idx, int start = 0) const { int i; for (i = start; i < length (); i++) @@ -655,7 +666,7 @@ // Compute a linear index from an index tuple. Dimensions are // required to be cumulative. - octave_idx_type cum_compute_index (const octave_idx_type *idx) + octave_idx_type cum_compute_index (const octave_idx_type *idx) const { octave_idx_type k = idx[0];