Changes in libcfa/src/bits/sequence.hfa [a78c3ff:a5a67ab8]
- File:
-
- 1 edited
-
libcfa/src/bits/sequence.hfa (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/sequence.hfa
ra78c3ff ra5a67ab8 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 } // post: n == tail() & succ(n) == 0 | n != tail() & *succ(n) in *s53 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: //
Note:
See TracChangeset
for help on using the changeset viewer.