Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Heed::DynLinArr< T > Class Template Reference

#include <AbsArr.h>

+ Inheritance diagram for Heed::DynLinArr< T >:

Public Member Functions

 DynLinArr (void)
 
 DynLinArr (long fqel)
 
 DynLinArr (long fqel, const T &val)
 
 DynLinArr (long fqel, const T *ar, ArgInterp_Arr)
 
DynLinArr< T > & operator= (const DynLinArr< T > &f)
 
template<class D >
DynLinArr< T > & operator= (const DynLinArr< D > &f)
 
void pass (long fqel, T *fel)
 
 DynLinArr (const DynLinArr< T > &f)
 
 DynLinArr (const DynLinArr< T > &f, Pilfer)
 
 DynLinArr (const DynArr< T > &f)
 
 DynLinArr (const DynArr< T > &f, int n_of_dim, long roc_number)
 
DynLinArrassignAll (const T &f)
 
template<class X >
DynLinArr< T > & assignAll1 (const X &f)
 
T & operator[] (long n)
 
const T & operator[] (long n) const
 
T & acu (long n)
 
const T & acu (long n) const
 
T & last_el (void)
 
const T & last_el (void) const
 
long get_qel (void) const
 
void put_qel (long fqel)
 
void put_qel (long fqel, const T *val, ArgInterp_SingleAdr t)
 
void put_qel (long fqel, const T &val)
 
void increment (const T *val=NULL)
 
void increment (const T &val)
 
void clear (void)
 
void pilfer (const DynLinArr< T > &f)
 
void check (void) const
 
DynArr< T > top (void)
 
void sort (long q_to_sort=0)
 
void sort (DynLinArr< long > &sort_ind, long q_to_sort=0) const
 
void sort_select_increasing (DynLinArr< long > &sort_ind, long q_to_sort=0) const
 
void sort_select_decreasing (DynLinArr< long > &sort_ind, long q_to_sort=0) const
 
virtual DynLinArrcopy () const
 
virtual ~DynLinArr ()
 
- Public Member Functions inherited from Heed::RegPassivePtr
 RegPassivePtr (void)
 
 RegPassivePtr (char fs_ban_del, char fs_ban_sub, char fs_ban_cop=0)
 
 RegPassivePtr (const RegPassivePtr &f)
 
RegPassivePtroperator= (const RegPassivePtr &f)
 
CountPP_ns::CountPassivePtrbook (void) const
 
void clear_pointers (void) const
 
virtual RegPassivePtrcopy () const
 
virtual ~RegPassivePtr ()
 
virtual void print (std::ostream &file, int l=1) const
 
void set_s_ban_del (char fs_ban_del)
 
char get_s_ban_del (void) const
 
void set_s_ban_sub (char fs_ban_sub)
 
char get_s_ban_sub (void) const
 
void set_s_ban_cop (char fs_ban_cop)
 
char get_s_ban_cop (void) const
 
void set_s_allow_del_at_zero_count (char fs_allow_del_at_zero_count)
 
char get_s_allow_del_at_zero_count (void) const
 
long get_total_number_of_references (void) const
 

Friends

template<class P >
void apply1 (DynLinArr< P > &ar, void(*fun)(P &f))
 
template<class P , class X >
void apply2 (DynLinArr< P > &ar, void(*fun1)(P &f, void(*fun21)(X &f)), void(*fun2)(X &f))
 

Additional Inherited Members

- Static Public Member Functions inherited from Heed::RegPassivePtr
static void set_s_ban_del_ignore (char fs_ban_del_ignore)
 
static char get_s_ban_del_ignore (void)
 
static void set_s_print_adr_cpp (char fs_print_adr_cpp)
 
static char get_s_print_adr_cpp (void)
 

Detailed Description

template<class T>
class Heed::DynLinArr< T >

Definition at line 102 of file AbsArr.h.

Constructor & Destructor Documentation

◆ DynLinArr() [1/8]

template<class T >
Heed::DynLinArr< T >::DynLinArr ( void  )
inline

Definition at line 105 of file AbsArr.h.

105: qel(0), el(NULL) { ; }

◆ DynLinArr() [2/8]

template<class T >
Heed::DynLinArr< T >::DynLinArr ( long  fqel)
inlineexplicit

Definition at line 106 of file AbsArr.h.

