CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
crange.cc
Go to the documentation of this file.
1// -*- C++ -*-
12#include "ranges/ranges.h"
13#include "ranges/prange.h"
14#include "operation/operation.h"
15
16namespace CNORXZ
17{
18 /*=====================================================+
19 | Implementations of member functions of CIndex |
20 +=====================================================*/
21
22 CIndex::CIndex(const RangePtr& range, SizeT pos) :
23 IndexInterface<CIndex,SizeT>(pos), mRangePtr(rangeCast<RangeType>(range))
24 {}
25
27 {
29 return *this;
30 }
31
33 {
34 ++IB::mPos;
35 return *this;
36 }
37
39 {
40 --IB::mPos;
41 return *this;
42 }
43
45 {
46 return CIndex(mRangePtr, IB::mPos + n);
47 }
48
50 {
51 return CIndex(mRangePtr, IB::mPos - n);
52 }
53
55 {
56 return lex() - i.lex();
57 }
58
60 {
61 IB::mPos += n;
62 return *this;
63 }
64
66 {
67 IB::mPos -= n;
68 return *this;
69 }
70
72 {
73 return IB::mPos;
74 }
75
77 {
78 return UPos(mRangePtr->size());
79 }
80
82 {
83 return UPos(mRangePtr->size());
84 }
85
87 {
88 return IndexId<0>(this->ptrId());
89 }
90
92 {
93 return IB::mPos;
94 }
95
97 {
98 return 1;
99 }
100
102 {
103 return mRangePtr;
104 }
105
107 {
108 return toString(IB::mPos);
109 }
110
112 {
113 return IB::mPos;
114 }
115
117 {
119 return *this;
120 }
121
123 {
124 // preliminary solution (TODO: implement xpr that simply returns PosT value):
125 static Vector<SizeT> m;
126 if(m.size() < _this->lmax().val()){
127 m.resize(_this->lmax().val());
128 for(SizeT i = 0; i != m.size(); ++i) {
129 m[i] = i;
130 }
131 }
132 return coproot(m.data(), _this);
133 }
134
136 {
137 CXZ_ASSERT(last >= *this, "got last index position (" << last.lex()
138 << ") smaller than begin index position (" << lex() << ")");
139 const SizeT beginPos = lex();
140 Vector<SizeT> parts(last.lex() - beginPos + 1);
141 for(auto i = *this; i != last+1; ++i){
142 parts[i.lex()-beginPos] = i.lex();
143 }
144 return CNORXZ::prange(mRangePtr, parts);
145 }
146
148 {
149 return 1;
150 }
151
153 {
154 return lmax().val();
155 }
156
158 {
159 CXZ_ASSERT(f[0]*s[0] == lmax().val(), "got wrong extension: " << f[0]*s[0]
160 << " vs " << lmax().val());
161 CXZ_ASSERT(CNORXZ::formatIsTrivial(f,s), "format is not trivial: f = " << toString(f)
162 << ", s = " << toString(s));
163 return *this;
164 }
165
167 {
168 return true;
169 }
170
171 /*============================================================+
172 | Implementations of member functions of CRangeFactory |
173 +============================================================*/
174
176 mSize(size) {}
177
179 mSize(size), mRef(ref) {}
180
182 {
183 if(mRef != nullptr) {
184 mProd = this->fromCreated(typeid(CRange), {mRef->id()});
185 }
186 if(mProd == nullptr){
187 RangePtr key = mProd = std::shared_ptr<CRange>
188 ( new CRange( mSize ) );
189 if(mRef != nullptr) { key = mRef; }
190 this->addToCreated(typeid(CRange), { key->id() }, mProd);
191 }
192 }
193
194 /*=====================================================+
195 | Implementations of member functions of CRange |
196 +=====================================================*/
197
198 CRange::CRange(SizeT size) : mSize(size) {}
199
201 {
202 return pos;
203 }
204
206 {
207 return metaPos;
208 }
209
211 {
212 return mSize;
213 }
214
216 {
217 return 1;
218 }
219
220 std::string CRange::stringMeta(SizeT pos) const
221 {
222 return toString(pos);
223 }
224
225 const TypeInfo& CRange::type() const
226 {
227 return typeid(CRange);
228 }
229
231 {
232 return typeid(SizeT);
233 }
234
236 {
237 auto rx = rangeCast<CRange>(r);
238 return CRangeFactory( this->size() + rx->size() ).create();
239 }
240
242 {
243 return Vector<Uuid> { this->id() };
244 }
245
246 /*======================================+
247 | Implementations of range casts |
248 +======================================*/
249
251 {
252 return std::dynamic_pointer_cast<CRange>( CRangeFactory(r->size(), r).create() );
253 }
254}
255
#define CXZ_ASSERT(statement, errmsg)
Definition assert.h:40
CIndex & operator=(SizeT lexpos)
Definition crange.cc:26
COpRoot< SizeT, CIndex > xpr(const Sptr< CIndex > &_this) const
Definition crange.cc:122
CIndex & operator+=(Int n)
Definition crange.cc:59
CIndex & reformat(const Vector< SizeT > &f, const Vector< SizeT > &s)
Definition crange.cc:157
CIndex & operator++()
Definition crange.cc:32
SizeT meta() const
Definition crange.cc:111
CIndex & operator-=(Int n)
Definition crange.cc:65
SizeT deepMax() const
Definition crange.cc:152
SizeT lex() const
Definition crange.cc:71
SizeT dim() const
Definition crange.cc:96
CIndex operator-(Int n) const
Definition crange.cc:49
IndexId< 0 > id() const
Definition crange.cc:86
RangePtr prange(const CIndex &last) const
Definition crange.cc:135
CIndex operator+(Int n) const
Definition crange.cc:44
bool formatIsTrivial() const
Definition crange.cc:166
CIndex & operator--()
Definition crange.cc:38
Sptr< RangeType > range() const
Definition crange.cc:101
String stringMeta() const
Definition crange.cc:106
UPos pmax() const
Definition crange.cc:81
CIndex & at(const SizeT &metaPos)
Definition crange.cc:116
CIndex(const RangePtr &range, SizeT pos=0)
Definition crange.cc:22
SizeT operator*() const
Definition crange.cc:91
UPos lmax() const
Definition crange.cc:76
SizeT deepFormat() const
Definition crange.cc:147
CRangeFactory(SizeT size)
Definition crange.cc:175
virtual void make() override
Definition crange.cc:181
SizeT get(SizeT pos) const
Definition crange.cc:200
SizeT mSize
Definition crange.h:207
CRange()=default
virtual const TypeInfo & type() const override final
Definition crange.cc:225
virtual RangePtr extend(const RangePtr &r) const override final
Definition crange.cc:235
virtual Vector< Uuid > key() const override final
Definition crange.cc:241
virtual const TypeInfo & metaType() const override final
Definition crange.cc:230
virtual String stringMeta(SizeT pos) const override final
Definition crange.cc:220
virtual SizeT dim() const override final
Definition crange.cc:215
virtual SizeT size() const override final
Definition crange.cc:210
friend CRangeFactory
Definition crange.h:174
SizeT getMeta(SizeT metaPos) const
Definition crange.cc:205
Uuid id() const
Definition range_base.cc:88
RangePtr fromCreated(const TypeInfo &info, const Vector< Uuid > &rids) const
Definition range_base.cc:33
void addToCreated(const TypeInfo &info, const Vector< Uuid > &rids, const RangePtr &r)
Definition range_base.cc:44
constexpr const SizeT & val() const
std::string String
Definition types.h:42
std::type_info TypeInfo
Definition types.h:71
uint64_t SizeT
Definition types.h:38
constexpr decltype(auto) coproot(const CArrayBase< T > &a, const Sptr< IndexT > &ind)
Sptr< RangeBase > RangePtr
Definition types.h:157
std::vector< T, Allocator< T > > Vector
Definition types.h:310
int32_t Int
Definition types.h:36
Sptr< Range > rangeCast(const RangePtr r)
bool formatIsTrivial(const Vector< SizeT > &f, const Vector< SizeT > &s)
String toString(const T &a)
RangePtr prange(const Sptr< RangeT > &range, const Vector< SizeT > &parts)
Definition prange.cc.h:401
std::shared_ptr< T > Sptr
Definition types.h:48
Operation main header.
PRange, PRangeFactory and PIndex declaration.
Ranges main header.
static Sptr< Range > func(const RangePtr &r)