@@ -49,8 +49,8 @@ impl <K: Eq Ord, V: Eq> TreeMap<K, V>: Eq {
49
49
let mut y = other. iter ( ) ;
50
50
for self . len( ) . times {
51
51
unsafe { // unsafe as a purity workaround
52
- x = x . next ( ) ;
53
- y = y . next ( ) ;
52
+ map_next ( & mut x ) ;
53
+ map_next ( & mut y ) ;
54
54
// FIXME: #4492 (ICE), x.get() == y.get()
55
55
let ( x1, x2) = x. get ( ) . unwrap ( ) ;
56
56
let ( y1, y2) = y. get ( ) . unwrap ( ) ;
@@ -74,8 +74,8 @@ pure fn lt<K: Ord, V>(a: &TreeMap<K, V>, b: &TreeMap<K, V>) -> bool {
74
74
let ( a_len, b_len) = ( a. len ( ) , b. len ( ) ) ;
75
75
for uint:: min( a_len, b_len) . times {
76
76
unsafe { // purity workaround
77
- x = x . next ( ) ;
78
- y = y . next ( ) ;
77
+ map_next ( & mut x ) ;
78
+ map_next ( & mut y ) ;
79
79
let ( key_a, _) = x. get( ) . unwrap( ) ;
80
80
let ( key_b, _) = y. get( ) . unwrap( ) ;
81
81
if * key_a < * key_b { return true ; }
@@ -210,32 +210,30 @@ impl <K: Ord, V> TreeMapIterator<K, V> {
210
210
// Returns the current node, or None if this iterator is at the end.
211
211
fn get ( & const self ) -> Option < ( & self /K , & self /V ) > {
212
212
match self . current {
213
- Some ( res) => Some ( ( & res. key , & res. value ) ) ,
214
- None => None
213
+ Some ( res) => Some ( ( & res. key , & res. value ) ) ,
214
+ None => None
215
215
}
216
216
}
217
+ }
217
218
218
- /// Advance the iterator to the next node (in order). If this iterator
219
- /// is finished, does nothing.
220
- fn next ( self ) -> TreeMapIterator /& self <K , V > {
221
- let mut this = self ;
222
- while !this. stack. is_empty ( ) || this. node. is_some ( ) {
223
- match * this. node {
224
- Some ( ref x) => {
225
- this. stack . push ( x) ;
226
- this. node = & x. left ;
227
- }
228
- None => {
229
- let res = this. stack . pop ( ) ;
230
- this. node = & res. right ;
231
- this. current = Some ( res) ;
232
- return this;
233
- }
234
- }
219
+ /// Advance the iterator to the next node (in order). If this iterator
220
+ /// is finished, does nothing.
221
+ fn map_next < K : Ord , V > ( iter : & mut TreeMapIterator /& a < K , V > ) {
222
+ while !iter. stack . is_empty ( ) || iter. node . is_some ( ) {
223
+ match * iter. node {
224
+ Some ( ref x) => {
225
+ iter. stack . push ( x) ;
226
+ iter. node = & x. left ;
227
+ }
228
+ None => {
229
+ let res = iter. stack . pop ( ) ;
230
+ iter. node = & res. right ;
231
+ iter. current = Some ( res) ;
232
+ return ;
233
+ }
235
234
}
236
- this. current = None ;
237
- return this;
238
235
}
236
+ iter. current = None ;
239
237
}
240
238
241
239
pub struct TreeSet < T > {
@@ -297,18 +295,18 @@ impl <T: Ord> TreeSet<T>: Set<T> {
297
295
let mut x = self . iter ( ) ;
298
296
let mut y = other. iter ( ) ;
299
297
unsafe { // purity workaround
300
- x = x . next ( ) ;
301
- y = y . next ( ) ;
298
+ set_next ( & mut x ) ;
299
+ set_next ( & mut y ) ;
302
300
let mut a = x. get ( ) ;
303
301
let mut b = y. get ( ) ;
304
302
while a. is_some ( ) && b. is_some ( ) {
305
303
let a1 = a. unwrap ( ) ;
306
304
let b1 = b. unwrap ( ) ;
307
305
if a1 < b1 {
308
- x = x . next ( ) ;
306
+ set_next ( & mut x ) ;
309
307
a = x. get ( ) ;
310
308
} else if b1 < a1 {
311
- y = y . next ( ) ;
309
+ set_next ( & mut y ) ;
312
310
b = y. get ( ) ;
313
311
} else {
314
312
return false ;
@@ -328,8 +326,8 @@ impl <T: Ord> TreeSet<T>: Set<T> {
328
326
let mut x = self . iter ( ) ;
329
327
let mut y = other. iter ( ) ;
330
328
unsafe { // purity workaround
331
- x = x . next ( ) ;
332
- y = y . next ( ) ;
329
+ set_next ( & mut x ) ;
330
+ set_next ( & mut y ) ;
333
331
let mut a = x. get ( ) ;
334
332
let mut b = y. get ( ) ;
335
333
while b. is_some ( ) {
@@ -345,10 +343,10 @@ impl <T: Ord> TreeSet<T>: Set<T> {
345
343
}
346
344
347
345
if !( a1 < b1) {
348
- y = y . next ( ) ;
346
+ set_next ( & mut y ) ;
349
347
b = y. get ( ) ;
350
348
}
351
- x = x . next ( ) ;
349
+ set_next ( & mut x ) ;
352
350
a = x. get ( ) ;
353
351
}
354
352
}
@@ -361,15 +359,15 @@ impl <T: Ord> TreeSet<T>: Set<T> {
361
359
let mut y = other. iter ( ) ;
362
360
363
361
unsafe { // purity workaround
364
- x = x . next ( ) ;
365
- y = y . next ( ) ;
362
+ set_next ( & mut x ) ;
363
+ set_next ( & mut y ) ;
366
364
let mut a = x. get ( ) ;
367
365
let mut b = y. get ( ) ;
368
366
369
367
while a. is_some ( ) {
370
368
if b. is_none ( ) {
371
369
return do a. while_some ( ) |a1| {
372
- if f ( a1) { x = x . next ( ) ; x. get ( ) } else { None }
370
+ if f ( a1) { set_next ( & mut x ) ; x. get ( ) } else { None }
373
371
}
374
372
}
375
373
@@ -378,11 +376,11 @@ impl <T: Ord> TreeSet<T>: Set<T> {
378
376
379
377
if a1 < b1 {
380
378
if !f ( a1) { return }
381
- x = x . next ( ) ;
379
+ set_next ( & mut x ) ;
382
380
a = x. get ( ) ;
383
381
} else {
384
- if !( b1 < a1) { x = x . next ( ) ; a = x. get ( ) }
385
- y = y . next ( ) ;
382
+ if !( b1 < a1) { set_next ( & mut x ) ; a = x. get ( ) }
383
+ set_next ( & mut y ) ;
386
384
b = y. get ( ) ;
387
385
}
388
386
}
@@ -396,15 +394,15 @@ impl <T: Ord> TreeSet<T>: Set<T> {
396
394
let mut y = other. iter ( ) ;
397
395
398
396
unsafe { // purity workaround
399
- x = x . next ( ) ;
400
- y = y . next ( ) ;
397
+ set_next ( & mut x ) ;
398
+ set_next ( & mut y ) ;
401
399
let mut a = x. get ( ) ;
402
400
let mut b = y. get ( ) ;
403
401
404
402
while a. is_some ( ) {
405
403
if b. is_none ( ) {
406
404
return do a. while_some ( ) |a1| {
407
- if f ( a1) { x . next ( ) ; x. get ( ) } else { None }
405
+ if f ( a1) { set_next ( & mut x ) ; x. get ( ) } else { None }
408
406
}
409
407
}
410
408
@@ -413,21 +411,21 @@ impl <T: Ord> TreeSet<T>: Set<T> {
413
411
414
412
if a1 < b1 {
415
413
if !f ( a1) { return }
416
- x = x . next ( ) ;
414
+ set_next ( & mut x ) ;
417
415
a = x. get ( ) ;
418
416
} else {
419
417
if b1 < a1 {
420
418
if !f ( b1) { return }
421
419
} else {
422
- x = x . next ( ) ;
420
+ set_next ( & mut x ) ;
423
421
a = x. get ( ) ;
424
422
}
425
- y = y . next ( ) ;
423
+ set_next ( & mut y ) ;
426
424
b = y. get ( ) ;
427
425
}
428
426
}
429
427
do b. while_some |b1| {
430
- if f ( b1) { y = y . next ( ) ; y. get ( ) } else { None }
428
+ if f ( b1) { set_next ( & mut y ) ; y. get ( ) } else { None }
431
429
}
432
430
}
433
431
}
@@ -438,22 +436,22 @@ impl <T: Ord> TreeSet<T>: Set<T> {
438
436
let mut y = other. iter ( ) ;
439
437
440
438
unsafe { // purity workaround
441
- x = x . next ( ) ;
442
- y = y . next ( ) ;
439
+ set_next ( & mut x ) ;
440
+ set_next ( & mut y ) ;
443
441
let mut a = x. get ( ) ;
444
442
let mut b = y. get ( ) ;
445
443
446
444
while a. is_some ( ) && b. is_some ( ) {
447
445
let a1 = a. unwrap ( ) ;
448
446
let b1 = b. unwrap ( ) ;
449
447
if a1 < b1 {
450
- x = x . next ( ) ;
448
+ set_next ( & mut x ) ;
451
449
a = x. get ( ) ;
452
450
} else {
453
451
if !( b1 < a1) {
454
452
if !f ( a1) { return }
455
453
}
456
- y = y . next ( ) ;
454
+ set_next ( & mut y ) ;
457
455
b = y. get ( ) ;
458
456
}
459
457
}
@@ -466,15 +464,15 @@ impl <T: Ord> TreeSet<T>: Set<T> {
466
464
let mut y = other. iter ( ) ;
467
465
468
466
unsafe { // purity workaround
469
- x = x . next ( ) ;
470
- y = y . next ( ) ;
467
+ set_next ( & mut x ) ;
468
+ set_next ( & mut y ) ;
471
469
let mut a = x. get ( ) ;
472
470
let mut b = y. get ( ) ;
473
471
474
472
while a. is_some ( ) {
475
473
if b. is_none ( ) {
476
474
return do a. while_some ( ) |a1| {
477
- if f ( a1) { x = x . next ( ) ; x. get ( ) } else { None }
475
+ if f ( a1) { set_next ( & mut x ) ; x. get ( ) } else { None }
478
476
}
479
477
}
480
478
@@ -483,15 +481,15 @@ impl <T: Ord> TreeSet<T>: Set<T> {
483
481
484
482
if b1 < a1 {
485
483
if !f ( b1) { return }
486
- y = y . next ( ) ;
484
+ set_next ( & mut y ) ;
487
485
b = y. get ( ) ;
488
486
} else {
489
487
if !f ( a1) { return }
490
488
if !( a1 < b1) {
491
- y = y . next ( ) ;
489
+ set_next ( & mut y ) ;
492
490
b = y. get ( )
493
491
}
494
- x = x . next ( ) ;
492
+ set_next ( & mut x ) ;
495
493
a = x. get ( ) ;
496
494
}
497
495
}
@@ -524,16 +522,16 @@ impl <T: Ord> TreeSetIterator<T> {
524
522
/// Returns the current node, or None if this iterator is at the end.
525
523
fn get( & const self ) -> Option <& self /T > {
526
524
match self . iter. get( ) {
527
- None => None ,
528
- Some ( ( k, _) ) => Some ( k)
525
+ None => None ,
526
+ Some ( ( k, _) ) => Some ( k)
529
527
}
530
528
}
529
+ }
531
530
532
- /// Advance the iterator to the next node (in order). If this iterator is
533
- /// finished, does nothing.
534
- fn next( self ) -> TreeSetIterator /& self <T > {
535
- TreeSetIterator { iter: self . iter. next( ) }
536
- }
531
+ /// Advance the iterator to the next node (in order). If this iterator is
532
+ /// finished, does nothing.
533
+ fn set_next<T : Ord >( iter: & mut TreeSetIterator /& a<T >) {
534
+ map_next( & mut iter. iter) ;
537
535
}
538
536
539
537
// Nodes keep track of their level in the tree, starting at 1 in the
@@ -967,18 +965,18 @@ mod test_treemap {
967
965
968
966
// FIXME: #4492 (ICE): iter.next() == Some((&x1, &y1))
969
967
970
- iter = iter. next ( ) ;
968
+ map_next ( & mut iter) ;
971
969
assert iter. get ( ) . unwrap ( ) == ( & x1, & y1) ;
972
- iter = iter. next ( ) ;
970
+ map_next ( & mut iter) ;
973
971
assert iter. get ( ) . unwrap ( ) == ( & x2, & y2) ;
974
- iter = iter. next ( ) ;
972
+ map_next ( & mut iter) ;
975
973
assert iter. get ( ) . unwrap ( ) == ( & x3, & y3) ;
976
- iter = iter. next ( ) ;
974
+ map_next ( & mut iter) ;
977
975
assert iter. get ( ) . unwrap ( ) == ( & x4, & y4) ;
978
- iter = iter. next ( ) ;
976
+ map_next ( & mut iter) ;
979
977
assert iter. get ( ) . unwrap ( ) == ( & x5, & y5) ;
980
978
981
- iter = iter. next ( ) ;
979
+ map_next ( & mut iter) ;
982
980
assert iter. get ( ) . is_none ( ) ;
983
981
}
984
982
}
0 commit comments