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
Sptr<RangeType> range() const;
SizeT getStepSize(SizeT n) const;
SizeT getStepSize(PtrId iptr) const;
Int getOffset(PtrId iptr) const;
String stringMeta() const;
SizeT meta() const;

View file

@ -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;

View file

@ -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<I,MetaType> mRel;
};
template <class I, typename MetaType>

View file

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

View file

@ -14,8 +14,8 @@ namespace CNORXZ
*****************/
template <typename MetaType>
UIndex<MetaType>::UIndex(const RangePtr& range) :
IndexInterface<UIndex<MetaType>,MetaType>(0),
UIndex<MetaType>::UIndex(const RangePtr& range, SizeT pos) :
IndexInterface<UIndex<MetaType>,MetaType>(pos),
mRangePtr(rangeCast<MetaType>(range)),
mMetaPtr(&mRangePtr->get(0))
{}
@ -41,6 +41,44 @@ namespace CNORXZ
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>
Int UIndex<MetaType>::pp(PtrId idxPtrNum)
{
@ -87,9 +125,15 @@ namespace CNORXZ
}
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>

View file

@ -19,7 +19,7 @@ namespace CNORXZ
typedef IndexInterface<UIndex<MetaType>,MetaType> IB;
typedef URange<MetaType> 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<RangeType> range() const;
SizeT getStepSize(SizeT n) const;
SizeT getStepSize(PtrId iptr) const;
Int getOffset(PtrId iptr) const;
String stringMeta() const;
const MetaType& meta() const;

View file

@ -117,9 +117,15 @@ namespace CNORXZ
}
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>

View file

@ -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;

View file

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

View file

@ -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

View file

@ -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

View file

@ -122,7 +122,14 @@ 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 !!!