2017-12-24 18:14:07 +01:00
|
|
|
// -*- C++ -*-
|
|
|
|
|
|
|
|
#ifndef __index_info_h__
|
|
|
|
#define __index_info_h__
|
|
|
|
|
|
|
|
#include <cstdlib>
|
2017-12-25 01:35:09 +01:00
|
|
|
#include <cstdint>
|
2017-12-24 18:14:07 +01:00
|
|
|
#include <vector>
|
2017-12-25 01:35:09 +01:00
|
|
|
#include <memory>
|
|
|
|
#include "vindex_base.h"
|
|
|
|
#include "index_type.h"
|
2017-12-24 18:14:07 +01:00
|
|
|
|
|
|
|
namespace MultiArrayTools
|
|
|
|
{
|
|
|
|
class IndexInfo;
|
|
|
|
|
|
|
|
class IndexInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-12-25 01:35:09 +01:00
|
|
|
IndexInfo(IndexInfo&& in) = default;
|
|
|
|
IndexInfo& operator=(IndexInfo&& in) = default;
|
2018-02-13 21:36:41 +01:00
|
|
|
IndexInfo(const IndexInfo& in) = default;
|
|
|
|
IndexInfo& operator=(const IndexInfo& in) = default;
|
2017-12-25 01:35:09 +01:00
|
|
|
|
2017-12-24 18:14:07 +01:00
|
|
|
template <class IndexClass>
|
|
|
|
IndexInfo(const IndexClass& ind, size_t stepSize = 1);
|
2017-12-25 01:35:09 +01:00
|
|
|
|
2017-12-25 13:44:55 +01:00
|
|
|
template <class IndexClass>
|
|
|
|
IndexInfo& reassign(const IndexClass& ind, size_t stepSize = 1);
|
|
|
|
|
2017-12-25 01:35:09 +01:00
|
|
|
bool operator==(const IndexInfo& in) const;
|
|
|
|
bool operator!=(const IndexInfo& in) const;
|
|
|
|
|
|
|
|
bool operator<=(const IndexInfo& in) const;
|
|
|
|
bool operator<(const IndexInfo& in) const;
|
|
|
|
bool operator>(const IndexInfo& in) const;
|
|
|
|
bool operator>=(const IndexInfo& in) const;
|
|
|
|
|
2017-12-24 18:14:07 +01:00
|
|
|
|
|
|
|
const IndexInfo* getPtr(size_t inum) const;
|
|
|
|
std::intptr_t getPtrNum() const;
|
|
|
|
size_t dim() const;
|
2017-12-25 01:35:09 +01:00
|
|
|
size_t max() const;
|
2017-12-24 18:14:07 +01:00
|
|
|
size_t getStepSize(size_t inum) const;
|
|
|
|
size_t getStepSize() const;
|
2017-12-25 01:35:09 +01:00
|
|
|
IndexType type() const;
|
|
|
|
|
2017-12-24 18:14:07 +01:00
|
|
|
private:
|
2017-12-25 01:35:09 +01:00
|
|
|
|
|
|
|
IndexInfo() = default;
|
|
|
|
|
2017-12-24 18:14:07 +01:00
|
|
|
std::vector<IndexInfo> mNext;
|
|
|
|
std::intptr_t mPtrNum;
|
|
|
|
size_t mDim;
|
2017-12-25 01:35:09 +01:00
|
|
|
size_t mMax;
|
2017-12-24 18:14:07 +01:00
|
|
|
size_t mStepSize;
|
2017-12-25 01:35:09 +01:00
|
|
|
IndexType mType;
|
2017-12-24 18:14:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class IndexClass>
|
|
|
|
IndexInfo::IndexInfo(const IndexClass& ind, size_t stepSize) :
|
|
|
|
mNext(ind.infoVec()),
|
|
|
|
mPtrNum( reinterpret_cast<std::intptr_t>( &ind ) ),
|
2017-12-25 01:35:09 +01:00
|
|
|
mDim(ind.vrange()->dim()),
|
|
|
|
mMax(ind.max()),
|
2017-12-26 15:13:50 +01:00
|
|
|
mStepSize(stepSize),
|
|
|
|
mType(ind.type())
|
2017-12-24 18:14:07 +01:00
|
|
|
{}
|
2017-12-25 13:44:55 +01:00
|
|
|
|
|
|
|
template <class IndexClass>
|
|
|
|
IndexInfo& IndexInfo::reassign(const IndexClass& ind, size_t stepSize)
|
|
|
|
{
|
|
|
|
IndexInfo ii(ind, stepSize);
|
|
|
|
(*this) = std::move(ii);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-02-13 21:36:41 +01:00
|
|
|
std::vector<IndexInfo> getRootIndices(const IndexInfo& info);
|
|
|
|
|
2018-02-14 00:38:44 +01:00
|
|
|
inline size_t getStepSize(const IndexInfo& ii, std::intptr_t j)
|
|
|
|
{
|
|
|
|
if(ii.type() == IndexType::SINGLE){
|
|
|
|
return ii.getPtrNum() == j ? 1 : 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
size_t ss = 0;
|
|
|
|
size_t sx = 1;
|
|
|
|
for(size_t i = 0; i != ii.dim(); ++i){
|
|
|
|
const IndexInfo& itmp = *ii.getPtr(ii.dim()-i-1);
|
|
|
|
const size_t max = itmp.max();
|
|
|
|
const size_t tmp = getStepSize(itmp, j);
|
|
|
|
ss += tmp * sx;
|
|
|
|
sx *= max;
|
|
|
|
}
|
|
|
|
return ss;
|
|
|
|
}
|
|
|
|
}
|
2018-02-13 21:36:41 +01:00
|
|
|
|
|
|
|
size_t getStepSize(const std::vector<IndexInfo>& iv, std::intptr_t j);
|
2017-12-24 18:14:07 +01:00
|
|
|
} // end namespace MultiArrayTools
|
|
|
|
|
|
|
|
#endif
|