add further sreplace function to anonymous range
This commit is contained in:
parent
b2290e14e5
commit
8ed5d01c46
2 changed files with 22 additions and 0 deletions
|
@ -97,6 +97,8 @@ namespace MultiArrayTools
|
|||
|
||||
std::shared_ptr<AnonymousRange> sreplace(const std::shared_ptr<RangeBase> in, size_t num) const;
|
||||
std::shared_ptr<AnonymousRange> sreplace(const vector<std::shared_ptr<RangeBase>>& in, size_t num) const;
|
||||
std::shared_ptr<AnonymousRange> sreplace(const std::shared_ptr<RangeBase>& in,
|
||||
const vector<size_t>& num) const;
|
||||
|
||||
bool isEmpty() const;
|
||||
|
||||
|
|
|
@ -210,6 +210,26 @@ namespace MultiArrayTools
|
|||
return std::dynamic_pointer_cast<AnonymousRange>(arf.create());
|
||||
}
|
||||
|
||||
std::shared_ptr<AnonymousRange> AnonymousRange::sreplace(const std::shared_ptr<RangeBase>& in,
|
||||
const vector<size_t>& num) const
|
||||
{
|
||||
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();
|
||||
}
|
||||
assert(rep_size == in->size());
|
||||
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());
|
||||
}
|
||||
|
||||
const vector<std::shared_ptr<RangeBase> >& AnonymousRange::orig() const
|
||||
{
|
||||
return mOrig;
|
||||
|
|
Loading…
Reference in a new issue