Changes in / [1de50a9:cf2257f]


Ignore:
Location:
libcfa/src/bits
Files:
1 deleted
3 edited

Legend:

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

    r1de50a9 rcf2257f  
    2727                }
    2828
    29                 T * succ( Queue(T) & q, T * n ) with( q ) {             // pre: *n in *q
     29                T & succ( Queue(T) & q, T & n ) with( q ) {             // pre: *n in *q
    3030#ifdef __CFA_DEBUG__
    31                         if ( ! listed( n ) ) abort( "(Queue &)%p.succ( %p ) : Node is not on a list.", &q, n );
     31                        if ( ! listed( &n ) ) abort( "(Queue &)%p.succ( %p ) : Node is not on a list.", &q, &n );
    3232#endif // __CFA_DEBUG__
    33                         return (Next( n ) == n) ? 0p : Next( n );
     33                        return (Next( &n ) == &n) ? *0p : *Next( &n );
    3434                } // post: n == tail() & succ(n) == 0 | n != tail() & *succ(n) in *q
    3535
     
    6262
    6363                T & dropHead( Queue(T) & q ) with( q ) {
    64                         T & t = head( q );
     64                        T * t = &head( q );
    6565                        if ( root ) {
    6666                                root = Next( root );
    67                                 if ( &head( q ) == &t ) {
     67                                if ( &head( q ) == t ) {
    6868                                        root = last = 0p;                                       // only one element
    6969                                }
    70                                 Next( &t ) = 0p;
     70                                Next( t ) = 0p;
    7171                        }
    72                         return t;
     72                        return *t;
    7373                }
    7474
     
    8181                        if ( ! listed( (Colable &)n ) ) abort( "(Queue &)%p.remove( %p ) : Node is not on a list.", &q, &n );
    8282#endif // __CFA_DEBUG__
    83                         T * prev = 0p;
     83                        T * prev = 0;
    8484                        T * curr = (T *)root;
    8585                        for ( ;; ) {
    86                                 if ( &n == curr ) {                                             // found => remove
    87                                         if ( (T *)root == &n ) {
     86                                if (&n == curr) {                                               // found => remove
     87                                        if ((T *)root == &n) {
    8888                                                dropHead( q );
    89                                         } else if ( last == &n ) {
     89                                        } else if (last == &n) {
    9090                                                last = prev;
    9191                                                Next( last ) = last;
     
    132132                        to.last = &n;                                                           // end of "to" list
    133133                        from.root = Next( &n );                                         // start of "from" list
    134                         if ( &n == &head( from ) ) {                            // last node in list ?
     134                        if ( &n == &head( from ) ) {                                    // last node in list ?
    135135                                from.root = from.last = 0p;                             // mark "from" list empty
    136136                        } else {
    137                                 Next( &n ) = &n;                                                // fix end of "to" list
     137                                Next( &n ) = &n;                                                        // fix end of "to" list
    138138                        }
    139139                        transfer( q, to );
     
    179179
    180180// Local Variables: //
    181 // compile-command: "cfa queue.cfa" //
     181// compile-command: "make install" //
    182182// End: //
  • libcfa/src/bits/sequence.hfa

    r1de50a9 rcf2257f  
    22
    33#include "collection.hfa"
     4#include <stdlib.hfa>
     5#include <stdio.h>
    46
    57struct Seqable {
     
    4850                T & tail( Sequence(T) & s ) with( s ) {
    4951                        return root ? (T &)*Back( &head( s ) ) : *0p;
    50                 }       // post: empty() & tail() == 0 | !empty() & tail() in *s
     52                }       // post: empty() & tail() == 0 | !empty() & tail() in *s\
    5153
    5254                // Return a pointer to the element after *n, or 0p if there isn't one.
    53                 T * succ( Sequence(T) & s, T * n ) with( s ) {  // pre: *n in *s
    54 #ifdef __CFA_DEBUG__
    55                         if ( ! listed( n ) ) abort( "(Sequence &)%p.succ( %p ) : Node is not on a list.", &s, n );
    56 #endif // __CFA_DEBUG__
    57                         return Next( n ) == &head( s ) ? 0p : Next( n );
    58                 } // post: n == tail() & succ(n) == 0 | n != tail() & *succ(n) in *s
     55                T & succ( Sequence(T) & s, T & n ) with( s ) {  // pre: *n in *s
     56#ifdef __CFA_DEBUG__
     57                        if ( ! listed( &n ) ) abort( "(Sequence &)%p.succ( %p ) : Node is not on a list.", &s, &n );
     58#endif // __CFA_DEBUG__
     59                        return Next( &n ) == &head( s ) ? *0p : *Next( &n );
     60                }       // post: n == tail() & succ(n) == 0 | n != tail() & *succ(n) in *s
    5961
    6062                // Return a pointer to the element before *n, or 0p if there isn't one.
    61                 T * pred( Sequence(T) & s, T * n ) with( s ) {  // pre: *n in *s
    62 #ifdef __CFA_DEBUG__
    63                         if ( ! listed( n ) ) abort( "(Sequence &)%p.pred( %p ) : Node is not on a list.", &s, n );
    64 #endif // __CFA_DEBUG__
    65                         return n == &head( s ) ? 0p : Back( n );
     63                T & pred( Sequence(T) & s, T & n ) with( s ) {  // pre: *n in *s
     64#ifdef __CFA_DEBUG__
     65                        if ( ! listed( &n ) ) abort( "(Sequence &)%p.pred( %p ) : Node is not on a list.", &s, &n );
     66#endif // __CFA_DEBUG__
     67                        return &n == &head( s ) ? *0p : *Back( &n );
    6668                }       // post: n == head() & head(n) == 0 | n != head() & *pred(n) in *s
    6769
     
    135137                        if ( &n == &head( s ) ) {
    136138                                if ( Next( &head( s ) ) == &head( s ) ) root = 0p;
    137                                 else root = Next( &head( s ) );
     139                                else root = Next( &head(s ) );
    138140                        } // if
    139141                        Back( Next( &n ) ) = Back( &n );
     
    225227                        curr = &head( s );
    226228                } // post: elts = null.
    227 
    228                 void ?{}( SeqIter(T) & si, Sequence(T) & s, T & start ) with( si ) {
    229                         ((ColIter &) si){};
    230                         seq = &s;
    231                         curr = &start;
    232                 } // post: elts = null.
    233 
     229               
    234230                void over( SeqIter(T) & si, Sequence(T) & s ) with( si ) {
    235231                        seq = &s;
     
    240236                        if ( curr ) {
    241237                                &tp = Curr( si );
    242                                 T * n = succ( *seq, Curr( si ) );
     238                                T * n = &succ( *seq, *Curr( si ) );
    243239                                curr = n == &head( *seq ) ? 0p : n;
    244240                        } else &tp = 0p;
     
    265261                        curr = &tail( s );
    266262                } // post: elts = null.
    267 
    268                 void ?{}( SeqIterRev(T) & si, Sequence(T) & s, T & start ) with( si ) {
    269                         ((ColIter &) si){};
    270                         seq = &s;
    271                         curr = &start;
    272                 } // post: elts = null.
    273 
     263               
    274264                void over( SeqIterRev(T) & si, Sequence(T) & s ) with( si ) {
    275265                        seq = &s;
     
    280270                        if ( curr ) {
    281271                                &tp = Curr( si );
    282                                 T * n = pred( *seq, Curr( si ) );
     272                                T * n = &pred( *seq, *Curr( si ) );
    283273                                curr = n == &tail( *seq ) ? 0p : n;
    284274                        } else &tp = 0p;
     
    289279
    290280// Local Variables: //
    291 // compile-command: "cfa sequence.hfa" //
     281// compile-command: "make install" //
    292282// End: //
  • libcfa/src/bits/stack.hfa

    r1de50a9 rcf2257f  
    1010        inline {
    1111                // wrappers to make Collection have T
    12                 T & head( Stack(T) & s ) with( s ) {
    13                         return *(T *)head( (Collection &)s );
     12                T * head( Stack(T) & s ) with( s ) {
     13                        return (T *)head( (Collection &)s );
    1414                } // post: empty() & head() == 0 | !empty() & head() in *this
    1515
     
    2222
    2323                T & top( Stack(T) & s ) with( s ) {
    24                         return head( s );
     24                        return *head( s );
    2525                }
    2626
     
    2929                        if ( listed( (Colable &)(n) ) ) abort( "(Stack &)%p.addHead( %p ) : Node is already on another list.", &s, n );
    3030#endif // __CFA_DEBUG__
    31                         Next( &n ) = &head( s ) ? &head( s ) : &n;
     31                        Next( &n ) = head( s ) ? head( s ) : &n;
    3232                        root = &n;
    3333                }
     
    4242
    4343                T & drop( Stack(T) & s ) with( s ) {
    44                         T & t = head( s );
     44                        T & t = *head( s );
    4545                        if ( root ) {
    4646                                root = ( T *)Next(root);
    47                                 if ( &head( s ) == &t ) root = 0p;              // only one element ?
     47                                if ( head( s ) == &t ) root = 0p;               // only one element ?
    4848                                Next( &t ) = 0p;
    4949                        } // if
     
    7070                // create an iterator active in Stack s
    7171                void ?{}( StackIter(T) & si, Stack(T) & s ) with( si ) {
    72                         curr = &head( s );
     72                        curr = head( s );
    7373                } // post: curr = {e in s}
    7474
     
    7979                // make existing iterator active in Stack q
    8080                void over( StackIter(T) & si, Stack(T) & s ) with( si ) {
    81                         curr = &head( s );
     81                        curr = head( s );
    8282                } // post: curr = {e in s}
    8383
Note: See TracChangeset for help on using the changeset viewer.