index pack

This commit is contained in:
Christian Zimmermann 2022-12-31 15:18:26 +01:00
parent 1ab0c21667
commit 0980934706
7 changed files with 189 additions and 2 deletions

View file

@ -0,0 +1,61 @@
#ifndef __cxz_index_pack_cc_h__
#define __cxz_index_pack_cc_h__
#include "index_pack.h"
namespace CNORXZ
{
template <class... Indices>
constexpr SPack<Indices...>::SPack(const Sptr<Indices>&... is) :
mIs(is...)
{}
template <class... Indices>
constexpr SPack<Indices...>::SPack(const Tuple<Sptr<Indices>...>& is) :
mIs(is)
{}
template <class... Indices>
constexpr const Tuple<Sptr<Indices>...>& SPack<Indices...>::all() const
{
return mIs;
}
template <class... Indices>
template <SizeT I>
constexpr decltype(auto) SPack<Indices...>::get(std::integral_constant<SizeT,I> i) const
{
return std::get<I>(mIs);
}
template <class... Indices>
template <SizeT I>
constexpr decltype(auto) SPack<Indices...>::operator[](std::integral_constant<SizeT,I> i) const
{
return get(i);
}
template <class... Indices>
template <class Index>
constexpr decltype(auto) SPack<Indices...>::rmul(const Sptr<Index>& i) const
{
return SPack<Indices...,Index>( std::tuple_cat(mIs,i) );
}
template <class... Indices>
template <class Index>
constexpr decltype(auto) SPack<Indices...>::lmul(const Sptr<Index>& i) const
{
return SPack<Index,Indices...>( std::tuple_cat(i, mIs) );
}
template <class... Indices>
template <class... Indices2>
constexpr decltype(auto) SPack<Indices...>::mul(const SPack<Indices2...>& p) const
{
return SPack<Indices...,Indices2...>( std::tuple_cat(mIs, all()) );
}
}
#endif

View file

@ -0,0 +1,61 @@
#ifndef __cxz_index_pack_h__
#define __cxz_index_pack_h__
#include "base/base.h"
#include "xindex.h"
namespace CNORXZ
{
template <class... Indices>
class SPack
{
public:
SP_DEFAULT_MEMBERS(constexpr,SPack);
constexpr SPack(const Sptr<Indices>&... is);
constexpr SPack(const Tuple<Sptr<Indices>...>& is);
constexpr const Tuple<Sptr<Indices>...>& all() const;
constexpr SizeT size() const;
template <SizeT I>
constexpr decltype(auto) get(std::integral_constant<SizeT,I> i) const;
template <SizeT I>
constexpr decltype(auto) operator[](std::integral_constant<SizeT,I> i) const;
template <class Index>
constexpr decltype(auto) rmul(const Sptr<Index>& i) const;
template <class Index>
constexpr decltype(auto) lmul(const Sptr<Index>& i) const;
template <class... Indices2>
constexpr decltype(auto) mul(const SPack<Indices2...>& p) const;
private:
Tuple<Sptr<Indices>...> mIs;
};
class DPack
{
public:
DEFAULT_MEMBERS(DPack);
DPack(const Vector<XIndexPtr>& is);
DPack(Vector<XIndexPtr>&& is);
const Vector<XIndexPtr>& all() const;
SizeT size() const;
const XIndexPtr& get(SizeT i) const;
const XIndexPtr& operator[](SizeT i) const;
DPack rmul(const XIndexPtr& i) const;
DPack lmul(const XIndexPtr& i) const;
DPack mul(const DPack& p) const;
private:
Vector<XIndexPtr> mIs;
};
}
#endif

View file

