Changeset a3a76ea for libcfa/src/bits/sequence.hfa
- Timestamp:
- Dec 27, 2020, 5:55:50 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 62a7cc0
- Parents:
- 83c7e3c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/sequence.hfa
r83c7e3c ra3a76ea 77 77 78 78 // Insert *n into the sequence before *bef, or at the end if bef == 0. 79 voidinsertBef( Sequence(T) & s, T & n, T & bef ) with( s ) { // pre: !n->listed() & *bef in *s79 T & 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; 107 108 } // post: n->listed() & *n in *s & succ(n) == bef 108 109 109 110 110 111 // Insert *n into the sequence after *aft, or at the beginning if aft == 0. 111 voidinsertAft( Sequence(T) & s, T & aft, T & n ) with( s ) { // pre: !n->listed() & *aft in *s112 T & insertAft( Sequence(T) & s, T & aft, T & n ) with( s ) { // pre: !n->listed() & *aft in *s 112 113 #ifdef __CFA_DEBUG__ 113 114 if ( listed( &n ) ) abort( "(Sequence &)%p.insertAft( %p, %p ) : Node is already on another list.", &s, &aft, &n ); … … 135 136 Next( &aft ) = &n; 136 137 } // if 138 return n; 137 139 } // post: n->listed() & *n in *s & succ(n) == bef 138 140 139 141 // pre: n->listed() & *n in *s 140 voidremove( Sequence(T) & s, T & n ) with( s ) { // O(1)142 T & remove( Sequence(T) & s, T & n ) with( s ) { // O(1) 141 143 #ifdef __CFA_DEBUG__ 142 144 if ( ! listed( &n ) ) abort( "(Sequence &)%p.remove( %p ) : Node is not on a list.", &s, &n ); … … 149 151 Next( Back( &n ) ) = Next( &n ); 150 152 Next( &n ) = Back( &n ) = 0p; 153 return n; 151 154 } // post: !n->listed(). 152 155 153 156 // Add an element to the head of the sequence. 154 void addHead( Sequence(T) & s, T & n ) {// pre: !n->listed(); post: n->listed() & head() == n155 insertAft( s, *0p, n );157 T & addHead( Sequence(T) & s, T & n ) { // pre: !n->listed(); post: n->listed() & head() == n 158 return insertAft( s, *0p, n ); 156 159 } 157 160 // Add an element to the tail of the sequence. 158 void addTail( Sequence(T) & s, T & n ) {// pre: !n->listed(); post: n->listed() & head() == n159 insertBef( s, n, *0p );161 T & addTail( Sequence(T) & s, T & n ) { // pre: !n->listed(); post: n->listed() & head() == n 162 return insertBef( s, n, *0p ); 160 163 } 161 164 // Add an element to the tail of the sequence. 162 void add( Sequence(T) & s, T & n ) {// pre: !n->listed(); post: n->listed() & head() == n163 addTail( s, n );165 T & add( Sequence(T) & s, T & n ) { // pre: !n->listed(); post: n->listed() & head() == n 166 return addTail( s, n ); 164 167 } 165 168 // Remove and return the head element in the sequence.
Note: See TracChangeset
for help on using the changeset viewer.