Garfield++ 3.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:205
#define Iprint2n(file, name1, name2)
Definition: prstream.h:220

◆ 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 519 of file AbsArr.h.

520 : RegPassivePtr(),
521 qel(0),
522 el(NULL) {
523#ifdef DEBUG_DYNLINARR
524 mcout << "DynLinArr(const DynLinArr<T>& f) is working\n";
525#endif
526 *this = f;
527}
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 2553 of file AbsArr.h.

2553 {
2554 // mcout<<"template<class T> DynLinArr<T>::DynLinArr(const DynArr<T>& f):\n";
2555 f.check();
2556 long qdim = f.get_qdim();
2557 if (qdim != 1) {
2558 mcerr << "ERROR in DynLinArr<T>::DynLinArr(const DynArr<T>& f):\n"
2559 << "f.get_qdim() != 1, f.get_qdim()=" << f.get_qdim() << '\n';
2560 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2561 << '\n';
2562 spexit(mcerr);
2563 }
2564 const DynLinArr<long>& qelem = f.get_qel();
2565 qel = qelem[0];
2566 // mcout<<"qel="<<qel<<'\n';
2567 if (qel > 0) {
2568 el = new T[qel];
2569 for (long n = 0; n < qel; n++) el[n] = f.ac(n);
2570 } else
2571 el = NULL;
2572}

◆ DynLinArr() [8/8]

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

Definition at line 2575 of file AbsArr.h.

2579{
2580 f.check();
2581 long qdim = f.get_qdim();
2582 if (qdim != 2) {
2583 mcerr << "ERROR in DynLinArr<T>::DynLinArr(const DynArr<T>& f, int "
2584 "n_of_dim,long roc_number):\n"
2585 << "f.get_qdim() != 2, f.get_qdim()=" << f.get_qdim() << '\n';
2586 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2587 << '\n';
2588 spexit(mcerr);
2589 }
2590 const DynLinArr<long>& qelem = f.get_qel();
2591 if (n_of_dim == 0) {
2592 qel = qelem[1];
2593 } else {
2594 qel = qelem[0];
2595 }
2596 // mcout<<"qel="<<qel<<'\n';
2597 if (qel > 0) {
2598 el = new T[qel];
2599 long n;
2600 if (n_of_dim == 0) {
2601 for (n = 0; n < qel; n++) el[n] = f.ac(roc_number, n);
2602 } else {
2603 for (n = 0; n < qel; n++) el[n] = f.ac(n, roc_number);
2604 }
2605 }
2606}

◆ ~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)
500 //{
501 // mcout<<"DynLinArr<T>& operator=(const DynLinArr<T>& f): long(el)="
502 //<<long(el)<<'\n';
503 check();
504 f.check();
505 // First of all we allocate memory and copy to there
506 // all elements from f, because f can be part of this array,
507 // for example, one of its elements.
508 long q = f.get_qel();
509 T* temp_el = (T*)NULL;
510 if (q > 0) {
511 temp_el = new T[q];
512 for (long n = 0; n < q; n++) temp_el[n] = f[n];
513 }
514 pass(q, temp_el);
515 return *this;
516}
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 530 of file AbsArr.h.

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

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 572 of file AbsArr.h.

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

◆ sort() [1/2]

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

Definition at line 689 of file AbsArr.h.

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

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

◆ 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 809 of file AbsArr.h.

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

◆ 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 745 of file AbsArr.h.

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

◆ top()

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

Definition at line 2527 of file AbsArr.h.

2527 {
2528 check();
2529 DynArr<T> r(1, qel);
2530 long n;
2531 for (n = 0; n < qel; n++) {
2532 r.ac(0, n) = el[n];
2533 }
2534 return r;
2535}

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: