Changeset 9536761 for libcfa


Ignore:
Timestamp:
Dec 28, 2020, 4:00:51 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
657c36f
Parents:
1e6f632f
Message:

formatting, change container iterator operator from ">>" to "|"

Location:
libcfa/src/bits
Files:
4 edited

Legend:

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

    r1e6f632f r9536761  
    6868
    6969struct ColIter {
    70         void * curr;                                                                            // element to be returned by >>
     70        void * curr;                                                                            // element returned by |
    7171};
    7272
  • libcfa/src/bits/queue.hfa

    r1e6f632f r9536761  
    22
    33#include "bits/collection.hfa"
     4
     5// A Queue(T) is a Collection(T) defining the ordering that nodes are returned by drop() in the same 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.
    410
    511forall( dtype T | { T *& Next ( T * ); } ) {
     
    108114                } // post: ! listed( n )
    109115
    110                 T & dropTail( Queue(T) & q ) with( q ) { // O(n)
     116                T & dropTail( Queue(T) & q ) with( q ) {                // O(n)
    111117                        T & n = tail( q );
    112118                        return &n ? remove( q, n ), n : *0p;
     
    155161                } // post: curr == 0p
    156162
    157                 // create an iterator active in Queue q
     163                // create an iterator active in queue q
    158164                void ?{}( QueueIter(T) & qi, Queue(T) & q ) with( qi ) {
    159165                        curr = &head( q );
     
    164170                } // post: curr = {e in q}
    165171
    166                 // make existing iterator active in Queue q
     172                // make existing iterator active in queue q
    167173                void over( QueueIter(T) & qi, Queue(T) & q ) with( qi ) {
    168174                        curr = &head( q );
    169175                } // post: curr = {e in q}
    170176
    171                 bool ?>>?( QueueIter(T) & qi, T && tp ) with( qi ) {
     177                bool ?|?( QueueIter(T) & qi, T && tp ) with( qi ) {
    172178                        if ( curr ) {
    173179                                &tp = Curr( qi );
     
    177183                        return &tp != 0p;
    178184                }
    179                 // post: elts == null & !operator>>(tp) | elts != null & *tp' in elts & elts' == elts - *tp & operator>>(tp)
     185                // post: elts == null & !operator|(tp) | elts != null & *tp' in elts & elts' == elts - *tp & operator|(tp)
    180186        } // distribution
    181187} // distribution
  • libcfa/src/bits/sequence.hfa

    r1e6f632f r9536761  
    3636} // distribution
    3737
     38
     39// A Sequence(T) is a Collection(T) defining the ordering of a uStack and uQueue, and to insert and remove elements
     40// anywhere in the sequence. T must be a public descendant of uSeqable.
     41
     42// The implementation is a typical doubly-linked list, except the next field of the last node points at the first node
     43// and the back field of the last node points at the first node (circular).
     44
    3845forall( dtype T | { T *& Back ( T * ); T *& Next ( T * ); } ) {
    3946        struct Sequence {
     
    5259                void ?{}( Sequence(T) & s ) with( s ) {
    5360                        ((Collection &)s){};
    54                 }       // post: isEmpty().
    55 
    56                 // Return a pointer to the last sequence element, without removing it. 
     61                }       // post: isEmpty()
     62
     63                // Return a pointer to the last sequence element, without removing it.
    5764                T & tail( Sequence(T) & s ) with( s ) {
    5865                        return root ? (T &)*Back( &head( s ) ) : *0p;
     
    6774                } // post: n == tail() & succ(n) == 0 | n != tail() & *succ(n) in *s
    6875
    69                 // Return a pointer to the element before *n, or 0p if there isn't one.
     76                // Return a pointer to the element before *n, or 0p if list empty.
    7077                T * pred( Sequence(T) & s, T * n ) with( s ) {  // pre: *n in *s
    7178                        #ifdef __CFA_DEBUG__
     
    7380                        #endif // __CFA_DEBUG__
    7481                        return n == &head( s ) ? 0p : Back( n );
    75                 }       // post: n == head() & head(n) == 0 | n != head() & *pred(n) in *s
    76 
    77 
    78                 // Insert *n into the sequence before *bef, or at the end if bef == 0.
     82                } // post: n == head() & head(n) == 0 | n != head() & *pred(n) in *s
     83
     84
     85                // Insert *n into the sequence before *bef, or at the end if bef == 0p.
    7986                T & insertBef( Sequence(T) & s, T & n, T & bef ) with( s ) { // pre: !n->listed() & *bef in *s
    8087                        #ifdef __CFA_DEBUG__
     
    137144                        } // if
    138145                        return n;
    139                 }        // post: n->listed() & *n in *s & succ(n) == bef
     146                } // post: n->listed() & *n in *s & succ(n) == bef
    140147               
    141148                // pre: n->listed() & *n in *s
     
    152159                        Next( &n ) = Back( &n ) = 0p;
    153160                        return n;
    154                 }                                                       // post: !n->listed().
     161                } // post: !n->listed()
    155162
    156163                // Add an element to the head of the sequence.
     
    158165                        return insertAft( s, *0p, n );
    159166                }
     167
    160168                // Add an element to the tail of the sequence.
    161169                T & addTail( Sequence(T) & s, T & n ) {                 // pre: !n->listed(); post: n->listed() & head() == n
    162170                        return insertBef( s, n, *0p );
    163171                }
     172
    164173                // Add an element to the tail of the sequence.
    165174                T & add( Sequence(T) & s, T & n ) {                             // pre: !n->listed(); post: n->listed() & head() == n
    166175                        return addTail( s, n );
    167176                }
     177
    168178                // Remove and return the head element in the sequence.
    169179                T & dropHead( Sequence(T) & s ) {
     
    171181                        return &n ? remove( s, n ), n : *0p;
    172182                }
     183
    173184                // Remove and return the head element in the sequence.
    174185                T & drop( Sequence(T) & s ) {
    175186                        return dropHead( s );
    176187                }
     188
    177189                // Remove and return the tail element in the sequence.
    178190                T & dropTail( Sequence(T) & s ) {
     
    233245                        ((ColIter &)si){};
    234246                        seq = 0p;
    235                 } // post: elts = null.
    236 
     247                } // post: elts = null
     248
     249                // Create a iterator active in sequence s.
    237250                void ?{}( SeqIter(T) & si, Sequence(T) & s ) with( si ) {
    238251                        ((ColIter &)si){};
    239252                        seq = &s;
    240253                        curr = &head( s );
    241                 } // post: elts = null.
     254                } // post: elts = null
    242255
    243256                void ?{}( SeqIter(T) & si, Sequence(T) & s, T & start ) with( si ) {
     
    245258                        seq = &s;
    246259                        curr = &start;
    247                 } // post: elts = null.
    248 
     260                } // post: elts = null
     261
     262                // Make the iterator active in sequence s.
    249263                void over( SeqIter(T) & si, Sequence(T) & s ) with( si ) {
    250264                        seq = &s;
    251265                        curr = &head( s );
    252                 } // post: elts = {e in s}.
    253 
    254                 bool ?>>?( SeqIter(T) & si, T && tp ) with( si ) {
     266                } // post: elts = {e in s}
     267
     268                bool ?|?( SeqIter(T) & si, T && tp ) with( si ) {
    255269                        if ( curr ) {
    256270                                &tp = Curr( si );
     
    274288                        ((ColIter &)si){};
    275289                        seq = 0p;
    276                 } // post: elts = null.
    277 
     290                } // post: elts = null
     291
     292                // Create a iterator active in sequence s.
    278293                void ?{}( SeqIterRev(T) & si, Sequence(T) & s ) with( si ) {   
    279294                        ((ColIter &)si){};
    280295                        seq = &s;
    281296                        curr = &tail( s );
    282                 } // post: elts = null.
     297                } // post: elts = null
    283298
    284299                void ?{}( SeqIterRev(T) & si, Sequence(T) & s, T & start ) with( si ) {
     
    286301                        seq = &s;
    287302                        curr = &start;
    288                 } // post: elts = null.
    289 
     303                } // post: elts = null
     304
     305                // Make the iterator active in sequence s.
    290306                void over( SeqIterRev(T) & si, Sequence(T) & s ) with( si ) {
    291307                        seq = &s;
    292308                        curr = &tail( s );
    293                 } // post: elts = {e in s}.
    294 
    295                 bool ?>>?( SeqIterRev(T) & si, T && tp ) with( si ) {
     309                } // post: elts = {e in s}
     310
     311                bool ?|?( SeqIterRev(T) & si, T && tp ) with( si ) {
    296312                        if ( curr ) {
    297313                                &tp = Curr( si );
  • libcfa/src/bits/stack.hfa

    r1e6f632f r9536761  
    22
    33#include "bits/collection.hfa"
     4
     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.
    410
    511forall( dtype T | { T *& Next ( T * ); } ) {
     
    5864} // distribution
    5965
     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().
    6068
    6169forall( dtype T | { T *& Next ( T * ); } ) {
     
    6977                } // post: curr == 0p
    7078
    71                 // create an iterator active in Stack s
     79                // create an iterator active in stack s
    7280                void ?{}( StackIter(T) & si, Stack(T) & s ) with( si ) {
    7381                        curr = &head( s );
     
    7886                } // post: curr = {e in s}
    7987
    80                 // make existing iterator active in Stack q
     88                // make existing iterator active in stack s
    8189                void over( StackIter(T) & si, Stack(T) & s ) with( si ) {
    8290                        curr = &head( s );
    8391                } // post: curr = {e in s}
    8492
    85                 bool ?>>?( StackIter(T) & si, T && tp ) with( si ) {
     93                bool ?|?( StackIter(T) & si, T && tp ) with( si ) {
    8694                        if ( curr ) {
    8795                                &tp = Curr( si );
Note: See TracChangeset for help on using the changeset viewer.