106 : qel(fqel), el(NULL) {
107 if (qel > max_qel_DynLinArr) {
108 mcerr << "ERROR in DynLinArr(long fqel):\n";
109 mcerr << "qel > max_qel_DynLinArr:\n";
111 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
112 << '\n';
113 spexit(mcerr);
114 }
115 if (qel < 0) {
116 mcerr << "ERROR in DynLinArr(long fqel):\n";
117 mcerr << "qel < 0:\n";
118 Iprintn(mcout, qel);
119 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
120 << '\n';
121 spexit(mcerr);
122 }
123 el = (fqel > 0) ? (new T[fqel]) : (T*)NULL;
124 }
#define spexit(stream)
Definition: FunNameStack.h:256
long max_qel_DynLinArr
Definition: AbsArr.cpp:17
#define mcout
Definition: prstream.h:126
#define mcerr
Definition: prstream.h:128
#define Iprintn(file, name)
Definition: prstream.h:204
#define Iprint2n(file, name1, name2)
Definition: prstream.h:219

◆ DynLinArr() [3/8]

template<class T >
Heed::DynLinArr< T >::DynLinArr ( long  fqel,
const T &  val 
)
inline

Definition at line 126 of file AbsArr.h.

126 : qel(fqel), el(NULL) {
127 if (qel > max_qel_DynLinArr) {
128 mcerr << "ERROR in DynLinArr(long fqel, const T& val):\n";
129 mcerr << "qel > max_qel_DynLinArr:\n";
131 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
132 << '\n';
133 spexit(mcerr);
134 }
135 if (qel < 0) {
136 mcerr << "ERROR in DynLinArr(long fqel, const T& val):\n";
137 mcerr << "qel < 0:\n";
138 Iprintn(mcout, qel);
139 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
140 << '\n';
141 spexit(mcerr);
142 }
143 el = (fqel > 0) ? (new T[fqel]) : (T*)NULL;
144 assignAll(val);
145 }
DynLinArr & assignAll(const T &f)
Definition: AbsArr.h:207

◆ DynLinArr() [4/8]

template<class T >
Heed::DynLinArr< T >::DynLinArr ( long  fqel,
const T *  ar,
ArgInterp_Arr   
)
inline

Definition at line 146 of file AbsArr.h.

146 : qel(fqel), el(NULL) {
147 if (qel > max_qel_DynLinArr) {
148 mcerr << "ERROR in DynLinArr(long fqel, const T* ar, ArgInterp_Arr):\n";
149 mcerr << "qel > max_qel_DynLinArr:\n";
151 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
152 << '\n';
153 spexit(mcerr);
154 }
155 if (qel < 0) {
156 mcerr << "ERROR in DynLinArr(long fqel, const T* ar, ArgInterp_Arr):\n";
157 mcerr << "qel < 0:\n";
158 Iprintn(mcout, qel);
159 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
160 << '\n';
161 spexit(mcerr);
162 }
163 el = (fqel > 0) ? (new T[fqel]) : (T*)NULL;
164 for (long n = 0; n < qel; n++) el[n] = ar[n];
165 }

◆ DynLinArr() [5/8]

template<class T >
Heed::DynLinArr< T >::DynLinArr ( const DynLinArr< T > &  f)
inline

Definition at line 516 of file AbsArr.h.

517 : RegPassivePtr(),
518 qel(0),
519 el(NULL) {
520#ifdef DEBUG_DYNLINARR
521 mcout << "DynLinArr(const DynLinArr<T>& f) is working\n";
522#endif
523 *this = f;
524}
RegPassivePtr(void)
Definition: AbsPtr.h:346

◆ DynLinArr() [6/8]

template<class T >
Heed::DynLinArr< T >::DynLinArr ( const DynLinArr< T > &  f,
Pilfer   
)
inline

Definition at line 192 of file AbsArr.h.

192 : qel(f.qel), el(f.el) {
193#ifdef DEBUG_DYNLINARR
194 mcout << "DynLinArr( DynLinArr<T>& f, Pilfer) is working\n";
195#endif
196 f.qel = 0;
197 f.el = 0;
198 }

◆ DynLinArr() [7/8]

template<class T >
Heed::DynLinArr< T >::DynLinArr ( const DynArr< T > &  f)

Definition at line 2537 of file AbsArr.h.

2537 {
2538 // mcout<<"template<class T> DynLinArr<T>::DynLinArr(const DynArr<T>& f):\n";
2539 f.check();
2540 long qdim = f.get_qdim();
2541 if (qdim != 1) {
2542 mcerr << "ERROR in DynLinArr<T>::DynLinArr(const DynArr<T>& f):\n"
2543 << "f.get_qdim() != 1, f.get_qdim()=" << f.get_qdim() << '\n';
2544 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2545 << '\n';
2546 spexit(mcerr);
2547 }
2548 const DynLinArr<long>& qelem = f.get_qel();
2549 qel = qelem[0];
2550 // mcout<<"qel="<<qel<<'\n';
2551 if (qel > 0) {
2552 el = new T[qel];
2553 for (long n = 0; n < qel; n++) el[n] = f.ac(n);
2554 } else
2555 el = NULL;
2556}

