change getStepSize: pass ptr id instead of index number

This commit is contained in:
Christian Zimmermann 2022-09-18 22:50:07 +02:00
parent a880d1e0db
commit d497eb09ae
12 changed files with 99 additions and 27 deletions

View file

@ -35,7 +35,8 @@ namespace CNORXZ
SizeT dim() const; // = 1 SizeT dim() const; // = 1
Sptr<RangeType> range() const; Sptr<RangeType> range() const;
SizeT getStepSize(SizeT n) const; SizeT getStepSize(PtrId iptr) const;
Int getOffset(PtrId iptr) const;
String stringMeta() const; String stringMeta() const;
SizeT meta() const; SizeT meta() const;

View file

@ -39,7 +39,8 @@ namespace CNORXZ
SizeT dim() const; SizeT dim() const;
RangePtr range() const; RangePtr range() const;
SizeT getStepSize(SizeT n) const; SizeT getStepSize(PtrId iptr) const;
Int getOffset(PtrId iptr) const;
String stringMeta() const; String stringMeta() const;
DType meta() const; DType meta() const;

View file

@ -45,10 +45,9 @@ namespace CNORXZ
SizeT dim() const { return THIS().dim(); } SizeT dim() const { return THIS().dim(); }
auto range() const { return THIS().range(); } auto range() const { return THIS().range(); }
// TODO: getStepSize(PtrId iptr) !!!! SizeT getStepSize(PtrId iptr) const { return THIS().getStepSize(iptr); }
SizeT getStepSize(SizeT n) const { return THIS().getStepSize(n); } //SizeT getStepSize(SizeT n) const { return THIS().getStepSize(n); }
Int getOffset(PtrId iptr) const Int getOffset(PtrId iptr) const { return THIS().getOffset(iptr); }
{ if(mRel) if(iptr == mRel->ptrId()) return mPos - mRel.pos(); return 0; }
String stringMeta() const { return THIS().stringMeta(); } String stringMeta() const { return THIS().stringMeta(); }
auto meta() const { return THIS().meta(); } auto meta() const { return THIS().meta(); }
@ -77,7 +76,6 @@ namespace CNORXZ
IndexInterface(SizeT pos); IndexInterface(SizeT pos);
PtrId mPtrId = 0; PtrId mPtrId = 0;
IndexPtr<I,MetaType> mRel;
}; };
template <class I, typename MetaType> template <class I, typename MetaType>

View file

@ -54,7 +54,8 @@ namespace CNORXZ
SizeT dim(); SizeT dim();
Sptr<RangeType> range(); Sptr<RangeType> range();
SizeT getStepSize(SizeT n); SizeT getStepSize(PtrId iptr) const;
Int getOffset(PtrId iptr) const;
String stringMeta() const; String stringMeta() const;
MetaType meta() const; MetaType meta() const;

View file