@ -10,7 +10,8 @@
namespace CNORXZ namespace CNORXZ
{ {
// template <class FormatT, class... Indices>
// -> Format + IndexTuple
template <class BlockType, class... Indices> template <class BlockType, class... Indices>
class GMIndex : public IndexInterface<GMIndex<BlockType,Indices...>, class GMIndex : public IndexInterface<GMIndex<BlockType,Indices...>,
Tuple<typename Indices::MetaType...> > Tuple<typename Indices::MetaType...> >
@ -31,6 +32,8 @@ namespace CNORXZ
constexpr GMIndex(const GMIndex& i); constexpr GMIndex(const GMIndex& i);
constexpr GMIndex& operator=(const GMIndex& i); constexpr GMIndex& operator=(const GMIndex& i);
//constexpr GMIndex(const SPack<Indices...>& is);
//constexpr GMIndex(const FormatT& format, const SPack<Indices...>& is);
constexpr GMIndex(const Indices&... is); constexpr GMIndex(const Indices&... is);
constexpr GMIndex(const BlockType& blockSizes, const Indices&... is); constexpr GMIndex(const BlockType& blockSizes, const Indices&... is);
constexpr GMIndex(const Sptr<Indices>&... is); constexpr GMIndex(const Sptr<Indices>&... is);
@ -113,7 +116,7 @@ namespace CNORXZ
IndexPack mIPack; IndexPack mIPack;
typedef RemoveRef<decltype(mkLexBlockSizes(mIPack,Isqr<0,NI-1>{}))> LexBlockType; typedef RemoveRef<decltype(mkLexBlockSizes(mIPack,Isqr<0,NI-1>{}))> LexBlockType;
LexBlockType mLexBlockSizes; LexBlockType mLexBlockSizes;
BlockType mBlockSizes; BlockType mBlockSizes; // -> FormatT
SizeT mLex; SizeT mLex;
typedef RemoveRef<decltype(mkLMax(mIPack))> LMaxT; typedef RemoveRef<decltype(mkLMax(mIPack))> LMaxT;
LMaxT mLMax; LMaxT mLMax;

View file

@ -8,3 +8,4 @@
#include "dindex.cc.h" #include "dindex.cc.h"
#include "lindex.cc.h" #include "lindex.cc.h"
#include "index_mul.cc.h" #include "index_mul.cc.h"
#include "index_pack.cc.h"

View file

@ -10,5 +10,6 @@
#include "dindex.h" #include "dindex.h"
#include "lindex.h" #include "lindex.h"
#include "index_mul.h" #include "index_mul.h"
#include "index_pack.h"
#include "ranges.cc.h" #include "ranges.cc.h"

View file

@ -6,6 +6,7 @@ set(libcnorxz_a_SOURCES
${CMAKE_SOURCE_DIR}/src/lib/ranges/yrange.cc ${CMAKE_SOURCE_DIR}/src/lib/ranges/yrange.cc
${CMAKE_SOURCE_DIR}/src/lib/ranges/crange.cc ${CMAKE_SOURCE_DIR}/src/lib/ranges/crange.cc
${CMAKE_SOURCE_DIR}/src/lib/ranges/dindex.cc ${CMAKE_SOURCE_DIR}/src/lib/ranges/dindex.cc
${CMAKE_SOURCE_DIR}/src/lib/ranges/index_pack.cc
) )
add_library(cnorxz_obj OBJECT add_library(cnorxz_obj OBJECT

View file

@ -0,0 +1,59 @@
#include "ranges/index_pack.h"
namespace CNORXZ
{
DPack::DPack(const Vector<XIndexPtr>& is) :
mIs(is)
{}
DPack::DPack(Vector<XIndexPtr>&& is) :
mIs(std::forward<Vector<XIndexPtr>>(is))
{}
const Vector<XIndexPtr>& DPack::all() const
{
return mIs;
}
SizeT DPack::size() const
{
return mIs.size();
}
const XIndexPtr& DPack::get(SizeT i) const
{
return mIs[i];
}
const XIndexPtr& DPack::operator[](SizeT i) const
{
return get(i);
}
DPack DPack::rmul(const XIndexPtr& i) const
{
auto o = mIs;
o.push_back(i);
return DPack(std::move(o));
}
DPack DPack::lmul(const XIndexPtr& i) const
{
Vector<XIndexPtr> o;
o.reserve(size()+1);
o.push_back(i);
o.insert(o.end(), mIs.begin(), mIs.end());
return DPack(std::move(o));
}
DPack DPack::mul(const DPack& p) const
{
Vector<XIndexPtr> o;
o.reserve(size()+p.size());
o.insert(o.end(), mIs.begin(), mIs.end());
o.insert(o.end(), p.all().begin(), p.all().end());
return DPack(std::move(o));
}
}