Changeset 1de50a9
- Timestamp:
- Dec 3, 2020, 8:58:29 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 032fd93
- Parents:
- cf2257f (diff), 7b2a786 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- libcfa/src/bits
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/queue.hfa
rcf2257f r1de50a9 27 27 } 28 28 29 T & succ( Queue(T) & q, T &n ) with( q ) { // pre: *n in *q29 T * succ( Queue(T) & q, T * n ) with( q ) { // pre: *n in *q 30 30 #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 ); 32 32 #endif // __CFA_DEBUG__ 33 return (Next( &n ) == &n) ? *0p : *Next( &n );33 return (Next( n ) == n) ? 0p : Next( n ); 34 34 } // post: n == tail() & succ(n) == 0 | n != tail() & *succ(n) in *q 35 35 … … 62 62 63 63 T & dropHead( Queue(T) & q ) with( q ) { 64 T * t = &head( q );64 T & t = head( q ); 65 65 if ( root ) { 66 66 root = Next( root ); 67 if ( &head( q ) == t ) {67 if ( &head( q ) == &t ) { 68 68 root = last = 0p; // only one element 69 69 } 70 Next( t ) = 0p;70 Next( &t ) = 0p; 71 71 } 72 return *t;72 return t; 73 73 } 74 74 … … 81 81 if ( ! listed( (Colable &)n ) ) abort( "(Queue &)%p.remove( %p ) : Node is not on a list.", &q, &n ); 82 82 #endif // __CFA_DEBUG__ 83 T * prev = 0 ;83 T * prev = 0p; 84 84 T * curr = (T *)root; 85 85 for ( ;; ) { 86 if ( &n == curr) { // found => remove87 if ( (T *)root == &n) {86 if ( &n == curr ) { // found => remove 87 if ( (T *)root == &n ) { 88 88 dropHead( q ); 89 } else if ( last == &n) {89 } else if ( last == &n ) { 90 90 last = prev; 91 91 Next( last ) = last; … … 132 132 to.last = &n; // end of "to" list 133 133 from.root = Next( &n ); // start of "from" list 134 if ( &n == &head( from ) ) { 134 if ( &n == &head( from ) ) { // last node in list ? 135 135 from.root = from.last = 0p; // mark "from" list empty 136 136 } else { 137 Next( &n ) = &n; 137 Next( &n ) = &n; // fix end of "to" list 138 138 } 139 139 transfer( q, to ); … … 179 179 180 180 // Local Variables: // 181 // compile-command: " make install" //181 // compile-command: "cfa queue.cfa" // 182 182 // End: // -
libcfa/src/bits/sequence.hfa
rcf2257f r1de50a9 2 2 3 3 #include "collection.hfa" 4 #include <stdlib.hfa>5 #include <stdio.h>6 4 7 5 struct Seqable { … … 50 48 T & tail( Sequence(T) & s ) with( s ) { 51 49 return root ? (T &)*Back( &head( s ) ) : *0p; 52 } // post: empty() & tail() == 0 | !empty() & tail() in *s \50 } // post: empty() & tail() == 0 | !empty() & tail() in *s 53 51 54 52 // Return a pointer to the element after *n, or 0p if there isn't one. 55 T & succ( Sequence(T) & s, T &n ) with( s ) { // pre: *n in *s56 #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 } 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 61 59 62 60 // Return a pointer to the element before *n, or 0p if there isn't one. 63 T & pred( Sequence(T) & s, T &n ) with( s ) { // pre: *n in *s64 #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 );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 ); 68 66 } // post: n == head() & head(n) == 0 | n != head() & *pred(n) in *s 69 67 … … 137 135 if ( &n == &head( s ) ) { 138 136 if ( Next( &head( s ) ) == &head( s ) ) root = 0p; 139 else root = Next( &head( s ) );137 else root = Next( &head( s ) ); 140 138 } // if 141 139 Back( Next( &n ) ) = Back( &n ); … … 227 225 curr = &head( s ); 228 226 } // post: elts = null. 229 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 230 234 void over( SeqIter(T) & si, Sequence(T) & s ) with( si ) { 231 235 seq = &s; … … 236 240 if ( curr ) { 237 241 &tp = Curr( si ); 238 T * n = &succ( *seq, *Curr( si ) );242 T * n = succ( *seq, Curr( si ) ); 239 243 curr = n == &head( *seq ) ? 0p : n; 240 244 } else &tp = 0p; … … 261 265 curr = &tail( s ); 262 266 } // post: elts = null. 263 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 264 274 void over( SeqIterRev(T) & si, Sequence(T) & s ) with( si ) { 265 275 seq = &s; … … 270 280 if ( curr ) { 271 281 &tp = Curr( si ); 272 T * n = &pred( *seq, *Curr( si ) );282 T * n = pred( *seq, Curr( si ) ); 273 283 curr = n == &tail( *seq ) ? 0p : n; 274 284 } else &tp = 0p; … … 279 289 280 290 // Local Variables: // 281 // compile-command: " make install" //291 // compile-command: "cfa sequence.hfa" // 282 292 // End: // -
libcfa/src/bits/stack.hfa
rcf2257f r1de50a9 10 10 inline { 11 11 // 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 ); 14 14 } // post: empty() & head() == 0 | !empty() & head() in *this 15 15 … … 22 22 23 23 T & top( Stack(T) & s ) with( s ) { 24 return *head( s );24 return head( s ); 25 25 } 26 26 … … 29 29 if ( listed( (Colable &)(n) ) ) abort( "(Stack &)%p.addHead( %p ) : Node is already on another list.", &s, n ); 30 30 #endif // __CFA_DEBUG__ 31 Next( &n ) = head( s ) ?head( s ) : &n;31 Next( &n ) = &head( s ) ? &head( s ) : &n; 32 32 root = &n; 33 33 } … … 42 42 43 43 T & drop( Stack(T) & s ) with( s ) { 44 T & t = *head( s );44 T & t = head( s ); 45 45 if ( root ) { 46 46 root = ( T *)Next(root); 47 if ( head( s ) == &t ) root = 0p; // only one element ?47 if ( &head( s ) == &t ) root = 0p; // only one element ? 48 48 Next( &t ) = 0p; 49 49 } // if … … 70 70 // create an iterator active in Stack s 71 71 void ?{}( StackIter(T) & si, Stack(T) & s ) with( si ) { 72 curr = head( s );72 curr = &head( s ); 73 73 } // post: curr = {e in s} 74 74 … … 79 79 // make existing iterator active in Stack q 80 80 void over( StackIter(T) & si, Stack(T) & s ) with( si ) { 81 curr = head( s );81 curr = &head( s ); 82 82 } // post: curr = {e in s} 83 83
Note: See TracChangeset
for help on using the changeset viewer.