◆ DynLinArr() [8/8]

template<class T >
Heed::DynLinArr< T >::DynLinArr ( const DynArr< T > &  f,
int  n_of_dim,
long  roc_number 
)

Definition at line 2559 of file AbsArr.h.

2563{
2564 f.check();
2565 long qdim = f.get_qdim();
2566 if (qdim != 2) {
2567 mcerr << "ERROR in DynLinArr<T>::DynLinArr(const DynArr<T>& f, int "
2568 "n_of_dim,long roc_number):\n"
2569 << "f.get_qdim() != 2, f.get_qdim()=" << f.get_qdim() << '\n';
2570 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2571 << '\n';
2572 spexit(mcerr);
2573 }
2574 const DynLinArr<long>& qelem = f.get_qel();
2575 if (n_of_dim == 0) {
2576 qel = qelem[1];
2577 } else {
2578 qel = qelem[0];
2579 }
2580 // mcout<<"qel="<<qel<<'\n';
2581 if (qel > 0) {
2582 el = new T[qel];
2583 long n;
2584 if (n_of_dim == 0) {
2585 for (n = 0; n < qel; n++) el[n] = f.ac(roc_number, n);
2586 } else {
2587 for (n = 0; n < qel; n++) el[n] = f.ac(n, roc_number);
2588 }
2589 }
2590}

◆ ~DynLinArr()

template<class T >
virtual Heed::DynLinArr< T >::~DynLinArr ( )
inlinevirtual

Definition at line 406 of file AbsArr.h.

406 {
407 check();
408 if (el) delete[] el;
409 }
void check(void) const
Definition: AbsArr.h:433

Member Function Documentation

◆ acu() [1/2]

◆ acu() [2/2]

template<class T >
const T & Heed::DynLinArr< T >::acu ( long  n) const
inline

Definition at line 251 of file AbsArr.h.

251 {
252 // unchecked access
253 return el[n];
254 }

◆ assignAll()

template<class T >
DynLinArr & Heed::DynLinArr< T >::assignAll ( const T &  f)
inline

Definition at line 207 of file AbsArr.h.

207 {
208 check();
209 for (long n = 0; n < qel; n++) el[n] = f;
210 return *this;
211 }

Referenced by Heed::DynArr< T >::assignAll(), Heed::DynLinArr< T >::assignAll1(), and Heed::DynLinArr< T >::DynLinArr().

◆ assignAll1()

template<class T >
template<class X >
DynLinArr< T > & Heed::DynLinArr< T >::assignAll1 ( const X &  f)
inline

Definition at line 213 of file AbsArr.h.

213 {
214 // assumes that element is object
215 // which also accepts assignAll, which is called for it.
216 check();
217 for (long n = 0; n < qel; n++) el[n].assignAll(f);
218 return *this;
219 }

◆ check()

template<class T >
void Heed::DynLinArr< T >::check ( void  ) const

Definition at line 433 of file AbsArr.h.

433 {
434 if (qel < 0) {
435 mcerr << "ERROR in template<class T> void DynLinArr<T>::check(void):\n";
436 mcerr << "qel < 0, qel=" << qel << '\n';
437 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
438 << '\n';
439 spexit(mcerr);
440 }
441 if (qel == 0 && el != NULL) {
442 mcerr << "ERROR in template<class T> void DynLinArr<T>::check(void):\n";
443 mcerr << "qel == 0 && el != NULL: el=" << el << '\n';
444 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
445 << '\n';
446 spexit(mcerr);
447 }
448 if (qel > 0) {
449 if (el == NULL) {
450 mcerr << "ERROR in template<class T> void DynLinArr<T>::check(void):\n";
451 mcerr << "qel > 0 && el == NULL: qel=" << qel << '\n';
452 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
453 << '\n';
454 spexit(mcerr);
455 }
456 if (qel > max_qel_DynLinArr) {
457 mcerr << "ERROR in template<class T> void DynLinArr<T>::check(void):\n";
458 mcerr << "qel > max_qel_DynLinArr: \n";
460 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
461 << '\n';
462 spexit(mcerr);
463 }
464 }
465}

