@@ -668,7 +668,8 @@ impl<K: Ord, V> TreeMap<K, V> {
668
668
}
669
669
}
670
670
671
- /// A lazy forward iterator over a map.
671
+ /// Note: stage0-specific version that lacks bound on A.
672
+ #[ cfg( stage0) ]
672
673
pub struct Entries < ' a , K , V > {
673
674
stack : Vec < & ' a TreeNode < K , V > > ,
674
675
// See the comment on MutEntries; this is just to allow
@@ -679,13 +680,32 @@ pub struct Entries<'a, K, V> {
679
680
remaining_max : uint
680
681
}
681
682
682
- /// Lazy backward iterator over a map.
683
+ /// Lazy forward iterator over a map
684
+ #[ cfg( not( stage0) ) ]
685
+ pub struct Entries < ' a , K : ' a , V : ' a > {
686
+ stack : Vec < & ' a TreeNode < K , V > > ,
687
+ // See the comment on MutEntries; this is just to allow
688
+ // code-sharing (for this immutable-values iterator it *could* very
689
+ // well be Option<&'a TreeNode<K,V>>).
690
+ node : * const TreeNode < K , V > ,
691
+ remaining_min : uint ,
692
+ remaining_max : uint
693
+ }
694
+
695
+ /// Note: stage0-specific version that lacks bound on A.
696
+ #[ cfg( stage0) ]
683
697
pub struct RevEntries < ' a , K , V > {
684
698
iter : Entries < ' a , K , V > ,
685
699
}
686
700
687
- /// A lazy forward iterator over a map that allows for the mutation of
688
- /// the values.
701
+ /// Lazy backward iterator over a map
702
+ #[ cfg( not( stage0) ) ]
703
+ pub struct RevEntries < ' a , K : ' a , V : ' a > {
704
+ iter : Entries < ' a , K , V > ,
705
+ }
706
+
707
+ /// Note: stage0-specific version that lacks bound on A.
708
+ #[ cfg( stage0) ]
689
709
pub struct MutEntries < ' a , K , V > {
690
710
stack : Vec < & ' a mut TreeNode < K , V > > ,
691
711
// Unfortunately, we require some unsafe-ness to get around the
@@ -712,11 +732,46 @@ pub struct MutEntries<'a, K, V> {
712
732
remaining_max : uint
713
733
}
714
734
715
- /// Lazy backward iterator over a map.
735
+ /// Lazy forward iterator over a map that allows for the mutation of
736
+ /// the values.
737
+ #[ cfg( not( stage0) ) ]
738
+ pub struct MutEntries < ' a , K : ' a , V : ' a > {
739
+ stack : Vec < & ' a mut TreeNode < K , V > > ,
740
+ // Unfortunately, we require some unsafe-ness to get around the
741
+ // fact that we would be storing a reference *into* one of the
742
+ // nodes in the stack.
743
+ //
744
+ // As far as the compiler knows, this would let us invalidate the
745
+ // reference by assigning a new value to this node's position in
746
+ // its parent, which would cause this current one to be
747
+ // deallocated so this reference would be invalid. (i.e. the
748
+ // compilers complaints are 100% correct.)
749
+ //
750
+ // However, as far as you humans reading this code know (or are
751
+ // about to know, if you haven't read far enough down yet), we are
752
+ // only reading from the TreeNode.{left,right} fields. the only
753
+ // thing that is ever mutated is the .value field (although any
754
+ // actual mutation that happens is done externally, by the
755
+ // iterator consumer). So, don't be so concerned, rustc, we've got
756
+ // it under control.
757
+ //
758
+ // (This field can legitimately be null.)
759
+ node : * mut TreeNode < K , V > ,
760
+ remaining_min : uint ,
761
+ remaining_max : uint
762
+ }
763
+
764
+ /// Note: stage0-specific version that lacks bound on A.
765
+ #[ cfg( stage0) ]
716
766
pub struct RevMutEntries < ' a , K , V > {
717
767
iter : MutEntries < ' a , K , V > ,
718
768
}
719
769
770
+ /// Lazy backward iterator over a map
771
+ #[ cfg( not( stage0) ) ]
772
+ pub struct RevMutEntries < ' a , K : ' a , V : ' a > {
773
+ iter : MutEntries < ' a , K , V > ,
774
+ }
720
775
721
776
/// TreeMap keys iterator.
722
777
pub type Keys < ' a , K , V > =
@@ -885,9 +940,7 @@ fn mut_deref<K, V>(x: &mut Option<Box<TreeNode<K, V>>>)
885
940
}
886
941
}
887
942
888
-
889
-
890
- /// A lazy forward iterator over a map that consumes the map while iterating.
943
+ /// Lazy forward iterator over a map that consumes the map while iterating
891
944
pub struct MoveEntries < K , V > {
892
945
stack : Vec < TreeNode < K , V > > ,
893
946
remaining : uint
@@ -1322,45 +1375,90 @@ impl<T: Ord> TreeSet<T> {
1322
1375
}
1323
1376
}
1324
1377
1325
- /// A lazy forward iterator over a set.
1378
+ /// Note: stage0-specific version that lacks bound on A.
1379
+ #[ cfg( stage0) ]
1326
1380
pub struct SetItems < ' a , T > {
1327
1381
iter : Entries < ' a , T , ( ) >
1328
1382
}
1329
1383
1330
- /// Lazy backward iterator over a set.
1384
+ /// A lazy forward iterator over a set.
1385
+ #[ cfg( not( stage0) ) ]
1386
+ pub struct SetItems < ' a , T : ' a > {
1387
+ iter : Entries < ' a , T , ( ) >
1388
+ }
1389
+
1390
+ /// Note: stage0-specific version that lacks bound on A.
1391
+ #[ cfg( stage0) ]
1331
1392
pub struct RevSetItems < ' a , T > {
1332
1393
iter : RevEntries < ' a , T , ( ) >
1333
1394
}
1334
1395
1396
+ /// A lazy backward iterator over a set.
1397
+ #[ cfg( not( stage0) ) ]
1398
+ pub struct RevSetItems < ' a , T : ' a > {
1399
+ iter : RevEntries < ' a , T , ( ) >
1400
+ }
1401
+
1335
1402
/// A lazy forward iterator over a set that consumes the set while iterating.
1336
1403
pub type MoveSetItems < T > = iter:: Map < ' static , ( T , ( ) ) , T , MoveEntries < T , ( ) > > ;
1337
1404
1338
- /// A lazy iterator producing elements in the set difference (in-order).
1405
+ /// Note: stage0-specific version that lacks bound on A.
1406
+ #[ cfg( stage0) ]
1339
1407
pub struct DifferenceItems < ' a , T > {
1340
1408
a : Peekable < & ' a T , SetItems < ' a , T > > ,
1341
1409
b : Peekable < & ' a T , SetItems < ' a , T > > ,
1342
1410
}
1343
1411
1344
- /// A lazy iterator producing elements in the set symmetric difference (in-order).
1412
+ /// A lazy iterator producing elements in the set difference (in-order).
1413
+ #[ cfg( not( stage0) ) ]
1414
+ pub struct DifferenceItems < ' a , T : ' a > {
1415
+ a : Peekable < & ' a T , SetItems < ' a , T > > ,
1416
+ b : Peekable < & ' a T , SetItems < ' a , T > > ,
1417
+ }
1418
+
1419
+ /// Note: stage0-specific version that lacks bound on A.
1420
+ #[ cfg( stage0) ]
1345
1421
pub struct SymDifferenceItems < ' a , T > {
1346
1422
a : Peekable < & ' a T , SetItems < ' a , T > > ,
1347
1423
b : Peekable < & ' a T , SetItems < ' a , T > > ,
1348
1424
}
1349
1425
1350
- /// A lazy iterator producing elements in the set intersection (in-order).
1426
+ /// A lazy iterator producing elements in the set symmetric difference (in-order).
1427
+ #[ cfg( not( stage0) ) ]
1428
+ pub struct SymDifferenceItems < ' a , T : ' a > {
1429
+ a : Peekable < & ' a T , SetItems < ' a , T > > ,
1430
+ b : Peekable < & ' a T , SetItems < ' a , T > > ,
1431
+ }
1432
+
1433
+ /// Note: stage0-specific version that lacks bound on A.
1434
+ #[ cfg( stage0) ]
1351
1435
pub struct IntersectionItems < ' a , T > {
1352
1436
a : Peekable < & ' a T , SetItems < ' a , T > > ,
1353
1437
b : Peekable < & ' a T , SetItems < ' a , T > > ,
1354
1438
}
1355
1439
1356
- /// A lazy iterator producing elements in the set union (in-order).
1440
+ /// A lazy iterator producing elements in the set intersection (in-order).
1441
+ #[ cfg( not( stage0) ) ]
1442
+ pub struct IntersectionItems < ' a , T : ' a > {
1443
+ a : Peekable < & ' a T , SetItems < ' a , T > > ,
1444
+ b : Peekable < & ' a T , SetItems < ' a , T > > ,
1445
+ }
1446
+
1447
+ /// Note: stage0-specific version that lacks bound on A.
1448
+ #[ cfg( stage0) ]
1357
1449
pub struct UnionItems < ' a , T > {
1358
1450
a : Peekable < & ' a T , SetItems < ' a , T > > ,
1359
1451
b : Peekable < & ' a T , SetItems < ' a , T > > ,
1360
1452
}
1361
1453
1362
- /// Compare `x` and `y`, but return `short` if x is None and `long` if y is
1363
- /// `None`.
1454
+ /// A lazy iterator producing elements in the set union (in-order).
1455
+ #[ cfg( not( stage0) ) ]
1456
+ pub struct UnionItems < ' a , T : ' a > {
1457
+ a : Peekable < & ' a T , SetItems < ' a , T > > ,
1458
+ b : Peekable < & ' a T , SetItems < ' a , T > > ,
1459
+ }
1460
+
1461
+ /// Compare `x` and `y`, but return `short` if x is None and `long` if y is None
1364
1462
fn cmp_opt < T : Ord > ( x : Option < & T > , y : Option < & T > ,
1365
1463
short : Ordering , long : Ordering ) -> Ordering {
1366
1464
match ( x, y) {
0 commit comments