19 #include "tbci/basics.h" 27 # pragma interface "list.h" 59 template <
typename T>
class List;
77 curr (li.curr), currnr (li.currnr),
78 vers (li.vers), lst (li.lst), dir(li.dir) {}
85 operator bool ()
const;
92 bool operator < (const ListIterator<T>& li)
const;
94 bool operator <= (const ListIterator<T>& li)
const;
101 : vers (_list.vers), lst (&_list), dir (1)
109 template <
typename T>
119 template <
typename T>
125 template <
typename T>
134 template <
typename T>
144 template <
typename T>
150 template <
typename T>
160 template <
typename T>
184 template <
typename T>
208 template <
typename T>
217 template <
typename T>
220 return !(*
this == li);
223 template <
typename T>
231 template <
typename T>
239 template <
typename T>
242 return !(*
this <= li);
245 template <
typename T>
248 return !(*
this < li);
252 template <
typename T>
267 const unsigned long nr)
274 template <
typename T>
288 template <
typename T>
316 iterator begin ()
const;
317 iterator
end ()
const;
318 riterator rbegin ()
const;
319 riterator rend ()
const;
331 T* getfirst ()
const;
336 T* setfirst ()
const;
345 unsigned long getlength ()
const;
346 unsigned long size ()
const;
348 unsigned long getcurrnr ()
const;
349 unsigned long getnr (
const T*)
const;
350 unsigned long getnr ()
const;
351 T* getbynr (
long)
const;
353 T* setcurrnr (
const unsigned long)
const;
354 T*
setcurr (
const T* rec)
const { setcurrnr (getnr (rec));
return getcurr (); }
356 void dumpList ()
const;
361 template <
typename T>
364 while (last -> next !=
NULL) {
365 last = last -> next; count++;
370 template <
typename T>
384 template <
typename T>
401 template <
typename T>
416 template <
typename T>
435 template <
typename T>
441 template <
typename T>
444 T *tmp = this->append ();
445 *tmp = *data;
return tmp;
449 template <
typename T>
452 if (!
curr)
return append();
466 template <
typename T>
474 template <
typename T>
509 template <
typename T>
519 curr->next = detached;
528 curr->next = detached;
538 curr->prev->next = detached;
539 detached =
curr->prev;
549 del->
next = detached;
557 template <
typename T>
560 if (last ==
NULL)
return;
564 while (!(last->data == delroot)) {
566 curr = last->prev;
delete last; last =
curr;
569 fprintf(stderr,
"List::deltree: error: wrong pointer provided !\n");
571 STD__ cerr <<
"List::deltree: error: wrong pointer provided !" <<
'\n';
579 curr = last->prev;
delete last; last =
curr;
587 template <
typename T>
591 deltree (root -> data);
602 template <
typename T>
605 template <
typename T>
608 template <
typename T>
611 template <
typename T>
616 template <
typename T>
618 {
return (root?root->data:
NULTP); }
620 template <
typename T>
622 {
return (last?last->data:
NULTP); }
624 template <
typename T>
628 template <
typename T>
631 else return curr->next->data; }
633 template <
typename T>
636 else return curr->prev->data; }
638 template <
typename T>
642 template <
typename T>
646 template <
typename T>
652 template <
typename T>
658 template <
typename T>
662 template <
typename T>
666 template <
typename T>
670 template <
typename T>
676 unsigned int ctr = 0;
679 if (rec == ptr->
data)
break;
703 template <
typename T>
706 if (root==
NULL)
return 0;
711 if (rec == ptr->
data)
return cntr;
717 template <
typename T>
721 template <
typename T>
724 if ((
unsigned)ctr >= count || root ==
NULL)
735 template <
typename T>
745 template <
typename T>
749 printf (
"Length:%li Curr:%li ", count,
currnr);
750 printf (
"ROOT=%p CURR=%p LAST=%p\n", root,
curr, last);
752 printf (
"Elem:%p Prev:%p Next:%p Data:%p\n", tmp, tmp->
prev, tmp->
next, tmp->
data);
760 # define EQDOUBLE = double 769 template <
typename T,
typename S EQDOUBLE>
782 void qsort (
bool =
false);
783 T* sortin_r (
T&,
bool =
false);
784 long move_window (
const S & val)
const;
787 template <
typename T,
typename S>
793 S test = (S)(((
double)le->
data->getval()+(double)ri->
data->getval())/2);
809 while ((
dir?le->
data->getval()>test:le->
data->getval()<test)) {
817 while ((
dir? ri->
data->getval() < test: ri->
data->getval() > test)) {
827 le = le->
next;
if (le == ri) lesri = 0;
829 if (lesri == 0) lesri = -1;
830 else if (le == ri) lesri = 0;
832 else if (lesri == 0) {
853 template <
typename T,
typename S>
857 if (root ==
NULL || root == last)
862 template <
class T,
class S>
865 bool sortedin =
false;
867 ptr2 = (frst? root: last);
868 bool comp = (dat.getval() < ptr2->
data->getval()) ^
dir;
873 fprintf (stderr,
"Not yet implemented !\n");
875 STD__ cerr <<
"Not yet implemented !\n";
883 if (!comp)
return ptr2->
data;
887 if (!ptr2)
return last->
data;
889 ptr = last; last = ptr2;
890 while (ptr2 && !sortedin) {
891 comp = (dat.getval() < ptr2->
data->getval()) ^
dir;
907 root->
prev = ptr; root = ptr;
921 template <
typename T,
typename S>
934 if ( (
curr == root ||
curr->data->getval() <= val)
935 && (!next || next->
data->getval() >= val))
940 while (next->
next && next->
data->getval() < val) {
943 if (
curr->next != next) {
948 while (
curr->prev &&
curr->data->getval() > val) {
956 if ( (
curr == root ||
curr->data->getval() >= val)
957 && (!next || next->
data->getval() <= val))
962 while (next->
next && next->
data->getval() > val) {
965 if (
curr->next != next) {
970 while (
curr->prev &&
curr->data->getval() < val) {
978 #ifdef NAMESPACE_TBCI
bool operator>=(const CPLX__ complex< T > &a, const CPLX__ complex< T > &b)
unsigned long getnr() const
ListIterator(const List< T > &_list, T *dataptr=0)
bool operator==(const ListIterator< T > &li) const
ListRIterator(const List< T > &_list, ListItem< T > *li, const unsigned long nr)
long move_window(const S &val) const
List< T > & alias(const List< T > &)
unsigned long size() const
ListIterator< T > iterator
ListRIterator< T > & operator=(const ListIterator< T > &)
ListIterator< T > & operator--()
bool operator!=(const ListIterator< T > &li) const
ListIterator(const ListIterator< T > &li)
ListIterator< T > & operator=(const ListIterator< T > &)
unsigned long getlength() const
NAMESPACE_CSTD_END NAMESPACE_CPLX bool operator>(const CPLX__ complex< T > &a, const CPLX__ complex< T > &b)
defined(NO_NS)
BdMatrix< T > operator*(const T &v, const BdMatrix< T > &m)
ListRIterator(const List< T > &_list, T *dataptr)
bool operator>(const ListIterator< T > &li) const
bool operator!=(const F_BandMatrix< T > &m1, const F_BandMatrix< T > &m2)
bool operator<=(const ListIterator< T > &li) const
T * setcurrnr(const unsigned long) const
ListRIterator(const List< T > &_list, ListItem< T > *li)
T * sortin_r(T &, bool=false)
ListRIterator< T > riterator
A numerically sortable List.
bool operator==(const F_BandMatrix< T > &m1, const F_BandMatrix< T > &m2)
List< T > & operator=(const List< T > &)
ListIterator< T > & operator++()
T * setcurr(const T *rec) const
bool operator<(const ListIterator< T > &li) const
unsigned long getcurrnr() const
Note that the numbers are 1-based.
void quick(ListItem< T > *, ListItem< T > *)
void qsort(bool=false)
Quicksort is really quick: sorts 1 000 000 records (int) in less than 50 secs on a 486DX4/100 under L...
bool operator>=(const ListIterator< T > &li) const