Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/bits/stack.hfa

    r9536761 r7d4ce2a  
    33#include "bits/collection.hfa"
    44
    5 // A Stack(T) is a Collection(T) defining the ordering that nodes are returned by drop() in the reverse order from those
    6 // added by add(). T must be a public descendant of uColable.
    7 
    8 // The implementation is a typical singly-linked list, except the next field of the last element points to itself
    9 // instead of being null.
    10 
    11 forall( dtype T | { T *& Next ( T * ); } ) {
     5forall( dtype T ) {
    126        struct Stack {
    137                inline Collection;                                                              // Plan 9 inheritance
     
    3125                }
    3226
    33                 T & addHead( Stack(T) & s, T & n ) with( s ) {
     27                void addHead( Stack(T) & s, T & n ) with( s ) {
    3428                        #ifdef __CFA_DEBUG__
    3529                        if ( listed( (Colable &)(n) ) ) abort( "(Stack &)%p.addHead( %p ) : Node is already on another list.", &s, n );
     
    3731                        Next( &n ) = &head( s ) ? &head( s ) : &n;
    3832                        root = &n;
    39                         return n;
    4033                }
    4134
    42                 T & add( Stack(T) & s, T & n ) with( s ) {
    43                         return addHead( s, n );
     35                void add( Stack(T) & s, T & n ) with( s ) {
     36                        addHead( s, n );
    4437                }
    4538
    46                 T & push( Stack(T) & s, T & n ) with( s ) {
    47                         return addHead( s, n );
     39                void push( Stack(T) & s, T & n ) with( s ) {
     40                        addHead( s, n );
    4841                }
    4942
     
    5144                        T & t = head( s );
    5245                        if ( root ) {
    53                                 root = ( T *)Next( (T *)root );
     46                                root = ( T *)Next( root );
    5447                                if ( &head( s ) == &t ) root = 0p;              // only one element ?
    5548                                Next( &t ) = 0p;
     
    6457} // distribution
    6558
    66 // A StackIter(T) is a subclass of ColIter(T) that generates the elements of a Stack(T).  It returns the elements in the
    67 // order returned by drop().
    6859
    69 forall( dtype T | { T *& Next ( T * ); } ) {
     60forall( dtype T ) {
    7061        struct StackIter {
    7162                inline ColIter;                                                                 // Plan 9 inheritance
     
    7768                } // post: curr == 0p
    7869
    79                 // create an iterator active in stack s
     70                // create an iterator active in Stack s
    8071                void ?{}( StackIter(T) & si, Stack(T) & s ) with( si ) {
    8172                        curr = &head( s );
     
    8677                } // post: curr = {e in s}
    8778
    88                 // make existing iterator active in stack s
     79                // make existing iterator active in Stack q
    8980                void over( StackIter(T) & si, Stack(T) & s ) with( si ) {
    9081                        curr = &head( s );
    9182                } // post: curr = {e in s}
    9283
    93                 bool ?|?( StackIter(T) & si, T && tp ) with( si ) {
     84                bool ?>>?( StackIter(T) & si, T && tp ) with( si ) {
    9485                        if ( curr ) {
    9586                                &tp = Curr( si );
Note: See TracChangeset for help on using the changeset viewer.