@ -14,8 +14,8 @@ namespace CNORXZ
*****************/ *****************/
template <typename MetaType> template <typename MetaType>
UIndex<MetaType>::UIndex(const RangePtr& range) : UIndex<MetaType>::UIndex(const RangePtr& range, SizeT pos) :
IndexInterface<UIndex<MetaType>,MetaType>(0), IndexInterface<UIndex<MetaType>,MetaType>(pos),
mRangePtr(rangeCast<MetaType>(range)), mRangePtr(rangeCast<MetaType>(range)),
mMetaPtr(&mRangePtr->get(0)) mMetaPtr(&mRangePtr->get(0))
{} {}
@ -41,6 +41,44 @@ namespace CNORXZ
return *this; return *this;
} }
template <typename MetaType>
UIndex<MetaType> UIndex<MetaType>::operator+(Int n) const
{
return UIndex(mRangePtr, IB::mPos + n);
}
template <typename MetaType>
UIndex<MetaType> UIndex<MetaType>::operator-(Int n) const
{
return UIndex(mRangePtr, IB::mPos - n);
}
template <typename MetaType>
UIndex<MetaType>& UIndex<MetaType>::operator+=(Int n)
{
IB::mPos += n;
return *this;
}
template <typename MetaType>
UIndex<MetaType>& UIndex<MetaType>::operator-=(Int n)
{
IB::mPos -= n;
return *this;
}
template <typename MetaType>
const MetaType& UIndex<MetaType>::operator*() const
{
return mMetaPtr[IB::mPos];
}
template <typename MetaType>
const MetaType* UIndex<MetaType>::operator->() const
{
return mMetaPtr + IB::mPos;
}
template <typename MetaType> template <typename MetaType>
Int UIndex<MetaType>::pp(PtrId idxPtrNum) Int UIndex<MetaType>::pp(PtrId idxPtrNum)
{ {
@ -87,9 +125,15 @@ namespace CNORXZ
} }
template <typename MetaType> template <typename MetaType>
SizeT UIndex<MetaType>::getStepSize(SizeT n) const SizeT UIndex<MetaType>::getStepSize(PtrId iptr) const
{ {
return 1; return iptr == this->ptrId() ? 1 : 0;
}
template <typename MetaType>
Int UIndex<MetaType>::getOffset(PtrId iptr) const
{
return 0;
} }
/* /*
template <typename MetaType> template <typename MetaType>

View file

@ -19,7 +19,7 @@ namespace CNORXZ
typedef IndexInterface<UIndex<MetaType>,MetaType> IB; typedef IndexInterface<UIndex<MetaType>,MetaType> IB;
typedef URange<MetaType> RangeType; typedef URange<MetaType> RangeType;
UIndex(const RangePtr& range); UIndex(const RangePtr& range, SizeT pos = 0);
UIndex& operator=(SizeT pos); UIndex& operator=(SizeT pos);
UIndex& operator++(); UIndex& operator++();
@ -37,7 +37,8 @@ namespace CNORXZ
SizeT dim() const; // = 1 SizeT dim() const; // = 1
Sptr<RangeType> range() const; Sptr<RangeType> range() const;
SizeT getStepSize(SizeT n) const; SizeT getStepSize(PtrId iptr) const;
Int getOffset(PtrId iptr) const;
String stringMeta() const; String stringMeta() const;
const MetaType& meta() const; const MetaType& meta() const;

View file

@ -117,9 +117,15 @@ namespace CNORXZ
} }
template <class Index, typename Meta> template <class Index, typename Meta>
SizeT XIndex<Index,Meta>::getStepSize(SizeT n) const SizeT XIndex<Index,Meta>::getStepSize(PtrId iptr) const
{ {
return mI->getStepSize(n); return mI->getStepSize(iptr);
}
template <class Index, typename Meta>
Int XIndex<Index,Meta>::getOffset(PtrId iptr) const
{
return mI->getOffset(iptr);
} }
template <class Index, typename Meta> template <class Index, typename Meta>

View file

@ -32,7 +32,8 @@ namespace CNORXZ
virtual SizeT dim() const = 0; virtual SizeT dim() const = 0;
virtual RangePtr range() 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 String stringMeta() const = 0;
virtual DType meta() const = 0; virtual DType meta() const = 0;
@ -80,7 +81,8 @@ namespace CNORXZ
virtual SizeT dim() const override final; virtual SizeT dim() const override final;
virtual RangePtr range() 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 String stringMeta() const override final;
virtual DType meta() const override final; virtual DType meta() const override final;

View file

@ -42,7 +42,8 @@ namespace CNORXZ
SizeT dim() const; SizeT dim() const;
Sptr<YRange> range() const; Sptr<YRange> range() const;
SizeT getStepSize(SizeT n) const; SizeT getStepSize(PtrId iptr) const;
Int getOffset(PtrId iptr) const;
String stringMeta() const; String stringMeta() const;
DType meta() const; DType meta() const;

View file

@ -83,9 +83,14 @@ namespace CNORXZ
return mRangePtr; 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 String CIndex::stringMeta() const

View file

@ -116,9 +116,14 @@ namespace CNORXZ
return mI->range(); 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 String DIndex::stringMeta() const

View file

@ -122,7 +122,14 @@ namespace CNORXZ
return mRangePtr; 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); assert(0);
// sub inds !!! // sub inds !!!