diff --git a/src/include/ranges/crange.h b/src/include/ranges/crange.h index 8e96d1a..cfef60b 100644 --- a/src/include/ranges/crange.h +++ b/src/include/ranges/crange.h @@ -2,8 +2,7 @@ /** @file include/ranges/crange.h - @brief ... - + @brief CRange and CIndex declaration. Copyright (c) 2022 Christian Zimmermann. All rights reserved. Mail: chizeta@f3l.de @@ -80,7 +79,7 @@ namespace CNORXZ SizeT operator*() const; /** @copydoc IndexInterface::dim() */ - SizeT dim() const; // = 1 + SizeT dim() const; /** @copydoc IndexInterface::range() */ Sptr range() const; @@ -140,14 +139,14 @@ namespace CNORXZ public: typedef CRange oType; - /** construct and setup factory - @param size size of the range to be constructed + /** Construct and setup factory + @param size Size of the range to be constructed */ CRangeFactory(SizeT size); - /** construct and setup factory - @param size size of the range to be constructed - @param ref range the range to be constructed is related to + /** Construct and setup factory + @param size Size of the range to be constructed + @param ref Range the range to be constructed is related to */ CRangeFactory(SizeT size, RangePtr ref); diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 48febe8..a5468b9 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -2,8 +2,7 @@ /** @file include/ranges/yrange.h - @brief ... - + @brief YRange and YIndex declaration Copyright (c) 2022 Christian Zimmermann. All rights reserved. Mail: chizeta@f3l.de @@ -24,6 +23,13 @@ namespace CNORXZ { + /** **** + Specific index for YRanges. + + A YIndex is a multi-index which consists of a set of sub-indices + and a format. In the case the index is used to access data, this format + determines the linearized memory position for a given sub-index combination. + */ class YIndex : public IndexInterface> { public: @@ -32,59 +38,154 @@ namespace CNORXZ typedef Vector MetaType; INDEX_RANDOM_ACCESS_ITERATOR_DEFS(MetaType); + + /** Default constructor. */ YIndex() = default; + + /** Move constructor. */ YIndex(YIndex&& i) = default; + + /** Move assignment. */ YIndex& operator=(YIndex&& i) = default; - // no defaults: + + /** Copy constructor. + No default copy: Have to copy sub-index instances + */ YIndex(const YIndex& i); + + /** Copy assigment. + No default copy: Have to copy sub-index instances + */ YIndex& operator=(const YIndex& i); + /** Construct from sub-index pointers. + @param is Vector of XIndex pointers. + */ YIndex(const Vector& is); + + /** Construct from sub-index pointers, specify index format. + @param bs Index format (YFormat). + @param is Vector of XIndex pointers. + */ YIndex(const YFormat& bs, const Vector& is); + + /** Construct from a range and an initial lexicographic position + @param range Range to iterate over. + @param lexpos Initial lexicographic position. + */ YIndex(const RangePtr& range, SizeT lexpos = 0); + + /** Construct from a range and an initial lexicographic position, specify format. + @param range Range to iterate over. + @param bs Index format. + @param lexpos Initial lexicographic position. + */ YIndex(const RangePtr& range, const YFormat& bs, SizeT lexpos = 0); + /** @copydoc IndexInterface::operator=(SizeT) */ YIndex& operator=(SizeT lexpos); + + /** @copydoc IndexInterface::operator++() */ YIndex& operator++(); + + /** @copydoc IndexInterface::operator--() */ YIndex& operator--(); - YIndex operator+(Int n) const; // equivalent to applying n times ++ + + /** @copydoc IndexInterface::operator+() */ + YIndex operator+(Int n) const; + + /** @copydoc IndexInterface::operator-() */ YIndex operator-(Int n) const; + + /** @copydoc IndexInterface::operator-(CIndex) */ SizeT operator-(const YIndex& i) const; + + /** @copydoc IndexInterface::operator+=() */ YIndex& operator+=(Int n); + + /** @copydoc IndexInterface::operator-=() */ YIndex& operator-=(Int n); + /** @copydoc IndexInterface::lex() */ SizeT lex() const; + + /** @copydoc IndexInterface::pmax() */ UPos pmax() const; + + /** @copydoc IndexInterface::lmax() */ UPos lmax() const; + + /** @copydoc IndexInterface::id() */ IndexId<0> id() const; + /** @copydoc IndexInterface::operator*() */ Vector operator*() const; + /** @copydoc IndexInterface::dim() */ SizeT dim() const; + + /** @copydoc IndexInterface::range() */ Sptr range() const; + + /** @copydoc IndexInterface::stepSize() */ UPos stepSize(const IndexId<0> id) const; + /** @copydoc IndexInterface::stringMeta() */ String stringMeta() const; + + /** @copydoc IndexInterface::meta() */ Vector meta() const; + + /** @copydoc IndexInterface::at() */ YIndex& at(const Vector& meta); + /** @copydoc IndexInterface::prange() */ + RangePtr prange(const YIndex& last) const; + + /** @copydoc IndexInterface::deepFormat() */ + Vector deepFormat() const; + + /** @copydoc IndexInterface::deepMax() */ + Vector deepMax() const; + + /** @copydoc IndexInterface::reformat() */ + YIndex& reformat(const Vector& f, const Vector& s); + + /** @copydoc IndexInterface::ifor() */ DXpr ifor(const DXpr& xpr, NoF&& f) const; - YIndex& operator()(const Sptr& i); - YIndex& operator()(); - - const DPack& pack() const; - RangePtr prange(const YIndex& last) const; - Vector deepFormat() const; - Vector deepMax() const; - const YFormat& format() const; - const YFormat& lexFormat() const; - YIndex& setFormat(const YFormat& bs); - YIndex& reformat(const Vector& f, const Vector& s); - /** @copydoc IndexInterface::formatIsTrivial() */ bool formatIsTrivial() const; + /** Replace sub-index instances. + All linearized positions are updated accordingly. + @param i Pointer to YIndex which provides the new sub-index instance + */ + YIndex& operator()(const Sptr& i); + + /** Update all linearized positions. */ + YIndex& operator()(); + + /** Get all sub-indices + @return Pack of sub-indices + */ + const DPack& pack() const; + + /** Get index format. + @return The format. + */ + const YFormat& format() const; + + /** Get lexicographic (trivial) index format. + @return The lexicographic format. + */ + const YFormat& lexFormat() const; + + /** Set the index format. + @param bs The new format. + */ + YIndex& setFormat(const YFormat& bs); + private: inline Vector mkFormat() const; inline Vector mkLexFormat() const; @@ -107,26 +208,80 @@ namespace CNORXZ UPos mLMax = 0; }; + /** **** + Specialization: YIndex is a multi-index. + @see index_is_multi + */ template <> struct index_is_multi { static constexpr bool value = true; }; + /** **** + Specialization: YIndex has sub-indices. + @see has_sub + */ template <> struct has_sub { static constexpr bool value = true; }; + /** Create YIndex from an index pack assuming a trivial index format. + @param pack Dynamic index pack. + @return The created YIndex. + */ YIndex yindex(const DPack& pack); + + /** Create YIndex from sub-indices assuming a trivial index format. + @param is Vector of pointers to the sub-indices used in the YIndex. + @return The created YIndex. + */ YIndex yindex(const Vector& is); + + /** Create YIndex from an index pack assuming a trivial index format. + @param pack Dynamic index pack. + @return A shared pointer to the created YIndex. + */ Sptr yindexPtr(const DPack& is); + + /** Create YIndex from sub-indices assuming a trivial index format. + @param is Vector of pointers to the sub-indices used in the YIndex. + @return A shared pointer to the created YIndex. + */ Sptr yindexPtr(const Vector& is); + + /** Create YIndex from sub-indices. + @param is Vector of pointers to the sub-indices used in the YIndex. + @param bs Index format. + @return A shared pointer to the created YIndex. + */ Sptr yindexPtr(const Vector& bs, const Vector& is); + /** **** + Specific factory for YRange. + */ class YRangeFactory : public RangeFactoryBase { public: + + /** Construct and setup factory. + @param rvec Vector of ranges i.e. the sub-ranges the YRange consists of + */ YRangeFactory(const Vector& rvec); + + /** Construct and setup factory. + @param rvec Vector of ranges i.e. the sub-ranges the YRange consists of (move) + */ YRangeFactory(Vector&& rvec); + + /** Construct and setup factory. + @param rvec Vector of ranges i.e. the sub-ranges the YRange consists of + @param ref Range the range to be constructed is related to + */ YRangeFactory(const Vector& rvec, const RangePtr& ref); + + /** Construct and setup factory. + @param rvec Vector of ranges i.e. the sub-ranges the YRange consists of (move) + @param ref Range the range to be constructed is related to + */ YRangeFactory(Vector&& rvec, const RangePtr& ref); private: @@ -138,6 +293,13 @@ namespace CNORXZ }; + /** **** + Dynamic multi-dimensional range + + Dimension and sub-range types are determined at runtime + The size of the range is given by the product of the + sizes of all sub-ranges. + */ class YRange : public RangeInterface { public: @@ -169,8 +331,16 @@ namespace CNORXZ SERIALIZATION_FUNCTIONS_NOPUB; }; + /** Create YRange from sub-ranges. + @param rs Vector of pointers to the sub-ranges used by the YRange. + @return A shared pointer to the created YRange. + */ RangePtr yrange(const Vector& rs); - + + /** **** + Specialize RangeCast for casts to YRange. + @see RangeCast + */ template <> struct RangeCast {