15#define _WX_COL_MAJOR_ORDER 1
16#define _WX_ROW_MAJOR_ORDER 2
27template<
int TYPE = _WX_COL_MAJOR_ORDER>
class WmIndexer
76 int index(
int k1,
int k2)
const;
81 int index(
int k1,
int k2,
int k3)
const;
86 int index(
int k1,
int k2,
int k3,
int k4)
const;
102 int*
invIndex(
unsigned loc,
int* indicesReturn)
const;
117 for (
unsigned i = 0; i <= _rank; ++i)
124 for (
unsigned i = 0; i <= _rank; ++i)
138 for (
int i = 0; i <= _rank; ++i)
150#ifdef _DO_RANGE_CHECK_
152 assert((k1 >= _r.lower(0)) && (k1 <= _r.upper(0)));
159#ifdef _DO_RANGE_CHECK_
161 assert((k1 >= _r.lower(0)) && (k1 <= _r.upper(0)));
162 assert((k2 >= _r.lower(1)) && (k2 <= _r.upper(1)));
164 return _ai[0] + k1 + _ai[2] * k2;
169#ifdef _DO_RANGE_CHECK_
171 assert((k1 >= _r.lower(0)) && (k1 <= _r.upper(0)));
172 assert((k2 >= _r.lower(1)) && (k2 <= _r.upper(1)));
173 assert((k3 >= _r.lower(2)) && (k3 <= _r.upper(2)));
175 return _ai[0] + k1 + _ai[2] * k2 + _ai[3] * k3;
181#ifdef _DO_RANGE_CHECK_
183 assert((k1 >= _r.lower(0)) && (k1 <= _r.upper(0)));
184 assert((k2 >= _r.lower(1)) && (k2 <= _r.upper(1)));
185 assert((k3 >= _r.lower(2)) && (k3 <= _r.upper(2)));
186 assert((k4 >= _r.lower(3)) && (k4 <= _r.upper(3)));
188 return _ai[0] + k1 + _ai[2] * k2 + _ai[3] * k3 + _ai[4] * k4;
193 int* indicesReturn)
const
197 for (
int i = (
int) _rank - 1; i >= 0; --i)
199 qr = div(n, _ai[i + 1]);
200 indicesReturn[i] = qr.quot + _r.lower(i);
203 return indicesReturn;
211#ifdef _DO_RANGE_CHECK_
213 assert((k1 >= _r.lower(0)) && (k1 <= _r.upper(0)));
220#ifdef _DO_RANGE_CHECK_
222 assert((k1 >= _r.lower(0)) && (k1 <= _r.upper(0)));
223 assert((k2 >= _r.lower(1)) && (k2 <= _r.upper(1)));
225 return _ai[0] + _ai[1] * k1 + k2;
230#ifdef _DO_RANGE_CHECK_
232 assert((k1 >= _r.lower(0)) && (k1 <= _r.upper(0)));
233 assert((k2 >= _r.lower(1)) && (k2 <= _r.upper(1)));
234 assert((k3 >= _r.lower(2)) && (k3 <= _r.upper(2)));
236 return _ai[0] + _ai[1] * k1 + _ai[2] * k2 + k3;
242#ifdef _DO_RANGE_CHECK_
244 assert((k1 >= _r.lower(0)) && (k1 <= _r.upper(0)));
245 assert((k2 >= _r.lower(1)) && (k2 <= _r.upper(1)));
246 assert((k3 >= _r.lower(2)) && (k3 <= _r.upper(2)));
247 assert((k4 >= _r.lower(3)) && (k4 <= _r.upper(3)));
249 return _ai[0] + _ai[1] * k1 + _ai[2] * k2 + _ai[3] * k3 + k4;
254 int* indicesReturn)
const
258 for (
unsigned i = 0; i < _rank; ++i)
260 qr = div(n, _ai[i + 1]);
261 indicesReturn[i] = qr.quot + _r.lower(i);
264 return indicesReturn;
269#ifdef _DO_RANGE_CHECK_
270 for (
unsigned i = 0; i < rank(); ++i)
271 assert(k[i] >= _r.lower(i) && k[i] <= _r.upper(i));
274 for (
unsigned i = 1; i <= _rank; ++i)
275 sum += _ai[i] * k[i - 1];
template<typename T> class WxArray;
Definition: wmindexer.h:28
unsigned rank() const
Rank of indexer.
Definition: wmindexer.h:55
int index(int k1, int k2, int k3) const
Index 3D array.
int index(int k1, int k2, int k3, int k4) const
Index 4D array.
int * invIndex(unsigned loc, int *indicesReturn) const
Return index location given a linear offset.
int index(int k1, int k2) const
Index 2D array.
WmIndexer(const WxRange &r)
Constructs indexer for a given range.
int index(int k1) const
Index 1D array.
const WxRange & range() const
Range of set indexed.
Definition: wmindexer.h:63
static const int max_dims
Maximum rank box that can be represented.
Definition: wxbox.h:321
WxRange represents a hyper-rectangular domain of an n-dimensional space of integers.
Definition: wxrange.h:23
WmIndexer & operator=(const WmIndexer &idx)
Definition: wmindexer.h:132
WmIndexer(const WmIndexer &idx)
Definition: wmindexer.h:115
~WmIndexer()
Definition: wmindexer.h:128
int index(const int *k) const
Index arbitrary dimensional array.
Definition: wmindexer.h:267
WmIndexer(unsigned rank, int *ai, const WxRange &r)
Definition: wmindexer.h:122
const unsigned __max_idx_size
Definition: wmindexer.h:19
WmIndexer()
The default constructor creates an empty WmIndexer object.
Definition: wmindexer.h:110