Changes in libcfa/src/bits/containers.hfa [8b73526:768bd556]
- File:
-
- 1 edited
-
libcfa/src/bits/containers.hfa (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/containers.hfa
r8b73526 r768bd556 17 17 #include "bits/align.hfa" 18 18 #include "bits/defs.hfa" 19 #include <stdio.h> 19 20 20 //----------------------------------------------------------------------------- 21 21 // Array … … 36 36 #define __small_array_t(T) __small_array(T) 37 37 #else 38 #define __small_array_t(T) __small_array38 #define __small_array_t(T) struct __small_array 39 39 #endif 40 40 … … 146 146 static inline forall( dtype T | is_node(T) ) { 147 147 void ?{}( __queue(T) & this ) with( this ) { 148 (this.head){ 1p }; 149 (this.tail){ &this.head }; 150 verify(*this.tail == 1p); 148 head{ 0p }; 149 tail{ &head }; 151 150 } 152 151 153 152 void append( __queue(T) & this, T * val ) with( this ) { 154 verify(this.tail != 0p); 155 verify(*this.tail == 1p); 156 *this.tail = val; 157 this.tail = &get_next( *val ); 158 *this.tail = 1p; 159 } 160 161 T * peek( __queue(T) & this ) { 162 verify(*this.tail == 1p); 163 T * front = this.head; 164 if( front != 1p ) { 165 verify(*this.tail == 1p); 166 return front; 167 } 168 verify(*this.tail == 1p); 169 return 0p; 153 verify(tail != 0p); 154 *tail = val; 155 tail = &get_next( *val ); 170 156 } 171 157 172 158 T * pop_head( __queue(T) & this ) { 173 verify(*this.tail == 1p); 174 T * _head = this.head; 175 if( _head != 1p ) { 176 this.head = get_next( *_head ); 177 if( get_next( *_head ) == 1p ) { 159 T * head = this.head; 160 if( head ) { 161 this.head = get_next( *head ); 162 if( !get_next( *head ) ) { 178 163 this.tail = &this.head; 179 164 } 180 get_next( *_head ) = 0p; 181 verify(*this.tail == 1p); 182 verify( get_next(*_head) == 0p ); 183 return _head; 184 } 185 verify(*this.tail == 1p); 186 return 0p; 165 get_next( *head ) = 0p; 166 } 167 return head; 187 168 } 188 169 … … 193 174 (*it) = get_next( *val ); 194 175 195 if( t his.tail == &get_next( *val ) ) {196 t his.tail = it;176 if( tail == &get_next( *val ) ) { 177 tail = it; 197 178 } 198 179 199 180 get_next( *val ) = 0p; 200 181 201 verify( ( this.head == 1p) == (&this.head == this.tail) );202 verify( *t his.tail == 1p );182 verify( (head == 0p) == (&head == tail) ); 183 verify( *tail == 0p ); 203 184 return val; 204 185 } 205 186 206 187 int ?!=?( const __queue(T) & this, __attribute__((unused)) zero_t zero ) { 207 return this.head != 1p;188 return this.head != 0; 208 189 } 209 190 } … … 239 220 forall(dtype T ) 240 221 static inline [void] ?{}( __dllist(T) & this, * [T * & next, T * & prev] ( T & ) __get ) { 241 (this.head){ 0p };222 this.head{ 0p }; 242 223 this.__get = __get; 243 224 } … … 248 229 void push_front( __dllist(T) & this, T & node ) with( this ) { 249 230 verify(__get); 250 if ( this.head ) {251 __get( node ).next = this.head;252 __get( node ).prev = __get( * this.head ).prev;231 if ( head ) { 232 __get( node ).next = head; 233 __get( node ).prev = __get( *head ).prev; 253 234 // inserted node must be consistent before it is seen 254 235 // prevent code movement across barrier 255 236 asm( "" : : : "memory" ); 256 __get( * this.head ).prev = &node;237 __get( *head ).prev = &node; 257 238 T & _prev = *__get( node ).prev; 258 239 __get( _prev ).next = &node; … … 264 245 // prevent code movement across barrier 265 246 asm( "" : : : "memory" ); 266 this.head = &node;247 head = &node; 267 248 } 268 249 269 250 void remove( __dllist(T) & this, T & node ) with( this ) { 270 251 verify(__get); 271 if ( &node == this.head ) {272 if ( __get( * this.head ).next == this.head ) {273 this.head = 0p;252 if ( &node == head ) { 253 if ( __get( *head ).next == head ) { 254 head = 0p; 274 255 } else { 275 this.head = __get( *this.head ).next;256 head = __get( *head ).next; 276 257 } 277 258 } … … 285 266 return this.head != 0; 286 267 } 287 288 void move_to_front( __dllist(T) & src, __dllist(T) & dst, T & node ) {289 remove (src, node);290 push_front(dst, node);291 }292 268 } 293 269 #undef next
Note:
See TracChangeset
for help on using the changeset viewer.