Referenced by Heed::DynLinArr< T >::assignAll(), Heed::DynLinArr< T >::assignAll1(), Heed::DynArr< T >::check(), Heed::DynLinArr< T >::increment(), Heed::operator<<(), Heed::DynLinArr< T >::operator=(), Heed::print_adr_DynLinArr(), Heed::print_DynArr_double(), Heed::print_DynArr_float(), Heed::print_DynArr_int_w(), Heed::print_DynLinArr(), Heed::print_DynLinArr_double(), Heed::print_DynLinArr_double2(), Heed::print_DynLinArr_float(), Heed::print_DynLinArr_int(), Heed::print_DynLinArr_int_double(), Heed::print_DynLinArr_int_double3(), Heed::print_DynLinArr_long(), and Heed::DynLinArr< T >::~DynLinArr().

◆ clear()

template<class T >
void Heed::DynLinArr< T >::clear ( void  )
inline

◆ copy()

template<class T >
DynLinArr< T > * Heed::DynLinArr< T >::copy
virtual

Reimplemented from Heed::RegPassivePtr.

Definition at line 417 of file AbsArr.h.

417 {
418 return new DynLinArr<T>(*this);
419}

◆ get_qel()

template<class T >
long Heed::DynLinArr< T >::get_qel ( void  ) const
inline

◆ increment() [1/2]

template<class T >
void Heed::DynLinArr< T >::increment ( const T &  val)
inline

Definition at line 308 of file AbsArr.h.

308 {
309 check();
310 long q = qel + 1;
311 put_qel(q, val);
312 }

◆ increment() [2/2]

template<class T >
void Heed::DynLinArr< T >::increment ( const T *  val = NULL)
inline

Definition at line 303 of file AbsArr.h.

303 {
304 check();
305 long q = qel + 1;
306 put_qel(q, *val);
307 }

◆ last_el() [1/2]

template<class T >
T & Heed::DynLinArr< T >::last_el ( void  )
inline

Definition at line 255 of file AbsArr.h.

255 {
256#ifdef ALR_CHECK_BOUND
257 if (qel > 0) return el[qel - 1];
258 mcerr << "ERROR in const T& DynLinArr::last_el(void) const: qel <=0:"
259 << " qel" << qel << '\n';
260 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
261 << '\n';
262 spexit(mcerr);
263 return el[0];
264#else
265 return el[qel];
266#endif
267 }

◆ last_el() [2/2]

template<class T >
const T & Heed::DynLinArr< T >::last_el ( void  ) const
inline

Definition at line 269 of file AbsArr.h.

269 {
270#ifdef ALR_CHECK_BOUND
271 if (qel > 0) return el[qel - 1];
272 mcerr << "ERROR in const T& DynLinArr::last_el(void) const: qel <=0:"
273 << " qel" << qel << '\n';
274 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
275 << '\n';
276 spexit(mcerr);
277 return el[0];
278#else
279 return el[qel];
280#endif
281 }

◆ operator=() [1/2]

template<class T >
template<class D >
DynLinArr< T > & Heed::DynLinArr< T >::operator= ( const DynLinArr< D > &  f)

Definition at line 494 of file AbsArr.h.

494 {
495#ifdef DEBUG_DYNLINARR
496 mcout << "DynLinArr<T>& DynLinArr<T>::operator=(const DynLinArr<D>& f) is "
497 "working\n";
498#endif
499 if (this == &f) return *this;
500 check();
501 f.check();
502 // First of all we allocate memory and copy to there
503 // all elements from f, because f can be part of this array,
504 // for example, one of its elements.
505 long q = f.get_qel();
506 T* temp_el = (T*)NULL;
507 if (q > 0) {
508 temp_el = new T[q];
509 for (long n = 0; n < q; n++) temp_el[n] = f[n];
510 }
511 pass(q, temp_el);
512 return *this;
513}
long get_qel(void) const
Definition: AbsArr.h:283
void pass(long fqel, T *fel)
Definition: AbsArr.h:183

◆ operator=() [2/2]

template<class T >
DynLinArr< T > & Heed::DynLinArr< T >::operator= ( const DynLinArr< T > &  f)

Definition at line 468 of file AbsArr.h.

