From 869d64b2795afea51e58e4ebe1d2cbf8283e6ac0 Mon Sep 17 00:00:00 2001 From: fred Date: Fri, 15 Nov 1996 23:41:54 +0000 Subject: [PATCH] flower-1.0.7 --- flower/list.cc | 87 +++++++++++++++++++++++++-------------------- flower/list.inl | 93 +++++++++---------------------------------------- 2 files changed, 66 insertions(+), 114 deletions(-) diff --git a/flower/list.cc b/flower/list.cc index 741e4ee97c..ce5e366cc8 100644 --- a/flower/list.cc +++ b/flower/list.cc @@ -34,51 +34,64 @@ List::OK() const assert(!lp); } + template -Cursor -List::top() +inline +List::~List() { -#if 0 - // ?? waarvoor is deze if ? - if ( top_ ) // equivalent: if ( size_ ) - { - Link* t = top_->previous(); - assert( t != top_ ); // silly link - while ( t ) - { - assert(false); // this is even more silly. - top_ = t; - t = top_->previous(); - } - } -#endif - -// list empty: Cursor not ok() - return Cursor( *this, top_ ); + Cursor next(*this); + for ( Cursor c( *this ); c.ok(); c = next ) { + next = c; + next++; + remove( c ); + } } - template -Cursor -List::bottom() +inline void +List::add( const T& thing, Cursor after_me ) { - /* wat is dit voor zooi? kan dit niet weg? + if (!size_) { // not much choice if list is empty + bottom_ = top_ = new Link( thing ); + } else { // add at aprioprate place + Link *p = ( after_me.ok() ) ? + after_me.pointer() : bottom().pointer(); + p->add(thing); + if (p == bottom_) // adjust bottom_ if necessary. + bottom_ = p->next(); + } - (invarianten!) - */ - if ( bottom_ ) // equivalent: if ( size_ ) - { - Link* b = bottom_->next(); - assert( b != bottom_ ); // silly link - while ( b ) - { - bottom_ = b; - b = bottom_->next(); - } - } - // list empty: Cursor not ok() - return Cursor( *this, bottom_ ); + size_++; } +/** + + Procedure: + \begin{itemize} + \item if #after_me# is #ok()#, add after #after_me#, else + \item if list !empty simply add to bottom, else + \item list is empty: create first \Ref{Link} and initialize + #bottom_# and #top_#. + \end{itemize} +*/ +template +inline void +List::insert( const T& thing, Cursor before_me ) +{ + if (!size_) { + bottom_ = top_ = new Link( thing ); + } else { + Link *p = + (before_me.ok())? + before_me.pointer() : top().pointer(); + + p->insert(thing); + if (p == top_) + top_ = p->previous(); + } + + size_++; + +} #endif diff --git a/flower/list.inl b/flower/list.inl index 8bdcf15877..d71e947050 100644 --- a/flower/list.inl +++ b/flower/list.inl @@ -1,6 +1,8 @@ // -*-c++-*- + #ifndef LIST_INL #define LIST_INL + template inline List::List() @@ -23,83 +25,6 @@ List::List( const T& thing ) set_empty(); add( thing, Cursor( *this, bottom_ ) ); } - -template -inline -List::~List() -{ - Cursor next(*this); - for ( Cursor c( *this ); c.ok(); c = next ) { - next = c; - next++; - remove( c ); - } -} - -template -inline void -List::add( const T& thing, Cursor after_me ) -{ -#if 0 - if ( after_me.ok() ) - after_me.pointer()->add( thing ); - else if ( size_ ) - bottom().pointer()->add( thing ); - else - bottom_ = top_ = new Link( thing ); -#endif - - if (!size_) { // not much choice if list is empty - bottom_ = top_ = new Link( thing ); - } else { // add at aprioprate place - Link *p = ( after_me.ok() ) ? - after_me.pointer() : bottom().pointer(); - p->add(thing); - if (p == bottom_) // adjust bottom_ if necessary. - bottom_ = p->next(); - } - - size_++; -} -/** - - Procedure: - \begin{itemize} - \item if #after_me# is #ok()#, add after #after_me#, else - \item if list !empty simply add to bottom, else - \item list is empty: create first \Ref{Link} and initialize - #bottom_# and #top_#. - \end{itemize} -*/ - -template -inline void -List::insert( const T& thing, Cursor before_me ) -{ - if (!size_) { - bottom_ = top_ = new Link( thing ); - } else { - Link *p = - (before_me.ok())? - before_me.pointer() : top().pointer(); - - p->insert(thing); - if (p == top_) - top_ = p->previous(); - } - - size_++; -#if 0 // rewrite hwn 16/9 - if ( before_me.ok() ) - before_me.pointer()->insert( thing ); - else if ( size_ ) - top().pointer()->insert( thing ); - else - bottom_ = top_ = new Link( thing ); - size_++; -#endif -} - template inline void List::remove( Cursor me ) @@ -119,6 +44,20 @@ List::size() const return size_; } +template +inline Cursor +List::top() +{ + return Cursor( *this, top_ ); +} + + +template +inline Cursor +List::bottom() +{ + return Cursor( *this, bottom_ ); +} #endif -- 2.39.5