1 #ifndef multidimstorage_h 2 #define multidimstorage_h 28 MultiDimStorage(
int ndims,
int nvals);
30 virtual ~MultiDimStorage();
37 void setNrVals(
int,
bool keepdata);
38 void removeValue(
int);
40 bool allowsDuplicates()
const;
43 bool allowDuplicates(
bool);
47 int totalSize()
const;
57 int getPos(
int idx)
const;
61 template <
class IDX>
const T& getRef(
const IDX& index,
int val)
const;
64 template <
class IDX> T& getRef(
const IDX& index,
int val);
67 template <
class V,
class POS,
class IDX>
68 bool add(
const V& vals,
const POS& pos,
71 template <
class V,
class POS>
bool add(
const V& vals,
const POS& pos);
74 template <
class IDX>
void remove(
const IDX& index);
78 template <
class POS,
class IDX>
bool findFirst(
const POS&,IDX&)
const;
79 template <
class IDX>
bool getIndex(
int global_pos,IDX&)
const;
80 template <
class IDX,
class POS>
bool getPos(
const IDX&,POS&)
const;
81 template <
class IDX>
bool next(IDX&,
bool skipdups=
false)
const;
82 template <
class IDX>
bool prev(IDX&,
bool skipdups=
false)
const;
83 template <
class IDX>
bool isValidPos(
const IDX&)
const;
84 void removeDuplicates();
93 template <
class POS>
void getIndicesInRange(
const POS& start,
101 template <
class IDX>
void setToLastPos(IDX&)
const;
102 int findFirstPos(
int pos)
const;
103 template <
class POS>
void getIndicesInRangeI(
const POS& start,
119 template <
class T>
inline 123 , allowduplicates_( false )
127 template <
class T>
inline 147 template <
class T>
inline 154 template <
class T>
inline 175 template <
class T>
inline 184 template <
class T>
inline 190 for (
int idx=0; idx<b.
size(); idx++ )
192 const int pos = b.
getPos( idx );
233 template <
class T>
inline 238 template <
class T>
inline 253 template <
class T>
inline 267 template <
class T>
inline 281 template <
class T>
inline 288 template <
class T>
inline 296 template <
class T>
inline 304 template <
class T>
inline 309 template <
class T>
inline 315 template <
class T>
inline 330 template <
class T>
inline 351 template <
class T>
inline 355 template <
class T>
inline 359 template <
class T>
inline 375 const int nrpos =
size();
379 for (
int idx=0; idx<nrpos; idx++ )
381 for (
int idy=0; idy<nrvalstocp; idy++ )
391 template <
class T>
template <
class IDX>
inline 394 const int index = indexarr[
nrdims_-1];
401 template <
class T>
template <
class IDX>
inline 407 template <
class T>
template <
class V,
class POS,
class IDX>
inline 412 const int pos =
mCast(
int, posarr[dim] );
416 if ( !match ) index++;
418 if ( indexarr ) (*indexarr)[dim] = index;
449 for (
int idx=0; idx<
nrvals_; idx++ )
451 const int arrpos = index*nrvals_+idx;
467 for (
int idx=0; idx<
nrvals_; idx++ )
476 template <
class T>
template <
class V,
class POS>
inline 479 return add<V,POS,int*>( vals, posarr, 0 );
483 template <
class T>
template<
class IDX>
inline 487 const int index = indexarr[dim];
506 template <
class T>
template <
class POS,
class IDX>
inline 510 const int pos = posarr[dim];
516 indexarr[dim] = index;
522 template <
class T>
template <
class IDX,
class POS>
inline 526 int index = indexarr[dim];
535 template <
class T>
template <
class IDX>
inline 539 int& index = indexarr[dim];
546 if ( globalpos<localsum )
552 globalpos -= localsum;
568 template <
class T>
template <
class IDX>
inline 572 int& index = indexarr[dim];
617 }
while ( skipduplicate &&
positions_[index]==oldpos );
623 template <
class T>
template <
class IDX>
inline 627 int& index = indexarr[dim];
645 template <
class T>
template<
class IDX>
inline 649 const int index = indexarr[dim];
662 template <
class T>
inline 686 template <
class T>
template <
class POS>
inline 695 template <
class T>
template <
class POS>
inline 700 const int start = startarr[dim];
701 const int stop = stoparr[dim];
707 if ( idx<0 ) idx = 0;
709 for ( ; idx<sz; idx++ )
724 template <
class T>
template <
class IDX>
inline 728 const int index = indexarr[dim] =
size()-1;
734 template <
class T>
inline 744 for (
int idy=0; idy<
nrvals_; idy++ )
751 template <
class T>
inline 754 const int nrchunks = res.
size();
764 const int nrperchunk =
mNINT32((
float) totalsize / nrchunks );
767 int* idxs = allocidx;
768 for (
int idx=0; idx<
nrdims_; idx++ )
775 int chunk = idx/nrperchunk;
776 if ( chunk>=nrchunks )
781 if ( chunk==prevchunk )
784 for (
int idy=0; idy<
nrdims_; idy++ )
785 res[chunk][idy] = idxs[idy];
794 template <
class T>
template <
class IDXS>
inline 802 long long multiplicator = 1;
803 for (
int dim=0; dim<
nrdims_; dim++ )
805 dimsizes += multiplicator;
809 multiplicator *= ( rg.
width()+1 );
815 for (
int idx=0; idx<indices.
size(); idx++ )
817 long long sortkey = 0;
818 for (
int dim=0; dim<
nrdims_; dim++ )
819 sortkey += indices[idx][dim] * dimsizes[dim];
828 for (
int idx=
mCast(
int,idxs.
size()-1); idx>=0; idx-- )
829 indices[idx] = copy[(
int)idxs[idx]];
MultiDimStorage(int ndims, int nvals)
Definition: multidimstorage.h:120
virtual void insert(size_type, const T &)
Definition: typeset.h:347
Definition: multidimstorage.h:25
bool allowDuplicates(bool)
Definition: multidimstorage.h:239
#define mCast(tp, v)
Definition: commondefs.h:124
bool findFirst(const POS &, IDX &) const
Definition: multidimstorage.h:507
bool prev(IDX &, bool skipdups=false) const
Definition: multidimstorage.h:624
bool isEmpty() const
Definition: odset.h:45
ObjectSet< T >::size_type indexOf(const ObjectSet< T > &os, const S &val)
Locate object in set.
Definition: objectset.h:169
int getPos(int idx) const
Definition: multidimstorage.h:310
int nrvals_
Definition: multidimstorage.h:115
void setNrVals(int, bool keepdata)
Definition: multidimstorage.h:360
bool getIndex(int global_pos, IDX &) const
Definition: multidimstorage.h:536
virtual T * removeSingle(size_type, bool keep_order=true)
Definition: objectset.h:460
#define mMIN(x, y)
Definition: commondefs.h:49
MultiDimStorage< T > & operator=(const MultiDimStorage< T > &)
Definition: multidimstorage.h:135
bool getRange(int dim, Interval< int > &) const
Definition: multidimstorage.h:316
virtual T * arr()
3rd party access
Definition: typeset.h:92
size_type size() const
Definition: objectset.h:50
bool append(TypeSetBase< T, I > &to, const TypeSetBase< S, J > &from)
append allowing a different type to be merged into set
Definition: typeset.h:198
#define mNINT32(x)
Definition: commondefs.h:45
Set of (small) copyable elements.
Definition: commontypes.h:30
bool allowsDuplicates() const
Definition: multidimstorage.h:234
MultiDimStorage< T > * operator[](int)
Definition: multidimstorage.h:289
T width(bool allowrev=true) const
Definition: ranges.h:451
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
void getIndicesInRange(const POS &start, const POS &stop, TypeSet< int > &res) const
Definition: multidimstorage.h:687
virtual ~MultiDimStorage()
Definition: multidimstorage.h:148
bool isValidPos(const IDX &) const
Definition: multidimstorage.h:646
bool isEmpty() const
Definition: multidimstorage.h:254
int size() const
Definition: multidimstorage.h:282
bool add(const V &vals, const POS &pos, IDX *index=0)
Definition: multidimstorage.h:408
TypeSet< T > onedimstorage_
Definition: multidimstorage.h:110
void deepCopy(ObjectSet< T > &to, const ObjectSet< S > &from)
fill an ObjectSet with copies of the objects in the other set.
Definition: objectset.h:147
TypeSet< int > positions_
Definition: multidimstorage.h:108
bool append(const MultiDimStorage< T > &)
Definition: multidimstorage.h:185
void removeDuplicates()
Definition: multidimstorage.h:735
void getIndicesInRangeI(const POS &start, const POS &stop, TypeSet< int > &curpos, TypeSet< int > &res) const
Definition: multidimstorage.h:696
void setToLastPos(IDX &) const
Definition: multidimstorage.h:725
int nrdims_
Definition: multidimstorage.h:114
bool allowduplicates_
Definition: multidimstorage.h:111
void remove(const IDX &index)
Definition: multidimstorage.h:484
virtual bool append(const T *, size_type)
Definition: typeset.h:437
bool isOK() const
Definition: multidimstorage.h:155
int nrVals() const
Definition: multidimstorage.h:356
size_type size() const
Definition: typeset.h:254
T stop
Definition: ranges.h:93
void include(const T &, bool allowrev=true)
Definition: ranges.h:531
virtual void insertAt(T *newptr, size_type)
Definition: objectset.h:405
void sort(ObjectSet< T > &os)
Sort ObjectSet. Must have operator > defined for elements.
Definition: objectset.h:220
int totalSize() const
Definition: multidimstorage.h:268
const T & getRef(const IDX &index, int val) const
Definition: multidimstorage.h:402
bool next(IDX &, bool skipdups=false) const
Definition: multidimstorage.h:569
ObjectSet< MultiDimStorage< T > > lowerdimstorage_
Definition: multidimstorage.h:109
int nrDims() const
Definition: multidimstorage.h:352
virtual void erase()
Definition: typeset.h:339
void setEmpty()
Definition: multidimstorage.h:176
void getRangeI(int dim, Interval< int > &) const
Definition: multidimstorage.h:331
T start
Definition: ranges.h:92
bool sort(TypeSet< IDX > &indices) const
void copy(TypeSetBase< T, I > &to, const TypeSetBase< S, I > &from)
Definition: typeset.h:212
virtual void removeSingle(size_type, bool preserver_order=true)
Definition: typeset.h:500
#define mClass(module)
Definition: commondefs.h:164
bool isEmpty(const NLAModel *mdl)
#define pErrMsg(msg)
Definition: errmsg.h:60
bool divide(ObjectSet< int > &) const
Definition: multidimstorage.h:752
virtual size_type indexOf(T, bool forward=true, size_type start=-1) const
Definition: typeset.h:311
virtual bool validIdx(int64_t) const
Definition: typeset.h:279
bool findPos(const T1 &posarr, T3 sz, T2 pos, T3 beforefirst, T3 &idx)
Definition: idxable.h:75
int findFirstPos(int pos) const
Definition: multidimstorage.h:663
int indexOf(int pos) const
Definition: multidimstorage.h:305
void deepErase(ObjectSet< T > &os)
empty the ObjectSet deleting all objects pointed to.
Definition: objectset.h:118
void sort_coupled(T *arr, IT *idxs, I sz)
Definition: sorting.h:42