Changes in libcfa/src/bits/sequence.hfa [a3a76ea:19de7864]
- File:
-
- 1 edited
-
libcfa/src/bits/sequence.hfa (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/sequence.hfa
ra3a76ea r19de7864 77 77 78 78 // Insert *n into the sequence before *bef, or at the end if bef == 0. 79 T &insertBef( Sequence(T) & s, T & n, T & bef ) with( s ) { // pre: !n->listed() & *bef in *s79 void insertBef( Sequence(T) & s, T & n, T & bef ) with( s ) { // pre: !n->listed() & *bef in *s 80 80 #ifdef __CFA_DEBUG__ 81 81 if ( listed( &n ) ) abort( "(Sequence &)%p.insertBef( %p, %p ) : Node is already on another list.", &s, n, &bef ); … … 105 105 Next( Back( &n ) ) = &n; 106 106 } // if 107 return n;108 107 } // post: n->listed() & *n in *s & succ(n) == bef 109 108 110 109 111 110 // Insert *n into the sequence after *aft, or at the beginning if aft == 0. 112 T &insertAft( Sequence(T) & s, T & aft, T & n ) with( s ) { // pre: !n->listed() & *aft in *s111 void insertAft( Sequence(T) & s, T & aft, T & n ) with( s ) { // pre: !n->listed() & *aft in *s 113 112 #ifdef __CFA_DEBUG__ 114 113 if ( listed( &n ) ) abort( "(Sequence &)%p.insertAft( %p, %p ) : Node is already on another list.", &s, &aft, &n ); … … 136 135 Next( &aft ) = &n; 137 136 } // if 138 return n;139 137 } // post: n->listed() & *n in *s & succ(n) == bef 140 138 141 139 // pre: n->listed() & *n in *s 142 T &remove( Sequence(T) & s, T & n ) with( s ) { // O(1)140 void remove( Sequence(T) & s, T & n ) with( s ) { // O(1) 143 141 #ifdef __CFA_DEBUG__ 144 142 if ( ! listed( &n ) ) abort( "(Sequence &)%p.remove( %p ) : Node is not on a list.", &s, &n ); … … 151 149 Next( Back( &n ) ) = Next( &n ); 152 150 Next( &n ) = Back( &n ) = 0p; 153 return n;154 151 } // post: !n->listed(). 155 152 156 153 // Add an element to the head of the sequence. 157 T & addHead( Sequence(T) & s, T & n ) {// pre: !n->listed(); post: n->listed() & head() == n158 returninsertAft( s, *0p, n );154 void addHead( Sequence(T) & s, T & n ) { // pre: !n->listed(); post: n->listed() & head() == n 155 insertAft( s, *0p, n ); 159 156 } 160 157 // Add an element to the tail of the sequence. 161 T & addTail( Sequence(T) & s, T & n ) {// pre: !n->listed(); post: n->listed() & head() == n162 returninsertBef( s, n, *0p );158 void addTail( Sequence(T) & s, T & n ) { // pre: !n->listed(); post: n->listed() & head() == n 159 insertBef( s, n, *0p ); 163 160 } 164 161 // Add an element to the tail of the sequence. 165 T & add( Sequence(T) & s, T & n ) {// pre: !n->listed(); post: n->listed() & head() == n166 returnaddTail( s, n );162 void add( Sequence(T) & s, T & n ) { // pre: !n->listed(); post: n->listed() & head() == n 163 addTail( s, n ); 167 164 } 168 165 // Remove and return the head element in the sequence.
Note:
See TracChangeset
for help on using the changeset viewer.