Changeset a3a76ea
 Timestamp:
 Dec 27, 2020, 5:55:50 PM (21 months ago)
 Branches:
 armeh, enum, forallpointerdecay, jacob/cs343translation, master, newastuniqueexpr, pthreademulation, qualifiedEnum
 Children:
 62a7cc0
 Parents:
 83c7e3c
 Location:
 libcfa/src/bits
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

libcfa/src/bits/queue.hfa
r83c7e3c ra3a76ea 34 34 } // post: n == tail() & succ(n) == 0  n != tail() & *succ(n) in *q 35 35 36 voidaddHead( Queue(T) & q, T & n ) with( q ) {36 T & addHead( Queue(T) & q, T & n ) with( q ) { 37 37 #ifdef __CFA_DEBUG__ 38 38 if ( listed( &n ) ) abort( "(Queue &)%p.addHead( %p ) : Node is already on another list.", &q, &n ); … … 45 45 Next( &n ) = &n; // last node points to itself 46 46 } 47 return n; 47 48 } 48 49 49 voidaddTail( Queue(T) & q, T & n ) with( q ) {50 T & addTail( Queue(T) & q, T & n ) with( q ) { 50 51 #ifdef __CFA_DEBUG__ 51 52 if ( listed( &n ) ) abort( "(Queue &)%p.addTail( %p ) : Node is already on another list.", &q, &n ); … … 55 56 last = &n; 56 57 Next( &n ) = &n; // last node points to itself 58 return n; 57 59 } 58 60 59 voidadd( Queue(T) & q, T & n ) with( q ) {60 addTail( q, n );61 T & add( Queue(T) & q, T & n ) with( q ) { 62 return addTail( q, n ); 61 63 } 62 64 … … 77 79 } 78 80 79 voidremove( Queue(T) & q, T & n ) with( q ) { // O(n)81 T & remove( Queue(T) & q, T & n ) with( q ) { // O(n) 80 82 #ifdef __CFA_DEBUG__ 81 83 if ( ! listed( (Colable &)n ) ) abort( "(Queue &)%p.remove( %p ) : Node is not on a list.", &q, &n ); … … 103 105 curr = Next( curr ); 104 106 } 107 return n; 105 108 } // post: ! listed( n ) 106 109 
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. 
libcfa/src/bits/stack.hfa
r83c7e3c ra3a76ea 25 25 } 26 26 27 voidaddHead( Stack(T) & s, T & n ) with( s ) {27 T & addHead( Stack(T) & s, T & n ) with( s ) { 28 28 #ifdef __CFA_DEBUG__ 29 29 if ( listed( (Colable &)(n) ) ) abort( "(Stack &)%p.addHead( %p ) : Node is already on another list.", &s, n ); … … 31 31 Next( &n ) = &head( s ) ? &head( s ) : &n; 32 32 root = &n; 33 return n; 33 34 } 34 35 35 voidadd( Stack(T) & s, T & n ) with( s ) {36 addHead( s, n );36 T & add( Stack(T) & s, T & n ) with( s ) { 37 return addHead( s, n ); 37 38 } 38 39 39 voidpush( Stack(T) & s, T & n ) with( s ) {40 addHead( s, n );40 T & push( Stack(T) & s, T & n ) with( s ) { 41 return addHead( s, n ); 41 42 } 42 43
Note: See TracChangeset
for help on using the changeset viewer.