61 {
for (
tsize m=0; m<s; ++m) d[m]=val; }
64 template<
typename T2> T &
operator[] (T2 n) {
return d[n];}
66 template<
typename T2>
const T &
operator[] (T2 n)
const {
return d[n];}
73 T *
end() {
return d+s; }
76 const T *
begin()
const {
return d; }
79 const T *
end()
const {
return d+s; }
83 {
for (
tsize m=0; m<s; ++m) ptr[m]=d[m]; }
87 { std::sort (d,d+s); }
91 template<
typename Comp>
void sort(Comp comp)
92 { std::sort (d,d+s,comp); }
114 tsize &idx,
double &frac)
const 121 planck_assert(s>0,
"trying to find min and max of a zero-sized array");
123 for (
tsize m=1; m<s; ++m)
125 if (d[m]<minv) minv=d[m];
126 else if (d[m]>maxv) maxv=d[m];
133 for (
tsize m=0; m<s; ++m)
134 if (d[m]==val)
return true;
142 for (
tsize m=0; m<s; ++m)
143 if (d[m]==val)
return m;
151 if (s!=other.s)
return false;
152 for (
tsize i=0; i<s; ++i)
153 if (d[i]!=other.d[i])
return false;
172 template<
typename T2>
const T &
operator[] (T2 n)
const {
return d[n];}
183 { this->d=0; this->s=0; own=
true; }
193 { this->
fill(inival); }
209 {
for (
tsize m=0; m<this->s; ++m) this->d[m] = orig.d[m]; }
211 ~arrT() {
if (own) stm::dealloc(this->d); }
218 if (sz==this->s)
return;
219 if (own) stm::dealloc(this->d);
221 this->d = stm::alloc(sz);
231 void dealloc() {
if (own) stm::dealloc(this->d); reset();}
239 if (sz==this->s)
return;
240 T *tmp = stm::alloc(sz);
241 for (
tsize m=0; m<min(sz,this->s); ++m)
243 if (own) stm::dealloc(this->d);
252 if (
this==&orig)
return *
this;
254 for (
tsize m=0; m<this->s; ++m) this->d[m] = orig.d[m];
259 template<
typename T2>
void copyFrom (
const std::vector<T2> &orig)
262 for (
tsize m=0; m<this->s; ++m) this->d[m] = orig[m];
265 template<
typename T2>
void copyTo (std::vector<T2> &vec)
const 267 vec.clear(); vec.reserve(this->s);
268 for (
tsize m=0; m<this->s; ++m) vec.push_back(this->d[m]);
276 for (
tsize m=0; m<this->s; ++m) this->d[m]=ptr[m];
283 if (own) stm::dealloc(this->d);
292 std::swap(this->d,other.d);
293 std::swap(this->s,other.s);
294 std::swap(own,other.own);
299 template <
typename T>
309 arr(
tsize sz,
const T &inival) :
arrT<T,normalAlloc__<T> >(sz,inival) {}
328 template <
typename T,
int align>
339 :
arrT<T,alignAlloc__<T,align> >(sz,inival) {}
347 template <
typename T,
typename storageManager>
class arr2T 358 : s1(sz1), s2(sz2), d(s1*s2) {}
364 : s1(sz1), s2(sz2), d(p, s1*s2) {}
366 : s1(sz1), s2(sz2), d (s1*s2)
370 : s1(orig.s1), s2(orig.s2), d(orig.d) {}
387 if (sz1*sz2 != d.
size())
403 if (sz1*sz2<=d.
size())
413 {
for (
tsize m=0; m<s1*s2; ++m) d[m]=val; }
417 {
for (
tsize m=0; m<s1*s2; ++m) d[m]*=val; }
422 if (
this==&orig)
return *
this;
423 alloc (orig.s1, orig.s2);
429 template<
typename T2> T *
operator[] (T2 n) {
return &d[n*s2];}
431 template<
typename T2>
const T *
operator[] (T2 n)
const {
return &d[n*s2];}
434 template<
typename T2,
typename T3> T &operator() (T2 n1, T3 n2)
435 {
return d[n1*s2 + n2];}
438 template<
typename T2,
typename T3>
const T &operator() (T2 n1, T3 n2)
const 439 {
return d[n1*s2 + n2];}
446 "trying to find min and max of a zero-sized array");
448 for (
tsize m=1; m<s1*s2; ++m)
450 if (d[m]<minv) minv=d[m];
451 if (d[m]>maxv) maxv=d[m];
459 std::swap(s1,other.s1);
460 std::swap(s2,other.s2);
465 template<
typename T2,
typename T3>
bool conformable
467 {
return (other.
size1()==s1) && (other.
size2()==s2); }
473 template <
typename T>
487 :
arr2T<T,normalAlloc__<T> > (sz1,sz2,inival) {}
494 template <
typename T,
int align>
502 :
arr2T<T,alignAlloc__<T,align> > (sz1,sz2) {}
506 :
arr2T<T,alignAlloc__<T,align> > (sz1,sz2,inival) {}
519 {
for (
tsize m=0; m<s1; ++m) d1[m] = &d[m*s2]; }
523 arr2b() : s1(0), s2(0), d(0), d1(0) {}
526 : s1(sz1), s2(sz2), d(s1*s2), d1(s1)
530 : s1(orig.s1), s2(orig.s2), d(orig.d), d1(s1)
546 if ((s1==sz1) && (s2==sz2))
return;
562 if (
this==&orig)
return *
this;
563 alloc (orig.s1, orig.s2);
564 for (
tsize m=0; m<s1*s2; ++m) d[m] = orig.d[m];
571 template<
typename T2>
const T *
operator[] (T2 n)
const {
return d1[n];}
574 T **
p0() {
return &d1[0];}
581 template <
typename T>
class arr3 584 tsize s1, s2, s3, s2s3;
589 arr3() : s1(0), s2(0), s3(0), s2s3(0), d(0) {}
592 : s1(sz1), s2(sz2), s3(sz3), s2s3(s2*s3), d(s1*s2*s3) {}
595 : s1(orig.s1), s2(orig.s2), s3(orig.s3), s2s3(orig.s2s3), d(orig.d) {}
612 d.
alloc(sz1*sz2*sz3);
613 s1=sz1; s2=sz2; s3=sz3; s2s3=s2*s3;
625 if (
this==&orig)
return *
this;
626 alloc (orig.s1, orig.s2, orig.s3);
633 template<
typename T2,
typename T3,
typename T4> T &operator()
634 (T2 n1, T3 n2, T4 n3)
635 {
return d[n1*s2s3 + n2*s3 + n3];}
638 template<
typename T2,
typename T3,
typename T4>
const T &operator()
639 (T2 n1, T3 n2, T4 n3)
const 640 {
return d[n1*s2s3 + n2*s3 + n3];}
646 std::swap(s1,other.s1);
647 std::swap(s2,other.s2);
648 std::swap(s3,other.s3);
649 std::swap(s2s3,other.s2s3);
655 {
return (other.
size1()==s1)&&(other.
size2()==s2)&&(other.
size3()==s3); }
void alloc(tsize sz1, tsize sz2)
arr(tsize sz, const T &inival)
void copyTo(std::vector< T2 > &vec) const
arr2T(tsize sz1, tsize sz2)
arr2(T *p, tsize sz1, tsize sz2)
arr2(tsize sz1, tsize sz2)
arrT(tsize sz, const T &inival)
arrT & operator=(const arrT &orig)
void alloc(tsize sz1, tsize sz2, tsize sz3)
arr2_align(tsize sz1, tsize sz2)
tsize find(const T &val) const
void transfer(arrT &other)
void minmax(T &minv, T &maxv) const
arr2b(tsize sz1, tsize sz2)
bool contains(const T &val) const
bool contentsEqual(const arr_ref &other) const
void allocAndFill(tsize sz, const T &inival)
arr2T(T *p, tsize sz1, tsize sz2)
void minmax(T &minv, T &maxv) const
void copyFromPtr(const T2 *ptr, tsize sz)
arr2_align(tsize sz1, tsize sz2, const T &inival)
arr2(tsize sz1, tsize sz2, const T &inival)
#define planck_assert(testval, msg)
void interpol_helper(const T &val, tsize &idx, double &frac) const
bool conformable(const arr3< T2 > &other) const
void copyFrom(const std::vector< T2 > &orig)
arr3(tsize sz1, tsize sz2, tsize sz3)
void alloc(tsize sz1, tsize sz2)
void fast_alloc(tsize sz1, tsize sz2)
void interpol_helper(const T &val, Comp comp, tsize &idx, double &frac) const
void allocAndFill(tsize sz1, tsize sz2, const T &inival)
arr_align(tsize sz, const T &inival)
void copyToPtr(T *ptr) const