Changeset 7d51ef8
- Timestamp:
- May 11, 2021, 9:52:18 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:
- 1e5cd9a, 67b421c
- Parents:
- 8d1ad36
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/containers/list2.hfa
r8d1ad36 r7d51ef8 18 18 #include <assert.h> 19 19 20 extern "C" { 21 void * memset ( void * ptr, int value, size_t num ); 22 } 23 24 trait embedded( tOuter &, tInner & ) { 25 tInner & ?`inner( tOuter & ); 20 forall( Decorator &, T & ) 21 struct tytagref { 22 inline T &; 26 23 }; 27 24 28 // embedded is reflexive 29 forall( tX & ) 30 static inline tX & ?`inner( tX & this ) { return this; } 25 trait embedded( tOuter &, tMid &, tInner & ) { 26 tytagref( tMid, tInner ) ?`inner( tOuter & ); 27 }; 28 29 // embedded is reflexive, with no info (void) as the type tag 30 forall (T &) 31 tytagref(void, T) ?`inner ( T & this ) { tytagref( void, T ) ret = {this}; return ret; } 31 32 32 33 // use this on every case of plan-9 inheritance, to make embedded a closure of plan-9 inheritance 33 #define P9_EMBEDDED( tOuter, tInner ) \ 34 static inline tInner & ?`inner( tOuter & this ) { return this; } 34 #define P9_EMBEDDED( derived, immedBase ) \ 35 forall( Tbase &, TdiscardPath & | { tytagref( TdiscardPath, Tbase ) ?`inner( immedBase & ); } ) \ 36 static inline tytagref(immedBase, Tbase) ?`inner( derived & this ) { \ 37 immedBase & ib = this; \ 38 Tbase & b = ib`inner; \ 39 tytagref(immedBase, Tbase) result = { b }; \ 40 return result; \ 41 } 42 43 #define EMBEDDED_VIA( OUTER, MID, INNER ) \ 44 (struct { tytagref(MID, INNER) ( * ?`inner ) ( OUTER & ); }){ ?`inner } 45 46 #define DLINK_VIA( TE, TLINK ) \ 47 EMBEDDED_VIA( TE, TLINK, dlink(TE) ) 35 48 36 49 … … 81 94 } 82 95 83 forall( tLinks & = tE ) { 84 85 struct dlist { 86 inline dlink(tE); 87 }; 88 89 struct diref { 90 inline tE &; 91 }; 92 } 93 94 forall( tLinks & = tE | embedded( tE, tLinks ) | embedded( tLinks, dlink(tE) ) ) { 96 forall( tLinks & = dlink(tE) ) 97 struct dlist { 98 inline dlink(tE); 99 }; 100 101 forall( tLinks & | embedded( tE, tLinks, dlink(tE) ) ) { 95 102 static inline tE * $get_list_origin_addr( dlist(tE, tLinks) & lst ) { 96 dlink(tE) & link_from_null = ( * (tE *) 0p )`inner `inner;103 dlink(tE) & link_from_null = ( * (tE *) 0p )`inner; 97 104 ptrdiff_t link_offset = (ptrdiff_t) & link_from_null; 98 105 size_t origin_addr = ((size_t) & lst) - link_offset; … … 105 112 ( ( dlink(tE) & ) this ){ listOrigin, listOrigin } ; 106 113 } 107 108 // redundant109 // void ?{}( diref(tE, tLinks) & this, tE & target ) {110 // tE && ref = this;111 // &ref = ⌖112 // }113 114 } 114 115 … … 116 117 117 118 118 forall( tE &, tLinks & | embedded( tE, tLinks ) | embedded( tLinks, dlink(tE) ) ) {119 120 static inline void insert_after( diref(tE, tLinks)list_pos, tE &to_insert) {119 forall( tE &, tLinks & | embedded( tE, tLinks, dlink(tE) ) ) { 120 121 static inline void insert_after(tE & list_pos, tE &to_insert) { 121 122 verify (&list_pos != 0p); 122 123 verify (&to_insert != 0p); 123 dlink(tE) & linkToInsert = to_insert`inner `inner;124 dlink(tE) & linkToInsert = to_insert`inner; 124 125 verify(linkToInsert.prev == 0p); 125 126 verify(linkToInsert.next == 0p); 126 127 tE & list_pos_raw = list_pos; 127 128 tE & list_pos_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & list_pos_raw ); 128 asm( "" : : : "memory" ); 129 tE & after_raw = * (list_pos_elem`inner`inner).next; 129 dlink(tE) & list_pos_links = list_pos_elem`inner; 130 asm( "" : : : "memory" ); 131 tE & after_raw = * list_pos_links.next; 130 132 tE & after_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & after_raw ); 131 133 linkToInsert.prev = & list_pos_raw; 132 134 linkToInsert.next = & after_raw; 133 (after_elem`inner`inner).prev = &to_insert; 134 (list_pos_elem`inner`inner).next = &to_insert; 135 asm( "" : : : "memory" ); 136 } 137 138 static inline void insert_before(diref(tE, tLinks) list_pos, tE &to_insert) { 135 dlink(tE) & afterLinks = after_elem`inner; 136 afterLinks.prev = &to_insert; 137 list_pos_links.next = &to_insert; 138 asm( "" : : : "memory" ); 139 } 140 141 static inline void insert_before(tE & list_pos, tE &to_insert) { 139 142 verify (&list_pos != 0p); 140 143 verify (&to_insert != 0p); 141 dlink(tE) & linkToInsert = to_insert`inner `inner;144 dlink(tE) & linkToInsert = to_insert`inner; 142 145 verify(linkToInsert.next == 0p); 143 146 verify(linkToInsert.prev == 0p); 144 147 tE & list_pos_raw = list_pos; 145 148 tE & list_pos_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & list_pos_raw ); 146 asm( "" : : : "memory" ); 147 tE & before_raw = * (list_pos_elem`inner`inner).prev; 149 dlink(tE) & list_pos_links = list_pos_elem`inner; 150 asm( "" : : : "memory" ); 151 tE & before_raw = * (list_pos_links).prev; 148 152 tE & before_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & before_raw ); 149 153 linkToInsert.next = & list_pos_raw; 150 154 linkToInsert.prev = & before_raw; 151 (before_elem`inner`inner).next = &to_insert; 152 (list_pos_elem`inner`inner).prev = &to_insert; 153 asm( "" : : : "memory" ); 154 } 155 156 static inline tE & remove(diref(tE, tLinks) list_pos) { 155 dlink(tE) & beforeLinks = before_elem`inner; 156 beforeLinks.next = &to_insert; 157 (list_pos_links).prev = &to_insert; 158 asm( "" : : : "memory" ); 159 } 160 161 static inline tE & remove(tE & list_pos) { 157 162 verify (&list_pos != 0p); 158 163 tE & list_pos_elem = list_pos; 159 164 verify( ! ORIGIN_TAG_QUERY((size_t) & list_pos_elem) ); 160 dlink(tE) & list_pos_links = list_pos_elem`inner `inner;165 dlink(tE) & list_pos_links = list_pos_elem`inner; 161 166 tE & before_raw = * list_pos_links.prev; 162 167 tE & before_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & before_raw ); 163 dlink(tE) & before_links = before_elem`inner `inner;168 dlink(tE) & before_links = before_elem`inner; 164 169 tE & after_raw = * list_pos_links.next; 165 170 tE & after_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & after_raw ); 166 dlink(tE) & after_links = after_elem`inner `inner;171 dlink(tE) & after_links = after_elem`inner; 167 172 before_links.next = &after_raw; 168 173 after_links.prev = &before_raw; … … 174 179 } 175 180 176 static inline diref(tE, tLinks)?`first( dlist(tE, tLinks) &lst ) {181 static inline tE & ?`first( dlist(tE, tLinks) &lst ) { 177 182 tE * firstPtr = lst.next; 178 183 if (ORIGIN_TAG_QUERY((size_t)firstPtr)) firstPtr = 0p; 179 diref(tE, tLinks) ret = { *firstPtr }; 180 return ret; 181 } 182 static inline diref(tE, tLinks) ?`last ( dlist(tE, tLinks) &lst ) { 184 return *firstPtr; 185 } 186 static inline tE & ?`last ( dlist(tE, tLinks) &lst ) { 183 187 tE * lastPtr = lst.prev; 184 188 if (ORIGIN_TAG_QUERY((size_t)lastPtr)) lastPtr = 0p; 185 diref(tE, tLinks) ret = { *lastPtr }; 186 return ret; 189 return *lastPtr; 187 190 } 188 191 … … 193 196 } 194 197 195 static inline int ?!=?( const diref(tE, tLinks) & list_pos, zero_t ) { 196 tE & list_pos_elem = list_pos; 197 if (ORIGIN_TAG_QUERY((size_t) & list_pos_elem)) return 0; 198 return & list_pos_elem != 0p; 199 } 200 201 static inline int DUMB_COMPARE( diref(tE, tLinks) list_pos, tE * elem ) { 202 tE & signifiedLhs = list_pos; 203 return &signifiedLhs == elem; 204 } 205 206 static inline diref(tE, tLinks) ?`from( tE & elem ) { 207 diref(tE, tLinks) ret = { elem }; 208 return ret; 209 } 210 211 static inline diref(tE, tLinks) ?`elems( dlist(tE, tLinks) & lst ) { 198 static inline tE & ?`elems( dlist(tE, tLinks) & lst ) { 212 199 tE * origin = $get_list_origin_addr( lst ); 213 diref(tE, tLinks) ret = { *origin }; 214 return ret; 215 } 216 217 static inline bool ?`moveNext( diref(tE, tLinks) & refx ) { 200 return *origin; 201 } 202 203 static inline bool ?`moveNext( tE && refx ) { 218 204 tE && ref_inner = refx; 219 205 tE & oldReferent = * (tE*) ORIGIN_TAG_CLEAR( (size_t) & ref_inner ); 220 &ref_inner = oldReferent`inner `inner.next;206 &ref_inner = oldReferent`inner.next; 221 207 return &ref_inner != 0p && 222 208 ! ORIGIN_TAG_QUERY( (size_t) & ref_inner ); 223 209 } 224 210 225 static inline bool ?`movePrev( diref(tE, tLinks)& refx ) {211 static inline bool ?`movePrev( tE && refx ) { 226 212 tE && ref_inner = refx; 227 213 tE & oldReferent = * (tE*) ORIGIN_TAG_CLEAR( (size_t) & ref_inner ); 228 &ref_inner = oldReferent`inner `inner.prev;214 &ref_inner = oldReferent`inner.prev; 229 215 return &ref_inner != 0p && 230 216 ! ORIGIN_TAG_QUERY( (size_t) & ref_inner ); 231 217 } 232 218 233 static inline bool ?`hasNext( diref(tE, tLinks) refx ) { 234 return refx`moveNext; 235 } 236 237 static inline bool ?`hasPrev( diref(tE, tLinks) refx ) { 238 return refx`movePrev; 239 } 240 241 static inline diref(tE, tLinks) ?`next( diref(tE, tLinks) refx ) { 242 if( refx`moveNext ) return refx; 243 tE && ref_inner = refx; 244 & ref_inner = 0p; 245 return refx; 246 } 247 248 static inline diref(tE, tLinks) ?`prev( diref(tE, tLinks) refx ) { 249 if( refx`movePrev ) return refx; 250 tE && ref_inner = refx; 251 & ref_inner = 0p; 252 return refx; 219 static inline bool ?`hasNext( tE & e ) { 220 return e`moveNext; 221 } 222 223 static inline bool ?`hasPrev( tE & e ) { 224 return e`movePrev; 225 } 226 227 static inline tE & ?`next( tE & e ) { 228 if( e`moveNext ) return e; 229 return * 0p; 230 } 231 232 static inline tE & ?`prev( tE & e ) { 233 if( e`movePrev ) return e; 234 return * 0p; 253 235 } 254 236 … … 262 244 263 245 static inline tE & try_pop_front( dlist(tE, tLinks) &lst ) { 264 diref(tE, tLinks)first_inlist = lst`first;246 tE & first_inlist = lst`first; 265 247 tE & first_item = first_inlist; 266 248 if (&first_item) remove(first_inlist); … … 269 251 270 252 static inline tE & try_pop_back( dlist(tE, tLinks) &lst ) { 271 diref(tE, tLinks)last_inlist = lst`last;253 tE & last_inlist = lst`last; 272 254 tE & last_item = last_inlist; 273 255 if (&last_item) remove(last_inlist); … … 282 264 tE & lagElem = *0p; 283 265 284 while ( diref(tE, tLinks)it = this`elems; it`moveNext ) {266 while ( tE & it = this`elems; it`moveNext ) { 285 267 if (& lagElem == 0p && &it != & this`first ) return false; 286 268 & lagElem = & it; … … 297 279 tE & lagElem = *0p; 298 280 299 while ( diref(tE, tLinks)it = this`elems; it`movePrev ) {281 while ( tE & it = this`elems; it`movePrev ) { 300 282 if (& lagElem == 0p && &it != & this`last ) return false; 301 283 & lagElem = & it; … … 314 296 } 315 297 316 forall( tE & | embedded( tE, dlink(tE) ) ) {317 static inline void insert_after(tE & list_pos, tE &to_insert ) {318 diref(tE, tE) list_pos_ref = list_pos`from;319 insert_after( list_pos_ref, to_insert );320 }321 static inline void insert_before(tE & list_pos, tE &to_insert ) {322 diref(tE, tE) list_pos_ref = list_pos`from;323 insert_before( list_pos_ref, to_insert );324 }325 static inline tE & remove(tE & list_pos ) {326 diref(tE, tE) list_pos_ref = list_pos`from;327 return remove( list_pos_ref );328 }329 static inline bool ?`moveNext( tE && ref ) {330 diref(tE, tE) & ref_dird = (diref(tE, tE) &) & ref;331 return ref_dird`moveNext;332 }333 static inline bool ?`movePrev( tE && ref ) {334 diref(tE, tE) & ref_dird = (diref(tE, tE) &) & ref;335 return ref_dird`movePrev;336 }337 static inline bool ?`hasNext( tE & ref ) {338 diref(tE, tE) ref_dird = { ref };339 return ref_dird`hasNext;340 }341 static inline bool ?`hasPrev( tE & ref ) {342 diref(tE, tE) ref_dird = { ref };343 return ref_dird`hasPrev;344 }345 static inline tE & ?`next( tE & ref ) {346 diref(tE, tE) ref_dird = { ref };347 diref(tE, tE) rslt = ref_dird`next;348 return rslt;349 }350 static inline tE & ?`prev( tE & ref ) {351 diref(tE, tE) ref_dird = { ref };352 diref(tE, tE) rslt = ref_dird`prev;353 return rslt;354 }355 } -
tests/list/dlist-insert-remove-2.cfa
r8d1ad36 r7d51ef8 55 55 //////////////////////////////////////////////////////////// 56 56 57 void printMyFredsFwd(diref(fred, fred.mine) f) { 57 void printMyFredsFwd(fred & f) { 58 with( DLINK_VIA( fred, fred.mine ) ) 58 59 do { 59 60 sout | f.adatum; … … 61 62 } 62 63 63 void printMyFredsRev(diref(fred, fred.mine) f) { 64 void printMyFredsRev(fred & f) { 65 with( DLINK_VIA( fred, fred.mine ) ) 64 66 do { 65 67 sout | f.adatum; … … 75 77 } 76 78 if (&f1) { 77 printMyFredsFwd(f1 `from); sout | '-';78 printMyFredsRev(f1 `from); sout | '-';79 printMyFredsFwd(f1); sout | '-'; 80 printMyFredsRev(f1); sout | '-'; 79 81 } else { 80 82 sout | '-'; sout | '-'; 81 83 } 82 84 if (&f2) { 83 printMyFredsFwd(f2 `from); sout | '-';84 printMyFredsRev(f2 `from); sout | '-';85 printMyFredsFwd(f2); sout | '-'; 86 printMyFredsRev(f2); sout | '-'; 85 87 } else { 86 88 sout | '-'; sout | '-'; … … 88 90 } 89 91 90 void printYourFredsFwd(diref(fred, fred.yours) f) { 92 void printYourFredsFwd(fred & f) { 93 with( DLINK_VIA( fred, fred.yours ) ) 91 94 do { 92 95 sout | f.adatum; … … 94 97 } 95 98 96 void printYourFredsRev(diref(fred, fred.yours) f) { 99 void printYourFredsRev(fred & f) { 100 with( DLINK_VIA( fred, fred.yours ) ) 97 101 do { 98 102 sout | f.adatum; … … 107 111 } 108 112 if (&f1) { 109 printYourFredsFwd(f1 `from); sout | '-';110 printYourFredsRev(f1 `from); sout | '-';113 printYourFredsFwd(f1); sout | '-'; 114 printYourFredsRev(f1); sout | '-'; 111 115 } else { 112 116 sout | '-'; sout | '-'; 113 117 } 114 118 if (&f2) { 115 printYourFredsFwd(f2 `from); sout | '-';116 printYourFredsRev(f2 `from); sout | '-';119 printYourFredsFwd(f2); sout | '-'; 120 printYourFredsRev(f2); sout | '-'; 117 121 } else { 118 122 sout | '-'; sout | '-'; … … 275 279 // All three tests exercise the case of creating an empty container and 276 280 // adding two items to it. 277 278 281 void test__insertfirst_two_on_empty__fred_mine() { 279 282 … … 317 320 printYourFreddies(f1, f2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 318 321 } 319 320 322 void test__insertfirst_two_on_empty__mary() { 321 323 … … 323 325 mary m2 = {0.5}; 324 326 325 dlist(mary , mary) lm;327 dlist(mary) lm; 326 328 327 329 verify(validate(lm)); … … 392 394 mary m2 = {0.5}; 393 395 394 dlist(mary , mary) lm;396 dlist(mary) lm; 395 397 396 398 verify(validate(lm)); … … 421 423 dlist(fred, fred.mine) lf; 422 424 423 assert( ! lf`first);424 assert( ! lf`last);425 assert( & lf`first == 0p ); 426 assert( & lf`last == 0p ); 425 427 426 428 insert_first(lf, f1); 427 429 428 assert( DUMB_COMPARE(lf`first, & f1));429 assert( DUMB_COMPARE(lf`last , & f1));430 assert( & lf`first == & f1 ); 431 assert( & lf`last == & f1 ); 430 432 431 433 verify(validate(lf)); 432 434 433 diref(fred, fred.mine) f1_mine = f1`from; 434 insert_after(f1_mine, f2); 435 with ( DLINK_VIA(fred, fred.mine) ) insert_after(f1, f2); 435 436 436 437 verify(validate(lf)); … … 439 440 printYourFreddies(f1, f2, 0); // 3.14; 3.14; 0.5; 0.5 (unmodified) 440 441 441 assert( DUMB_COMPARE(lf`first, & f1));442 assert( DUMB_COMPARE(lf`last , & f2));442 assert( & lf`first == & f1 ); 443 assert( & lf`last == & f2 ); 443 444 } 444 445 … … 450 451 dlist(fred, fred.yours) lf; 451 452 452 assert( ! lf`first);453 assert( ! lf`last);453 assert( & lf`first == 0p ); 454 assert( & lf`last == 0p ); 454 455 455 456 insert_first(lf, f1); 456 457 457 assert( DUMB_COMPARE(lf`first, & f1));458 assert( DUMB_COMPARE(lf`last , & f1));458 assert( & lf`first == & f1 ); 459 assert( & lf`last == & f1 ); 459 460 460 461 verify(validate(lf)); 461 462 462 diref(fred, fred.yours) f1_yours = f1`from; 463 insert_after(f1_yours, f2); 463 with ( DLINK_VIA(fred, fred.yours) ) insert_after(f1, f2); 464 464 465 465 verify(validate(lf)); … … 468 468 printYourFreddies(f1, f2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 469 469 470 assert( DUMB_COMPARE(lf`first, & f1));471 assert( DUMB_COMPARE(lf`last , & f2));470 assert( & lf`first == & f1 ); 471 assert( & lf`last == & f2 ); 472 472 } 473 473 … … 477 477 mary m2 = {0.5}; 478 478 479 dlist(mary , mary) lm;480 481 assert( ! lm`first);482 assert( ! lm`last);479 dlist(mary) lm; 480 481 assert( & lm`first == 0p ); 482 assert( & lm`last == 0p ); 483 483 484 484 insert_first(lm, m1); 485 485 486 assert( DUMB_COMPARE(lm`first, & m1));487 assert( DUMB_COMPARE(lm`last , & m1));486 assert( & lm`first == & m1 ); 487 assert( & lm`last == & m1 ); 488 488 489 489 verify(validate(lm)); … … 495 495 printMariatheotokos(m1, m2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 496 496 497 assert( DUMB_COMPARE(lm`first, & m1));498 assert( DUMB_COMPARE(lm`last , & m2));497 assert( & lm`first == & m1 ); 498 assert( & lm`last == & m2 ); 499 499 } 500 500 … … 516 516 dlist(fred, fred.mine) lf; 517 517 518 assert( ! lf`first);519 assert( ! lf`last);518 assert( & lf`first == 0p ); 519 assert( & lf`last == 0p ); 520 520 521 521 insert_last(lf, f2); 522 522 523 assert( DUMB_COMPARE(lf`first, & f2));524 assert( DUMB_COMPARE(lf`last , & f2));523 assert( & lf`first == & f2 ); 524 assert( & lf`last == & f2 ); 525 525 526 526 verify(validate(lf)); 527 527 528 diref(fred, fred.mine) f2_mine = f2`from; 529 insert_before(f2_mine, f1); 528 with ( DLINK_VIA(fred, fred.mine) ) insert_before(f2, f1); 530 529 531 530 verify(validate(lf)); … … 534 533 printYourFreddies(f1, f2, 0); // 3.14; 3.14; 0.5; 0.5 (unmodified) 535 534 536 assert( DUMB_COMPARE(lf`first, & f1));537 assert( DUMB_COMPARE(lf`last , & f2));535 assert( & lf`first == & f1 ); 536 assert( & lf`last == & f2 ); 538 537 } 539 538 … … 545 544 dlist(fred, fred.yours) lf; 546 545 547 assert( ! lf`first);548 assert( ! lf`last);546 assert( & lf`first == 0p ); 547 assert( & lf`last == 0p ); 549 548 550 549 insert_last(lf, f2); 551 550 552 assert( DUMB_COMPARE(lf`first, & f2));553 assert( DUMB_COMPARE(lf`last , & f2));551 assert( & lf`first == & f2 ); 552 assert( & lf`last == & f2 ); 554 553 555 554 verify(validate(lf)); 556 555 557 diref(fred, fred.yours) f2_yours = f2`from; 558 insert_before(f2_yours, f1); 556 with ( DLINK_VIA(fred, fred.yours) )insert_before(f2, f1); 559 557 560 558 verify(validate(lf)); … … 563 561 printYourFreddies(f1, f2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 564 562 565 assert( DUMB_COMPARE(lf`first, & f1));566 assert( DUMB_COMPARE(lf`last , & f2));563 assert( & lf`first == & f1 ); 564 assert( & lf`last == & f2 ); 567 565 } 568 566 … … 572 570 mary m2 = {0.5}; 573 571 574 dlist(mary , mary) lm;575 576 assert( ! lm`first);577 assert( ! lm`last);572 dlist(mary) lm; 573 574 assert( & lm`first == 0p ); 575 assert( & lm`last == 0p ); 578 576 579 577 insert_last(lm, m2); 580 578 581 assert( DUMB_COMPARE(lm`first, & m2));582 assert( DUMB_COMPARE(lm`last , & m2));579 assert( & lm`first == & m2 ); 580 assert( & lm`last == & m2 ); 583 581 584 582 verify(validate(lm)); … … 590 588 printMariatheotokos(m1, m2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 591 589 592 assert(DUMB_COMPARE(lm`first, & m1)); 593 assert(DUMB_COMPARE(lm`last , & m2)); 594 } 595 590 assert( & lm`first == & m1 ); 591 assert( & lm`last == & m2 ); 592 } 596 593 #if 0 597 594 … … 900 897 verify(validate(flm)); 901 898 902 diref(fred, fred.mine) f1_mine = f1`from; 903 remove(f1_mine); 899 with( DLINK_VIA(fred, fred.mine) ) remove(f1); 904 900 905 901 verify(validate(fly)); … … 916 912 // assert(f1.$links_mine.prev.is_terminator == false); 917 913 } 914 918 915 919 916 void test__remove_at_head__fred_yours() { … … 939 936 verify(validate(flm)); 940 937 941 diref(fred, fred.yours) f1_yours = f1`from; 942 remove(f1_yours); 938 with( DLINK_VIA(fred, fred.yours) ) remove(f1); 943 939 944 940 verify(validate(fly)); … … 962 958 mary m3 = {3.7}; 963 959 964 dlist(mary , mary) ml;960 dlist(mary) ml; 965 961 insert_last(ml, m1); 966 962 insert_last(ml, m2); … … 1017 1013 verify(validate(flm)); 1018 1014 1019 diref(fred, fred.mine) f3_mine = f3`from; 1020 remove(f3_mine); 1015 with( DLINK_VIA(fred, fred.mine) ) remove(f3); 1021 1016 1022 1017 verify(validate(fly)); … … 1056 1051 verify(validate(flm)); 1057 1052 1058 diref(fred, fred.yours) f3_yours = f3`from; 1059 remove(f3_yours); 1053 with( DLINK_VIA(fred, fred.yours) ) remove(f3); 1060 1054 1061 1055 verify(validate(fly)); … … 1079 1073 mary m3 = {3.7}; 1080 1074 1081 dlist(mary , mary) ml;1075 dlist(mary) ml; 1082 1076 insert_last(ml, m1); 1083 1077 insert_last(ml, m2); … … 1128 1122 verify(validate(flm)); 1129 1123 1130 diref(fred, fred.mine) f_mine = f`from; 1131 remove(f_mine); 1132 1133 verify(validate(fly)); 1134 verify(validate(flm)); 1135 1136 assert(! flm`first); 1137 assert(! flm`last); 1124 with( DLINK_VIA(fred, fred.mine) ) remove(f); 1125 1126 verify(validate(fly)); 1127 verify(validate(flm)); 1128 1129 assert( & flm`first == 0p ); 1130 assert( & flm`last == 0p ); 1138 1131 1139 1132 printYourFreddies(fly`first, fly`last, 0); // 0.7; 0.7; 0.7; 0.7 (unmodified) … … 1168 1161 verify(validate(flm)); 1169 1162 1170 diref(fred, fred.yours) f_yours = f`from; 1171 remove(f_yours); 1172 1173 verify(validate(fly)); 1174 verify(validate(flm)); 1175 1176 assert(! fly`first); 1177 assert(! fly`last); 1163 with( DLINK_VIA(fred, fred.yours) ) remove(f); 1164 1165 verify(validate(fly)); 1166 verify(validate(flm)); 1167 1168 assert( & fly`first == 0p ); 1169 assert( & fly`last == 0p ); 1178 1170 1179 1171 printYourFreddies(flm`first, flm`last, 0); // 0.7; 0.7; 0.7; 0.7 (unmodified) … … 1196 1188 mary m = {0.7}; 1197 1189 1198 dlist(mary , mary) ml;1190 dlist(mary) ml; 1199 1191 insert_last(ml, m); 1200 1192 … … 1207 1199 verify(validate(ml)); 1208 1200 1209 assert( ! ml`first);1210 assert( ! ml`last);1201 assert( & ml`first == 0p ); 1202 assert( & ml`last == 0p ); 1211 1203 1212 1204 // observe f is solo in mine (now unlisted); in yours, it was just traversed … … 1256 1248 verify(validate(flm)); 1257 1249 1258 fred & popped = remove(flm`first);1250 fred & popped = try_pop_front(flm); 1259 1251 1260 1252 verify(validate(fly)); … … 1292 1284 verify(validate(flm)); 1293 1285 1294 fred & popped = remove(fly`first);1286 fred & popped = try_pop_front(fly); 1295 1287 1296 1288 verify(validate(fly)); … … 1312 1304 mary m3 = {3.7}; 1313 1305 1314 dlist(mary , mary) ml;1306 dlist(mary) ml; 1315 1307 insert_last(ml, m1); 1316 1308 insert_last(ml, m2); … … 1321 1313 verify(validate(ml)); 1322 1314 1323 mary & popped = remove(ml`first);1315 mary & popped = try_pop_front(ml); 1324 1316 1325 1317 verify(validate(ml)); … … 1355 1347 verify(validate(flm)); 1356 1348 1357 fred & popped = remove(flm`last);1349 fred & popped = try_pop_back(flm); 1358 1350 1359 1351 verify(validate(fly)); … … 1391 1383 verify(validate(flm)); 1392 1384 1393 fred & popped = remove(fly`last);1385 fred & popped = try_pop_back(fly); 1394 1386 1395 1387 verify(validate(fly)); … … 1411 1403 mary m3 = {3.7}; 1412 1404 1413 dlist(mary , mary) ml;1405 dlist(mary) ml; 1414 1406 insert_last(ml, m1); 1415 1407 insert_last(ml, m2); … … 1420 1412 verify(validate(ml)); 1421 1413 1422 mary & popped = remove(ml`last);1414 mary & popped = try_pop_back(ml); 1423 1415 1424 1416 verify(validate(ml)); … … 1431 1423 assert( &popped == &m3 ); 1432 1424 } 1433 1434 1425 1435 1426 //////////////////////////////////////////////////////////// … … 1450 1441 mary m3 = {3.7}; 1451 1442 1452 dlist(mary , mary) ml;assert( ml`isEmpty);1443 dlist(mary) ml; assert( ml`isEmpty); 1453 1444 1454 1445 insert_last(ml, m1); assert(!ml`isEmpty); … … 1486 1477 mary m3 = {3.7}; 1487 1478 1488 dlist(mary , mary) ml;1479 dlist(mary) ml; 1489 1480 1490 1481 mary &m1r = *0p; … … 1588 1579 mary m1 = {1.7}; 1589 1580 1590 dlist(mary , mary) ml;1581 dlist(mary) ml; 1591 1582 mary & mlorigin = ml`elems; 1592 1583
Note: See TracChangeset
for help on using the changeset viewer.