2018-02-14 21:37:18 +01:00
|
|
|
|
|
|
|
#include "ranges/anonymous_range.h"
|
2020-08-27 12:00:47 +02:00
|
|
|
#include "ranges/ranges_header.cc.h"
|
2021-07-28 20:59:31 +02:00
|
|
|
#include "cxz_assert.h"
|
2018-02-14 21:37:18 +01:00
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2018-02-14 21:37:18 +01:00
|
|
|
{
|
|
|
|
/******************************
|
|
|
|
* AnonymousRangeFactory *
|
|
|
|
******************************/
|
2018-07-15 15:22:15 +02:00
|
|
|
|
2018-07-16 15:55:55 +02:00
|
|
|
AnonymousRangeFactory::AnonymousRangeFactory()
|
|
|
|
{
|
|
|
|
mProd = std::shared_ptr<oType>( new AnonymousRange() );
|
|
|
|
}
|
2018-11-03 22:03:35 +01:00
|
|
|
|
2018-07-16 15:55:55 +02:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > AnonymousRangeFactory::mAleadyCreated;
|
2018-11-03 22:03:35 +01:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
AnonymousRangeFactory::AnonymousRangeFactory(const vector<std::shared_ptr<RangeBase>>& origs)
|
2018-11-03 22:03:35 +01:00
|
|
|
{
|
|
|
|
mProd = std::shared_ptr<oType>( new AnonymousRange( origs ) );
|
|
|
|
}
|
2018-07-16 14:44:55 +02:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
std::shared_ptr<RangeBase> AnonymousRangeFactory::checkIfCreated(const vector<std::shared_ptr<RangeBase> >& pvec)
|
2018-07-15 15:22:15 +02:00
|
|
|
{
|
|
|
|
std::shared_ptr<RangeBase> out;
|
|
|
|
bool check = false;
|
|
|
|
for(auto& x: mAleadyCreated){
|
|
|
|
if(x.second.size() == pvec.size()){
|
|
|
|
check = true;
|
2018-07-16 00:12:05 +02:00
|
|
|
for(size_t i = 0; i != x.second.size(); ++i){
|
|
|
|
if(x.second[i] != reinterpret_cast<std::intptr_t>( pvec[i].get() ) ){
|
2018-07-15 15:22:15 +02:00
|
|
|
check = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(check == true){
|
|
|
|
out = x.first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(not check){
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<std::intptr_t> app(pvec.size());
|
2018-07-15 15:22:15 +02:00
|
|
|
for(size_t i = 0; i != app.size(); ++i){
|
2018-07-16 00:12:05 +02:00
|
|
|
app[i] = reinterpret_cast<std::intptr_t>( pvec[i].get() );
|
2018-07-15 15:22:15 +02:00
|
|
|
}
|
|
|
|
mAleadyCreated[mProd] = app;
|
|
|
|
out = mProd;
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2018-05-20 20:03:44 +02:00
|
|
|
|
2018-02-14 21:37:18 +01:00
|
|
|
std::shared_ptr<RangeBase> AnonymousRangeFactory::create()
|
|
|
|
{
|
2018-07-16 00:12:05 +02:00
|
|
|
mProd = checkIfCreated(std::dynamic_pointer_cast<AnonymousRange>(mProd)->mOrig);
|
2018-07-15 15:22:15 +02:00
|
|
|
setSelf();
|
2018-07-16 14:44:55 +02:00
|
|
|
mProductCreated = true;
|
2018-02-14 21:37:18 +01:00
|
|
|
return mProd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************
|
|
|
|
* AnonymousRange *
|
|
|
|
***********************/
|
|
|
|
|
|
|
|
size_t AnonymousRange::get(size_t pos) const
|
|
|
|
{
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t AnonymousRange::getMeta(size_t metaPos) const
|
|
|
|
{
|
|
|
|
return metaPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t AnonymousRange::size() const
|
|
|
|
{
|
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t AnonymousRange::dim() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2018-07-19 21:27:09 +02:00
|
|
|
|
2018-07-28 15:27:11 +02:00
|
|
|
SpaceType AnonymousRange::spaceType() const
|
|
|
|
{
|
|
|
|
return SpaceType::ANON;
|
|
|
|
}
|
2018-08-06 19:20:57 +02:00
|
|
|
|
|
|
|
bool AnonymousRange::isEmpty() const
|
|
|
|
{
|
|
|
|
return mEmpty;
|
|
|
|
}
|
2019-03-14 14:20:38 +01:00
|
|
|
|
2019-03-19 20:58:59 +01:00
|
|
|
vector<size_t> AnonymousRange::typeNum() const
|
2019-03-14 14:20:38 +01:00
|
|
|
{
|
2019-03-19 20:58:59 +01:00
|
|
|
vector<size_t> o;
|
|
|
|
for(auto& x: mOrig){
|
|
|
|
auto tn = x->typeNum();
|
|
|
|
o.insert(o.end(), tn.begin(), tn.end());
|
|
|
|
}
|
|
|
|
return o;
|
2019-03-14 14:20:38 +01:00
|
|
|
}
|
2018-07-28 15:27:11 +02:00
|
|
|
|
2019-03-14 14:20:38 +01:00
|
|
|
size_t AnonymousRange::cmeta(char* target, size_t pos) const
|
|
|
|
{
|
|
|
|
size_t out = 0;
|
2019-03-19 20:58:59 +01:00
|
|
|
size_t off = cmetaSize();
|
2019-03-14 14:20:38 +01:00
|
|
|
for(size_t i = mOrig.size(); i != 0; --i) {
|
|
|
|
auto& x = mOrig[i-1];
|
|
|
|
const size_t redpos = pos % x->size();
|
2019-03-19 20:58:59 +01:00
|
|
|
const size_t s = x->cmetaSize();
|
|
|
|
out += s;
|
|
|
|
off -= s;
|
2019-03-14 14:20:38 +01:00
|
|
|
pos -= redpos;
|
|
|
|
pos /= x->size();
|
2019-03-19 20:58:59 +01:00
|
|
|
x->cmeta(target+off,redpos);
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t AnonymousRange::cmetaSize() const
|
|
|
|
{
|
|
|
|
size_t out = 0;
|
|
|
|
for(size_t i = mOrig.size(); i != 0; --i) {
|
|
|
|
auto& x = mOrig[i-1];
|
|
|
|
out += x->cmetaSize();
|
2019-03-14 14:20:38 +01:00
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2018-07-21 18:05:53 +02:00
|
|
|
std::string AnonymousRange::stringMeta(size_t pos) const
|
|
|
|
{
|
|
|
|
std::string out = "[ ";
|
2018-07-29 22:48:22 +02:00
|
|
|
//size_t xpos = pos;
|
2018-07-21 18:05:53 +02:00
|
|
|
for(size_t i = mOrig.size(); i != 0; --i) {
|
|
|
|
auto& x = mOrig[i-1];
|
|
|
|
const size_t redpos = pos % x->size();
|
|
|
|
out = ( (i == mOrig.size()) ? out : out + " , " ) + x->stringMeta(redpos);
|
2018-07-29 22:48:22 +02:00
|
|
|
pos -= redpos;
|
|
|
|
pos /= x->size();
|
2018-07-21 18:05:53 +02:00
|
|
|
}
|
|
|
|
out += " ]";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<char> AnonymousRange::data() const
|
2018-07-21 18:05:53 +02:00
|
|
|
{
|
2018-11-07 10:58:07 +01:00
|
|
|
DataHeader h = dataHeader();
|
2019-02-13 21:59:13 +01:00
|
|
|
vector<char> out;
|
2018-07-21 18:05:53 +02:00
|
|
|
char* hcp = reinterpret_cast<char*>(&h);
|
|
|
|
out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
|
|
|
|
for(auto& x: mOrig){
|
|
|
|
auto part = x->data();
|
|
|
|
out.insert(out.end(), part.begin(), part.end());
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
2018-11-07 10:58:07 +01:00
|
|
|
|
|
|
|
DataHeader AnonymousRange::dataHeader() const
|
|
|
|
{
|
|
|
|
DataHeader h;
|
|
|
|
h.spaceType = static_cast<int>( SpaceType::ANON );
|
|
|
|
h.metaSize = mOrig.size();
|
|
|
|
h.multiple = 1;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2018-07-19 21:27:09 +02:00
|
|
|
size_t AnonymousRange::anonymousDim() const
|
|
|
|
{
|
|
|
|
return mOrig.size();
|
|
|
|
}
|
|
|
|
|
2018-02-14 21:37:18 +01:00
|
|
|
typename AnonymousRange::IndexType AnonymousRange::begin() const
|
|
|
|
{
|
|
|
|
AnonymousIndex i
|
2018-07-16 15:55:55 +02:00
|
|
|
(std::dynamic_pointer_cast<AnonymousRange>
|
|
|
|
( std::shared_ptr<RangeBase>(RB::mThis) ) );
|
2018-02-14 21:37:18 +01:00
|
|
|
i = 0;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
typename AnonymousRange::IndexType AnonymousRange::end() const
|
|
|
|
{
|
|
|
|
AnonymousIndex i
|
2018-07-16 15:55:55 +02:00
|
|
|
(std::dynamic_pointer_cast<AnonymousRange>
|
|
|
|
( std::shared_ptr<RangeBase>(RB::mThis) ) );
|
2018-02-14 21:37:18 +01:00
|
|
|
i = size();
|
|
|
|
return i;
|
|
|
|
}
|
2018-04-28 17:33:57 +02:00
|
|
|
|
2018-05-20 20:03:44 +02:00
|
|
|
|
2018-04-28 17:33:57 +02:00
|
|
|
std::shared_ptr<RangeBase> AnonymousRange::sub(size_t num) const
|
|
|
|
{
|
|
|
|
return mOrig.at(num);
|
|
|
|
}
|
2018-09-14 17:50:40 +02:00
|
|
|
|
2019-01-18 17:49:58 +01:00
|
|
|
std::shared_ptr<AnonymousRange> AnonymousRange::sreplace(const std::shared_ptr<RangeBase> in, size_t num) const
|
2018-09-14 17:50:40 +02:00
|
|
|
{
|
2020-09-23 14:14:47 +02:00
|
|
|
MA_ASSERT(mOrig[num]->size() == in->size(),
|
|
|
|
std::string("replaced range has different size than given range (")
|
|
|
|
+std::to_string(mOrig[num]->size())+" vs "+std::to_string(in->size())+")");
|
2019-01-18 17:49:58 +01:00
|
|
|
auto tmp = mOrig;
|
|
|
|
tmp[num] = in;
|
|
|
|
AnonymousRangeFactory arf(tmp);
|
|
|
|
return std::dynamic_pointer_cast<AnonymousRange>(arf.create());
|
2018-09-14 17:50:40 +02:00
|
|
|
}
|
2018-11-02 18:58:58 +01:00
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
std::shared_ptr<AnonymousRange> AnonymousRange::sreplace(const vector<std::shared_ptr<RangeBase>>& in, size_t num) const
|
2018-12-18 12:44:50 +01:00
|
|
|
{
|
|
|
|
size_t nsize = 1;
|
|
|
|
for(auto& x: in){
|
|
|
|
nsize *= x->size();
|
|
|
|
}
|
2020-09-23 14:14:47 +02:00
|
|
|
MA_ASSERT(mOrig[num]->size() == nsize,
|
|
|
|
std::string("replaced range has different size than given range (")
|
|
|
|
+std::to_string(mOrig[num]->size())+" vs "+std::to_string(nsize)+")");
|
2018-12-18 12:44:50 +01:00
|
|
|
auto norig = mOrig;
|
|
|
|
norig.resize(mOrig.size() + in.size() - 1);
|
|
|
|
for(size_t i = 0; i != num; ++i){
|
|
|
|
norig[i] = mOrig[i];
|
|
|
|
}
|
|
|
|
for(size_t i = 0; i != in.size(); ++i){
|
|
|
|
norig[num+i] = in[i];
|
|
|
|
}
|
|
|
|
for(size_t i = num + 1 ; i < mOrig.size(); ++i){
|
|
|
|
norig[in.size()+i-1] = mOrig[i];
|
|
|
|
}
|
2019-01-18 17:49:58 +01:00
|
|
|
//mOrig = std::move( norig );
|
|
|
|
AnonymousRangeFactory arf(norig);
|
|
|
|
return std::dynamic_pointer_cast<AnonymousRange>(arf.create());
|
2018-12-18 12:44:50 +01:00
|
|
|
}
|
|
|
|
|
2019-03-19 10:33:07 +01:00
|
|
|
std::shared_ptr<AnonymousRange> AnonymousRange::sreplace(const std::shared_ptr<RangeBase>& in,
|
|
|
|
const vector<size_t>& num) const
|
|
|
|
{
|
2019-08-29 20:40:39 +02:00
|
|
|
if(num.size() != 0){
|
|
|
|
size_t cnt = num[0];
|
|
|
|
size_t rep_size = 1;
|
|
|
|
// assert continuous ordering or replaced ranges:
|
|
|
|
for(auto& x: num){
|
|
|
|
assert(cnt++ == x);
|
|
|
|
rep_size *= mOrig[x]->size();
|
|
|
|
}
|
2020-09-23 14:14:47 +02:00
|
|
|
MA_ASSERT(rep_size == in->size(),
|
|
|
|
std::string("replaced range has different size than given range (")
|
|
|
|
+std::to_string(rep_size)+" vs "+std::to_string(in->size())+")");
|
2019-08-29 20:40:39 +02:00
|
|
|
vector<std::shared_ptr<RangeBase>> norig;
|
|
|
|
norig.reserve(mOrig.size()-num.size()+1);
|
|
|
|
norig.insert(norig.end(),mOrig.begin(),mOrig.begin()+num[0]);
|
|
|
|
norig.push_back(in);
|
|
|
|
norig.insert(norig.end(),mOrig.begin()+num.back()+1,mOrig.end());
|
|
|
|
AnonymousRangeFactory arf(norig);
|
|
|
|
return std::dynamic_pointer_cast<AnonymousRange>(arf.create());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return std::dynamic_pointer_cast<AnonymousRange>( std::shared_ptr<RangeBase>(RB::mThis) );
|
2019-03-19 10:33:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 21:59:13 +01:00
|
|
|
const vector<std::shared_ptr<RangeBase> >& AnonymousRange::orig() const
|
2018-11-02 18:58:58 +01:00
|
|
|
{
|
|
|
|
return mOrig;
|
|
|
|
}
|
2018-11-03 22:03:35 +01:00
|
|
|
|
2019-07-05 17:40:26 +02:00
|
|
|
GenSingleRange<size_t,SpaceType::ANON,MUI>::GenSingleRange(const vector<std::shared_ptr<RangeBase>>& origs) :
|
2018-11-03 22:03:35 +01:00
|
|
|
RangeInterface<AnonymousIndex>(),
|
|
|
|
mOrig(origs)
|
|
|
|
{
|
|
|
|
mSize = 1;
|
|
|
|
for(auto& x: mOrig){
|
|
|
|
mSize *= x->size();
|
|
|
|
}
|
|
|
|
if(mOrig.size()){
|
|
|
|
mEmpty = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-14 21:37:18 +01:00
|
|
|
/*****************
|
|
|
|
* Functions *
|
|
|
|
*****************/
|
|
|
|
|
|
|
|
std::shared_ptr<AnonymousRange> defaultRange(size_t size )
|
|
|
|
{
|
|
|
|
AnonymousRangeFactory arf
|
2018-07-16 15:55:55 +02:00
|
|
|
( std::dynamic_pointer_cast<AnonymousRange>
|
|
|
|
(AnonymousRange::factory().create() ) );
|
2018-02-14 21:37:18 +01:00
|
|
|
return std::dynamic_pointer_cast<AnonymousRange>( arf.create() );
|
|
|
|
}
|
2018-07-16 00:12:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
} // end namespace CNORXZ
|