diff --git a/src/include/ranges/crange.h b/src/include/ranges/crange.h index 6eb2b19..1a3bdbf 100644 --- a/src/include/ranges/crange.h +++ b/src/include/ranges/crange.h @@ -35,8 +35,9 @@ namespace CNORXZ SizeT dim() const; // = 1 Sptr range() const; - SizeT getStepSize(SizeT n) const; - + SizeT getStepSize(PtrId iptr) const; + Int getOffset(PtrId iptr) const; + String stringMeta() const; SizeT meta() const; CIndex& at(const SizeT& metaPos); diff --git a/src/include/ranges/dindex.h b/src/include/ranges/dindex.h index 0312a45..52ee13e 100644 --- a/src/include/ranges/dindex.h +++ b/src/include/ranges/dindex.h @@ -39,7 +39,8 @@ namespace CNORXZ SizeT dim() const; RangePtr range() const; - SizeT getStepSize(SizeT n) const; + SizeT getStepSize(PtrId iptr) const; + Int getOffset(PtrId iptr) const; String stringMeta() const; DType meta() const; diff --git a/src/include/ranges/index_base.h b/src/include/ranges/index_base.h index 7c9c1cf..0bf2e5a 100644 --- a/src/include/ranges/index_base.h +++ b/src/include/ranges/index_base.h @@ -45,10 +45,9 @@ namespace CNORXZ SizeT dim() const { return THIS().dim(); } auto range() const { return THIS().range(); } - // TODO: getStepSize(PtrId iptr) !!!! - SizeT getStepSize(SizeT n) const { return THIS().getStepSize(n); } - Int getOffset(PtrId iptr) const - { if(mRel) if(iptr == mRel->ptrId()) return mPos - mRel.pos(); return 0; } + SizeT getStepSize(PtrId iptr) const { return THIS().getStepSize(iptr); } + //SizeT getStepSize(SizeT n) const { return THIS().getStepSize(n); } + Int getOffset(PtrId iptr) const { return THIS().getOffset(iptr); } String stringMeta() const { return THIS().stringMeta(); } auto meta() const { return THIS().meta(); } @@ -77,7 +76,6 @@ namespace CNORXZ IndexInterface(SizeT pos); PtrId mPtrId = 0; - IndexPtr mRel; }; template diff --git a/src/include/ranges/mrange.h b/src/include/ranges/mrange.h index f8ad35b..f73af3d 100644 --- a/src/include/ranges/mrange.h +++ b/src/include/ranges/mrange.h @@ -54,7 +54,8 @@ namespace CNORXZ SizeT dim(); Sptr range(); - SizeT getStepSize(SizeT n); + SizeT getStepSize(PtrId iptr) const; + Int getOffset(PtrId iptr) const; String stringMeta() const; MetaType meta() const; diff --git a/src/include/ranges/urange.cc.h b/src/include/ranges/urange.cc.h index f605d46..d8da929 100644 --- a/src/include/ranges/urange.cc.h +++ b/src/include/ranges/urange.cc.h @@ -14,8 +14,8 @@ namespace CNORXZ *****************/ template - UIndex::UIndex(const RangePtr& range) : - IndexInterface,MetaType>(0), + UIndex::UIndex(const RangePtr& range, SizeT pos) : + IndexInterface,MetaType>(pos), mRangePtr(rangeCast(range)), mMetaPtr(&mRangePtr->get(0)) {} @@ -41,6 +41,44 @@ namespace CNORXZ return *this; } + template + UIndex UIndex::operator+(Int n) const + { + return UIndex(mRangePtr, IB::mPos + n); + } + + template + UIndex UIndex::operator-(Int n) const + { + return UIndex(mRangePtr, IB::mPos - n); + } + + template + UIndex& UIndex::operator+=(Int n) + { + IB::mPos += n; + return *this; + } + + template + UIndex& UIndex::operator-=(Int n) + { + IB::mPos -= n; + return *this; + } + + template + const MetaType& UIndex::operator*() const + { + return mMetaPtr[IB::mPos]; + } + + template + const MetaType* UIndex::operator->() const + { + return mMetaPtr + IB::mPos; + } + template Int UIndex::pp(PtrId idxPtrNum) { @@ -87,9 +125,15 @@ namespace CNORXZ } template - SizeT UIndex::getStepSize(SizeT n) const + SizeT UIndex::getStepSize(PtrId iptr) const { - return 1; + return iptr == this->ptrId() ? 1 : 0; + } + + template + Int UIndex::getOffset(PtrId iptr) const + { + return 0; } /* template diff --git a/src/include/ranges/urange.h b/src/include/ranges/urange.h index 216e62a..3780bc6 100644 --- a/src/include/ranges/urange.h +++ b/src/include/ranges/urange.h @@ -19,7 +19,7 @@ namespace CNORXZ typedef IndexInterface,MetaType> IB; typedef URange RangeType; - UIndex(const RangePtr& range); + UIndex(const RangePtr& range, SizeT pos = 0); UIndex& operator=(SizeT pos); UIndex& operator++(); @@ -37,7 +37,8 @@ namespace CNORXZ SizeT dim() const; // = 1 Sptr range() const; - SizeT getStepSize(SizeT n) const; + SizeT getStepSize(PtrId iptr) const; + Int getOffset(PtrId iptr) const; String stringMeta() const; const MetaType& meta() const; diff --git a/src/include/ranges/xindex.cc.h b/src/include/ranges/xindex.cc.h index 75032a5..fb2bc3f 100644 --- a/src/include/ranges/xindex.cc.h +++ b/src/include/ranges/xindex.cc.h @@ -117,9 +117,15 @@ namespace CNORXZ } template - SizeT XIndex::getStepSize(SizeT n) const + SizeT XIndex::getStepSize(PtrId iptr) const { - return mI->getStepSize(n); + return mI->getStepSize(iptr); + } + + template + Int XIndex::getOffset(PtrId iptr) const + { + return mI->getOffset(iptr); } template diff --git a/src/include/ranges/xindex.h b/src/include/ranges/xindex.h index 4325a36..3f67e56 100644 --- a/src/include/ranges/xindex.h +++ b/src/include/ranges/xindex.h @@ -32,7 +32,8 @@ namespace CNORXZ virtual SizeT dim() const = 0; virtual RangePtr range() const = 0; - virtual SizeT getStepSize(SizeT n) const = 0; + virtual SizeT getStepSize(PtrId iptr) const = 0; + virtual Int getOffset(PtrId iptr) const = 0; virtual String stringMeta() const = 0; virtual DType meta() const = 0; @@ -80,7 +81,8 @@ namespace CNORXZ virtual SizeT dim() const override final; virtual RangePtr range() const override final; - virtual SizeT getStepSize(SizeT n) const override final; + virtual SizeT getStepSize(PtrId iptr) const override final; + virtual Int getOffset(PtrId iptr) const override final; virtual String stringMeta() const override final; virtual DType meta() const override final; diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 9337c0b..8a2c3c4 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -42,7 +42,8 @@ namespace CNORXZ SizeT dim() const; Sptr range() const; - SizeT getStepSize(SizeT n) const; + SizeT getStepSize(PtrId iptr) const; + Int getOffset(PtrId iptr) const; String stringMeta() const; DType meta() const; diff --git a/src/lib/ranges/crange.cc b/src/lib/ranges/crange.cc index aa36ae1..e66953b 100644 --- a/src/lib/ranges/crange.cc +++ b/src/lib/ranges/crange.cc @@ -10,7 +10,7 @@ namespace CNORXZ CIndex::CIndex(const RangePtr& range, SizeT pos) : IndexInterface(pos), mRangePtr(rangeCast(range)) {} - + CIndex& CIndex::operator=(SizeT pos) { IB::mPos = pos; @@ -83,9 +83,14 @@ namespace CNORXZ return mRangePtr; } - SizeT CIndex::getStepSize(SizeT n) const + SizeT CIndex::getStepSize(PtrId iptr) const { - return 1; + return iptr == this->ptrId() ? 1 : 0; + } + + Int CIndex::getOffset(PtrId iptr) const + { + return 0; } String CIndex::stringMeta() const diff --git a/src/lib/ranges/dindex.cc b/src/lib/ranges/dindex.cc index f091afe..0a5bcf8 100644 --- a/src/lib/ranges/dindex.cc +++ b/src/lib/ranges/dindex.cc @@ -116,9 +116,14 @@ namespace CNORXZ return mI->range(); } - SizeT DIndex::getStepSize(SizeT n) const + SizeT DIndex::getStepSize(PtrId iptr) const { - return mI->getStepSize(n); + return mI->getStepSize(iptr); + } + + Int DIndex::getOffset(PtrId iptr) const + { + return mI->getOffset(iptr); } String DIndex::stringMeta() const diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index bb81521..e283ac6 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -122,13 +122,20 @@ namespace CNORXZ return mRangePtr; } - SizeT YIndex::getStepSize(SizeT n) const + SizeT YIndex::getStepSize(PtrId iptr) const { assert(0); // sub inds !!! return 0; } - + + Int YIndex::getOffset(PtrId iptr) const + { + assert(0); + // sub inds !!! + return 0; + } + String YIndex::stringMeta() const { String out = "[";