468 {
469#ifdef DEBUG_DYNLINARR
470 mcout << "DynLinArr<T>& DynLinArr<T>::operator=(const DynLinArr<T>& f) is "
471 "working\n";
472#endif
473 if (this != &f) {
474 // mcout<<"DynLinArr<T>& operator=(const DynLinArr<T>& f): long(el)="
475 //<<long(el)<<'\n';
476 check();
477 f.check();
478 // First of all we allocate memory and copy to there
479 // all elements from f, because f can be part of this array,
480 // for example, one of its elements.
481 long q = f.get_qel();
482 T* temp_el = (T*)NULL;
483 if (q > 0) {
484 temp_el = new T[q];
485 for (long n = 0; n < q; n++) temp_el[n] = f.el[n];
486 }
487 pass(q, temp_el);
488 }
489 return *this;
490}

◆ operator[]() [1/2]

template<class T >
T & Heed::DynLinArr< T >::operator[] ( long  n)
inline

Definition at line 221 of file AbsArr.h.

221 {
222#ifdef ALR_CHECK_BOUND
223 if (n >= 0 && n < qel) return el[n];
224 mcerr << "ERROR in const T& DynLinArr::operator[](long n) const: "
225 << "n is out of bounds, n=" << n << " qel=" << qel << '\n';
226 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
227 << '\n';
228 spexit(mcerr);
229 return el[0];
230#else
231 return el[n];
232#endif
233 }

◆ operator[]() [2/2]

template<class T >
const T & Heed::DynLinArr< T >::operator[] ( long  n) const
inline

Definition at line 234 of file AbsArr.h.

234 {
235#ifdef ALR_CHECK_BOUND
236 if (n >= 0 && n < qel) return el[n];
237 mcerr << "ERROR in const T& DynLinArr::operator[](long n) const: "
238 << "n is out of bounds, n=" << n << " qel=" << qel << '\n';
239 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
240 << '\n';
241 spexit(mcerr);
242 return el[0];
243#else
244 return el[n];
245#endif
246 }

◆ pass()

template<class T >
void Heed::DynLinArr< T >::pass ( long  fqel,
T *  fel 
)
inline

Definition at line 183 of file AbsArr.h.

183 {
184 // Do not call directly! Is to be used only
185 // from assignment operator above
186 clear();
187 qel = fqel;
188 el = fel;
189 }
void clear(void)
Definition: AbsArr.h:313

◆ pilfer()

template<class T >
void Heed::DynLinArr< T >::pilfer ( const DynLinArr< T > &  f)
inline

Definition at line 315 of file AbsArr.h.

315 {
316#ifdef DEBUG_DYNLINARR
317 mcout << "DynLinArr::pilfer is called\n";
318#endif
319 if (this != &f) {
320 if (qel != 0) {
321 if (f.qel != 0) {
322 mcerr << "ERROR in DynLinArr::pilfer(...):\n";
323 mcerr << "Both the destination and source arrays are not empty\n";
324 // For explanations why it is dengerous, see similar function
325 // of ActivePtr.
326 spexit(mcerr);
327 } else {
328 delete[] el;
329 qel = 0;
330 }
331 }
332 el = f.el;
333 qel = f.qel;
334 f.el = NULL;
335 f.qel = 0;
336 }
337 }

Referenced by Heed::DynArr< T >::pilfer(), Heed::DynLinArr< T >::sort(), Heed::DynLinArr< T >::sort_select_decreasing(), and Heed::DynLinArr< T >::sort_select_increasing().

◆ put_qel() [1/3]

template<class T >
void Heed::DynLinArr< T >::put_qel ( long  fqel)

Definition at line 527 of file AbsArr.h.

527 {
528 //
529 // creates array with size fqel
530 // If old array existed, then
531 // If it was less than fqel, it all is copied to new array
532 // and the other elements either assigned *val or
533 // remains not inited.
534 // else its fqel part is copyed to new array.
535 // mcout<<"put_qel: *this="<<(*this);
536 if (fqel < 0) {
537 mcerr << "ERROR in template<class T> void DynLinArr<T>::put_qel(long "
538 "fqel):\n";
539 mcerr << "fqel < 0, fqel=" << fqel << '\n';
540 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
541 << '\n';
542 spexit(mcerr);
543 }
544 check();
545 if (el == NULL) {
546 qel = fqel;
547 if (qel > 0) el = new T[fqel];
548 } else {
549 if (qel != fqel) {
550 if (fqel <= 0) {
551 qel = 0;
552 delete[] el;
553 el = NULL;
554 } else {
555 T* elh;
556 elh = new T[fqel];
557 for (long n = 0; n < fqel; ++n) {
558 if (n < qel) elh[n] = el[n];
559 }
560 delete[] el;
561 el = elh;
562 qel = fqel;
563 }
564 }
565 }
566}

