Changes in libcfa/src/bits/sequence.hfa [636d3715:b37515b]
- File:
-
- 1 edited
-
libcfa/src/bits/sequence.hfa (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/sequence.hfa
r636d3715 rb37515b 10 10 inline { 11 11 void ?{}( Seqable & sq ) with( sq ) { 12 ((Colable & ) sq){};12 ((Colable & ) sq){}; 13 13 back = 0p; 14 14 } // post: ! listed() … … 34 34 } // post: empty() & head() == 0 | !empty() & head() in *s 35 35 36 bool empty( Sequence(T) & s ) with( s ) { // 0 <=> *s contains no elements 37 return empty( (Collection &)s ); 38 } 39 40 bool listed( T * n ) { 41 return Next( (Colable *)n ) != 0; 42 } 43 44 T *& Next( T * n ) { 45 return (T *)Next( (Colable *)n ); 46 } 47 36 48 T *& Back( T * n ) { 37 49 return (T *)Back( (Seqable *)n ); 50 } 51 52 T * Root( Sequence(T) & s ) with( s ) { 53 return (T *)root; 38 54 } 39 55 … … 47 63 // Return a pointer to the last sequence element, without removing it. 48 64 T & tail( Sequence(T) & s ) with( s ) { 49 return root ? (T &)Back( head( s ) ) : *0p; // needs cast?65 return root ? (T &)Back( Root( s ) ) : *0p; // needs cast? 50 66 } // post: empty() & tail() == 0 | !empty() & tail() in *s 51 67 … … 55 71 if ( ! listed( n ) ) abort( "(Sequence &)%p.succ( %p ) : Node is not on a list.", &s, n ); 56 72 #endif // __CFA_DEBUG__ 57 return Next( n ) == head( s ) ? 0p : Next( n );73 return Next( n ) == Root( s ) ? 0p : Next( n ); 58 74 } // post: n == tail() & succ(n) == 0 | n != tail() & *succ(n) in *s 59 75 … … 63 79 if ( ! listed( n ) ) abort( "(Sequence &)%p.pred( %p ) : Node is not on a list.", &s, n ); 64 80 #endif // __CFA_DEBUG__ 65 return n == head( s ) ? 0p : Back( n );81 return n == Root( s ) ? 0p : Back( n ); 66 82 } // post: n == head() & head(n) == 0 | n != head() & *pred(n) in *s 67 83 … … 72 88 if ( listed( &n ) ) abort( "(Sequence &)%p.insertBef( %p, %p ) : Node is already on another list.", &s, n, &bef ); 73 89 #endif // __CFA_DEBUG__ 74 if ( &bef == head( s ) ) { // must change root90 if ( &bef == Root( s ) ) { // must change root 75 91 if ( root ) { 76 Next( &n ) = head( s );77 Back( &n ) = Back( head( s ) );92 Next( &n ) = Root( s ); 93 Back( &n ) = Back( Root( s ) ); 78 94 // inserted node must be consistent before it is seen 79 95 asm( "" : : : "memory" ); // prevent code movement across barrier 80 Back( head( s ) ) = &n;96 Back( Root( s ) ) = &n; 81 97 Next( Back( &n ) ) = &n; 82 98 } else { … … 88 104 root = &n; 89 105 } else { 90 if ( ! &bef ) &bef = head( s );106 if ( ! &bef ) &bef = Root( s ); 91 107 Next( &n ) = &bef; 92 108 Back( &n ) = Back( &bef ); … … 106 122 if ( ! &aft ) { // must change root 107 123 if ( root ) { 108 Next( &n ) = head( s );109 Back( &n ) = Back( head( s ) );124 Next( &n ) = Root( s ); 125 Back( &n ) = Back( Root( s ) ); 110 126 // inserted node must be consistent before it is seen 111 127 asm( "" : : : "memory" ); // prevent code movement across barrier 112 Back( head( s ) ) = &n;128 Back( Root( s ) ) = &n; 113 129 Next( Back( &n ) ) = &n; 114 130 } else { … … 133 149 if ( ! listed( &n ) ) abort( "(Sequence &)%p.remove( %p ) : Node is not on a list.", &s, &n ); 134 150 #endif // __CFA_DEBUG__ 135 if ( &n == head( s ) ) {136 if ( Next( head( s ) ) == head( s ) ) root = 0p;137 else root = Next( head(s ) );151 if ( &n == Root( s ) ) { 152 if ( Next( Root( s ) ) == Root( s ) ) root = 0p; 153 else root = Next( Root(s ) ); 138 154 } // if 139 155 Back( Next( &n ) ) = Back( &n ); … … 175 191 root = from.root; 176 192 } else { // "to" list not empty 177 T * toEnd = Back( head( s ) );178 T * fromEnd = Back( head( from ) );193 T * toEnd = Back( Root( s ) ); 194 T * fromEnd = Back( Root( from ) ); 179 195 Back( root ) = fromEnd; 180 Next( fromEnd ) = head( s );196 Next( fromEnd ) = Root( s ); 181 197 Back( from.root ) = toEnd; 182 Next( toEnd ) = head( from );198 Next( toEnd ) = Root( from ); 183 199 } // if 184 200 from.root = 0p; // mark "from" list empty … … 197 213 from.root = 0p; // mark "from" list empty 198 214 } else { 199 Back( head( from ) ) = Back( head( to ) ); // fix "from" list200 Next( Back( head( to ) ) ) = head( from );201 Next( n ) = head( to ); // fix "to" list202 Back( head( to ) ) = n;215 Back( Root( from ) ) = Back( Root( to ) ); // fix "from" list 216 Next( Back( Root( to ) ) ) = Root( from ); 217 Next( n ) = Root( to ); // fix "to" list 218 Back( Root( to ) ) = n; 203 219 } // if 204 220 transfer( s, to ); … … 215 231 216 232 inline { 217 void ?{}( SeqIter(T) & si ) with( si ) { 218 ((ColIter &)si){}; 233 // wrappers to make ColIter have T 234 T * Curr( SeqIter(T) & si ) with( si ) { 235 return (T *)curr; 236 } 237 238 void ?{}( SeqIter(T) & si ) with( si ) { 239 ((ColIter &) si){}; 219 240 seq = 0p; 220 241 } // post: elts = null. … … 249 270 250 271 inline { 272 // wrappers to make ColIter have T 273 T * Curr( SeqIterRev(T) & si ) with( si ) { 274 return (T *)curr; 275 } 276 251 277 void ?{}( SeqIterRev(T) & si ) with( si ) { 252 278 ((ColIter &) si){};
Note:
See TracChangeset
for help on using the changeset viewer.