Changeset 58870e6b for libcfa/src/bits/queue.hfa
- Timestamp:
- Dec 7, 2020, 3:51:50 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- d6089ad
- Parents:
- e91a255
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/queue.hfa
re91a255 r58870e6b 31 31 if ( ! listed( n ) ) abort( "(Queue &)%p.succ( %p ) : Node is not on a list.", &q, n ); 32 32 #endif // __CFA_DEBUG__ 33 return (Next( *n ) == n) ? 0p : Next( *n );33 return (Next( n ) == n) ? 0p : Next( n ); 34 34 } // post: n == tail() & succ(n) == 0 | n != tail() & *succ(n) in *q 35 35 … … 39 39 #endif // __CFA_DEBUG__ 40 40 if ( last ) { 41 Next( n ) = &head( q );41 Next( &n ) = &head( q ); 42 42 q.root = &n; 43 43 } else { 44 44 root = last = &n; 45 Next( n ) = &n;// last node points to itself45 Next( &n ) = &n; // last node points to itself 46 46 } 47 47 } … … 51 51 if ( listed( &n ) ) abort( "(Queue &)%p.addTail( %p ) : Node is already on another list.", &q, &n ); 52 52 #endif // __CFA_DEBUG__ 53 if ( last ) Next( *last ) = &n;53 if ( last ) Next( last ) = &n; 54 54 else root = &n; 55 55 last = &n; 56 Next( n ) = &n;// last node points to itself56 Next( &n ) = &n; // last node points to itself 57 57 } 58 58 … … 64 64 T & t = head( q ); 65 65 if ( root ) { 66 root = Next( *root );66 root = Next( root ); 67 67 if ( &head( q ) == &t ) { 68 68 root = last = 0p; // only one element 69 69 } 70 Next( t ) = 0p;70 Next( &t ) = 0p; 71 71 } 72 72 return t; … … 81 81 if ( ! listed( (Colable &)n ) ) abort( "(Queue &)%p.remove( %p ) : Node is not on a list.", &q, &n ); 82 82 #endif // __CFA_DEBUG__ 83 T & prev = *0p;84 T & curr = *(T *)root;83 T * prev = 0p; 84 T * curr = (T *)root; 85 85 for ( ;; ) { 86 if ( &n == &curr ) { // found => remove86 if ( &n == curr ) { // found => remove 87 87 if ( (T *)root == &n ) { 88 88 dropHead( q ); 89 89 } else if ( last == &n ) { 90 last = &prev;91 Next( *last ) = last;90 last = prev; 91 Next( last ) = last; 92 92 } else { 93 93 Next( prev ) = Next( curr ); 94 94 } 95 Next( n ) = 0p;95 Next( &n ) = 0p; 96 96 break; 97 97 } 98 98 // not found => error 99 99 #ifdef __CFA_DEBUG__ 100 if ( &curr == last ) abort( "(Queue &)%p.remove( %p ) : Node is not in list.", &q, &n );100 if ( curr == last ) abort( "(Queue &)%p.remove( %p ) : Node is not in list.", &q, &n ); 101 101 #endif // __CFA_DEBUG__ 102 &prev = &curr;103 &curr = Next( curr );102 prev = curr; 103 curr = Next( curr ); 104 104 } 105 105 } // post: ! listed( n ) … … 116 116 root = from.root; 117 117 } else { // "to" list not empty 118 Next( *last ) = &head( from );118 Next( last ) = &head( from ); 119 119 } 120 120 last = from.last; … … 131 131 to.root = from.root; // start of "to" list 132 132 to.last = &n; // end of "to" list 133 from.root = Next( n ); // start of "from" list133 from.root = Next( &n ); // start of "from" list 134 134 if ( &n == &head( from ) ) { // last node in list ? 135 135 from.root = from.last = 0p; // mark "from" list empty 136 136 } else { 137 Next( n ) = &n;// fix end of "to" list137 Next( &n ) = &n; // fix end of "to" list 138 138 } 139 139 transfer( q, to ); … … 169 169 if ( curr ) { 170 170 &tp = Curr( qi ); 171 T * n = Next( *Curr( qi ) );171 T * n = Next( Curr( qi ) ); 172 172 curr = (n == Curr( qi ) ) ? 0p : n; 173 173 } else &tp = 0p;
Note: See TracChangeset
for help on using the changeset viewer.