Referenced by Heed::append(), Heed::DynLinArr< T >::clear(), Heed::DynArr< T >::DynArr(), Heed::DynLinArr< T >::increment(), Heed::operator>>(), Heed::DynLinArr< T >::put_qel(), Heed::DynLinArr< T >::sort_select_decreasing(), and Heed::DynLinArr< T >::sort_select_increasing().

◆ put_qel() [2/3]

template<class T >
void Heed::DynLinArr< T >::put_qel ( long  fqel,
const T &  val 
)
inline

Definition at line 300 of file AbsArr.h.

300 {
301 put_qel(fqel, &val, ArgInterp_SingleAdr());
302 }

◆ put_qel() [3/3]

template<class T >
void Heed::DynLinArr< T >::put_qel ( long  fqel,
const T *  val,
ArgInterp_SingleAdr  t 
)

Definition at line 569 of file AbsArr.h.

569 {
570 // By default val == NULL
571 // creates array with size fqel
572 // If old array existed, then
573 // If it was less than fqel, it all is copied to new array
574 // and the other elements either assigned *val or
575 // remains not inited.
576 // else its fqel part is copyed to new array.
577 // mcout<<"put_qel: *this="<<(*this);
578 if (fqel < 0) {
579 mcerr << "ERROR in template<class T> void DynLinArr<T>::put_qel(long fqel, "
580 "const T* val, ArgInterp_SingleAdr):\n";
581 mcerr << "fqel < 0, fqel=" << fqel << '\n';
582 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
583 << '\n';
584 spexit(mcerr);
585 // Avoid compiler warning because of unused variable t (HS).
586 mcerr << sizeof(t) << "\n";
587 }
588 check();
589 if (el == NULL) {
590 qel = fqel;
591 if (qel > 0) el = new T[fqel];
592 if (val != NULL)
593 for (long n = 0; n < qel; ++n) el[n] = *val;
594 } else {
595 if (qel != fqel) {
596 if (fqel <= 0) {
597 qel = 0;
598 delete[] el;
599 el = NULL;
600 } else {
601 T* elh;
602 elh = new T[fqel];
603 for (long n = 0; n < fqel; ++n) {
604 if (n < qel)
605 elh[n] = el[n];
606 else if (val != NULL)
607 elh[n] = *val;
608 }
609 delete[] el;
610 el = elh;
611 qel = fqel;
612 }
613 }
614 }
615}

◆ sort() [1/2]

template<class T >
void Heed::DynLinArr< T >::sort ( DynLinArr< long > &  sort_ind,
long  q_to_sort = 0 
) const

Definition at line 686 of file AbsArr.h.

686 {
687 mfunnamep(
688 "void DynLinArr<T>::sort(DynLinArr< long >& sort_ind, long "
689 "q_to_sort = 0) const");
690
691 check_econd12(q_to_sort, >, qel, mcerr);
692 if (q_to_sort <= 0) q_to_sort = qel;
693 // if(q_to_sort <= 1) return;
694
695 sort_ind.clear();
696 sort_ind.pilfer(DynLinArr<long>(q_to_sort));
697 long n, m;
698 for (n = 0; n < q_to_sort; n++) {
699 sort_ind.acu(n) = n;
700 }
701 if (q_to_sort <= 1) return;
702
703 long n_possible_next = 1;
704
705 for (n = 0; n < q_to_sort - 1; n++) {
706 // first it finds the minimum along the rest and replaces if it is less
707 long nmin = n_possible_next;
708 long ind_nmin = sort_ind.acu(nmin);
709 int s_change_possible_next = 0;
710
711 // for(m=n+2; m<q_to_sort; m++)
712 for (m = n_possible_next + 1; m < q_to_sort; m++) {
713 if (el[ind_nmin] > el[sort_ind.acu(m)])
714 // if(el[sort_ind.acu(nmin)] > el[sort_ind.acu(m)])
715 {
716 n_possible_next = nmin;
717 s_change_possible_next = 1;
718 nmin = m;
719 ind_nmin = sort_ind.acu(nmin);
720 }
721 }
722 if (s_change_possible_next == 0 || n_possible_next < n + 2) {
723 n_possible_next = n + 2;
724 }
725 if (el[sort_ind.acu(n)] > el[ind_nmin])
726 // if(el[sort_ind.acu(n)] > el[sort_ind.acu(nmin)])
727 {
728 if (s_change_possible_next == 1) {
729 if (n_possible_next < q_to_sort &&
730 el[sort_ind.acu(n)] < el[sort_ind.acu(n_possible_next)]) {
731 n_possible_next = nmin;
732 }
733 }
734 // long t = sort_ind.acu(nmin);
735 sort_ind.acu(nmin) = sort_ind.acu(n);
736 sort_ind.acu(n) = ind_nmin;
737 }
738 }
739}
#define mfunnamep(string)
Definition: FunNameStack.h:49
#define check_econd12(a, sign, b, stream)
Definition: FunNameStack.h:163
T & acu(long n)
Definition: AbsArr.h:247
void pilfer(const DynLinArr< T > &f)
Definition: AbsArr.h:315

◆ sort() [2/2]

template<class T >
void Heed::DynLinArr< T >::sort ( long  q_to_sort = 0)

Definition at line 625 of file AbsArr.h.

625 {
626 mfunnamep("void DynLinArr<T>::sort(long q_to_sort = 0)");
627
628 check_econd12(q_to_sort, >, qel, mcerr);
629 if (q_to_sort <= 0) q_to_sort = qel;
630 if (q_to_sort <= 1) return;
631
632 long n_possible_next = 1;
633 long q_comp = 0;
634 long n, m;
635 for (n = 0; n < q_to_sort - 1; n++) {
636 // Iprint2n(mcout, n, n_possible_next);
637 // first it finds the minimum along the rest and replaces if it is less
638 // long nmin = n+1;
639 long nmin = n_possible_next;
640 T el_min = el[nmin];
641 int s_change_possible_next = 0;
642
643 // for(m=n+2; m<q_to_sort; m++)
644 for (m = n_possible_next + 1; m < q_to_sort; m++) {
645 q_comp++;
646 // if(el[nmin] > el[m])
647 if (el_min > el[m]) {
648 n_possible_next = nmin;
649 s_change_possible_next = 1;
650 nmin = m;
651 el_min = el[nmin];
652 }
653 }
654 // Iprint4n(mcout, n_possible_next, s_change_possible_next, nmin, el_min);
655 if (s_change_possible_next == 0 || n_possible_next < n + 2) {
656 n_possible_next = n + 2;
657 }
658 // if(el[n] > el[nmin])
659 //{
660 // T t = el[nmin];
661 // el[nmin] = el[n];
662 // el[n] = t;
663 //}
664 // Iprintn(mcout, n_possible_next);
665 // Iprint2n(mcout, el[n], el_min);
666 if (el[n] > el_min) {
667 if (s_change_possible_next == 1) {
668 // if(n_possible_next < q_to_sort)
669 if (n_possible_next < q_to_sort && el[n] < el[n_possible_next]) {
670 n_possible_next = nmin;
671 }
672 }
673 // mcout<<"replacing el[n] and el_min\n";
674 T t = el_min;
675 el[nmin] = el[n];
676 el[n] = t;
677 }
678 // Iprintn(mcout, (*this));
679 }
680 // Iprintn(mcout, q_comp);
681}

◆ sort_select_decreasing()

template<class T >
void Heed::DynLinArr< T >::sort_select_decreasing ( DynLinArr< long > &  sort_ind,
long  q_to_sort = 0 
) const

Definition at line 806 of file AbsArr.h.

807 {
808 mfunnamep(
809 "void DynLinArr<T>::sort_select_decreasing(DynLinArr< long >& "
810 "sort_ind, long q_to_sort = 0) const");
811
812 check_econd12(q_to_sort, >, qel, mcerr);
813 long s_last_noninc = 0;
814 if (q_to_sort <= 0) {
815 q_to_sort = qel;
816 s_last_noninc = 1;
817 } else if (q_to_sort == qel) {
818 s_last_noninc = 1;
819 }
820 // Iprintn(mcout, q_to_sort);
821
822 // if(qel <= 1) return;
823 sort_ind.clear();
824 sort_ind.pilfer(DynLinArr<long>(qel));
825 long n, m;
826 for (n = 0; n < qel; n++) {
827 sort_ind[n] = n;
828 }
829 if (q_to_sort <= 1) return;
830
831 long n_possible_next = 1;
832
833 for (n = 0; n < q_to_sort - s_last_noninc; n++) {
834 // Iprintn(mcout, n);
835 // first it finds the minimum along the rest and replaces if it is less
836 long nmax = n_possible_next;
837 // Iprintn(mcout, nmax);
838 long ind_nmax = sort_ind[nmax];
839 int s_change_possible_next = 0;
840
841 // for(m=n+2; m<q_to_sort; m++)
842 for (m = n_possible_next + 1; m < qel; m++) {
843 // Iprint3n(mcout, ind_nmax, m, sort_ind[m]);
844 if (el[ind_nmax] < el[sort_ind[m]]) {
845 n_possible_next = nmax;
846 s_change_possible_next = 1;
847 nmax = m;
848 // Iprintn(mcout, nmax);
849 ind_nmax = sort_ind[nmax];
850 }
851 }
852 if (s_change_possible_next == 0 || n_possible_next < n + 2) {
853 n_possible_next = n + 2;
854 }
855 // Iprint4n(mcout, n, sort_ind[n], ind_nmax, el[ind_nmax]);
856 if (el[sort_ind[n]] < el[ind_nmax]) {
857 if (s_change_possible_next == 1) {
858 if (n_possible_next < q_to_sort &&
859 el[sort_ind[n]] > el[sort_ind[n_possible_next]]) {
860 n_possible_next = nmax;
861 }
862 }
863 // long t = sort_ind.acu(nmin);
864 sort_ind[nmax] = sort_ind[n];
865 sort_ind[n] = ind_nmax;
866 }
867 }
868 sort_ind.put_qel(qel);
869}

◆ sort_select_increasing()

template<class T >
void Heed::DynLinArr< T >::sort_select_increasing ( DynLinArr< long > &  sort_ind,
long  q_to_sort = 0 
) const

Definition at line 742 of file AbsArr.h.

743 {
744 mfunnamep(
745 "void DynLinArr<T>::sort_select_increasing(DynLinArr< long >& "
746 "sort_ind, long q_to_sort = 0) const");
747
748 check_econd12(q_to_sort, >, qel, mcerr);
749 long s_last_noninc = 0;
750 if (q_to_sort <= 0) {
751 q_to_sort = qel;
752 s_last_noninc = 1;
753 } else if (q_to_sort == qel) {
754 s_last_noninc = 1;
755 }
756
757 // if(qel <= 1) return;
758 sort_ind.clear();
759 sort_ind.pilfer(DynLinArr<long>(qel));
760 long n, m;
761 for (n = 0; n < qel; n++) {
762 sort_ind[n] = n;
763 }
764 if (q_to_sort <= 1) return;
765
766 long n_possible_next = 1;
767
768 for (n = 0; n < q_to_sort - s_last_noninc; n++) {
769 // first it finds the minimum along the rest and replaces if it is less
770 long nmin = n_possible_next;
771 long ind_nmin = sort_ind[nmin];
772 int s_change_possible_next = 0;
773
774 // for(m=n+2; m<q_to_sort; m++)
775 for (m = n_possible_next + 1; m < qel; m++) {
776 if (el[ind_nmin] > el[sort_ind[m]])
777 // if(el[sort_ind.acu(nmin)] > el[sort_ind.acu(m)])
778 {
779 n_possible_next = nmin;
780 s_change_possible_next = 1;
781 nmin = m;
782 ind_nmin = sort_ind[nmin];
783 }
784 }
785 if (s_change_possible_next == 0 || n_possible_next < n + 2) {
786 n_possible_next = n + 2;
787 }
788 if (el[sort_ind[n]] > el[ind_nmin])
789 // if(el[sort_ind.acu(n)] > el[sort_ind.acu(nmin)])
790 {
791 if (s_change_possible_next == 1) {
792 if (n_possible_next < q_to_sort &&
793 el[sort_ind[n]] < el[sort_ind[n_possible_next]]) {
794 n_possible_next = nmin;
795 }
796 }
797 // long t = sort_ind.acu(nmin);
798 sort_ind[nmin] = sort_ind[n];
799 sort_ind[n] = ind_nmin;
800 }
801 }
802 sort_ind.put_qel(qel);
803}

◆ top()

template<class T >
DynArr< T > Heed::DynLinArr< T >::top ( void  )

Definition at line 2511 of file AbsArr.h.

2511 {
2512 check();
2513 DynArr<T> r(1, qel);
2514 long n;
2515 for (n = 0; n < qel; n++) {
2516 r.ac(0, n) = el[n];
2517 }
2518 return r;
2519}

Friends And Related Function Documentation

◆ apply1

template<class T >
template<class P >
void apply1 ( DynLinArr< P > &  ar,
void(*)(P &f)  fun 
)
friend

◆ apply2

template<class T >
template<class P , class X >
void apply2 ( DynLinArr< P > &  ar,
void(*)(P &f, void(*fun21)(X &f))  fun1,
void(*)(X &f)  fun2 
)
friend

The documentation for this class was generated from the following file: