@@ -88,14 +88,14 @@ use core::fmt;
88
88
use core:: iter:: { Cloned , Chain , Enumerate , Repeat , Skip , Take } ;
89
89
use core:: iter;
90
90
use core:: num:: Int ;
91
- use core:: slice:: { Iter , IterMut } ;
91
+ use core:: slice;
92
92
use core:: { u8, u32, uint} ;
93
93
94
94
use core:: hash;
95
95
use Vec ;
96
96
97
- type Blocks < ' a > = Cloned < Iter < ' a , u32 > > ;
98
- type MutBlocks < ' a > = IterMut < ' a , u32 > ;
97
+ type Blocks < ' a > = Cloned < slice :: Iter < ' a , u32 > > ;
98
+ type MutBlocks < ' a > = slice :: IterMut < ' a , u32 > ;
99
99
type MatchWords < ' a > = Chain < Enumerate < Blocks < ' a > > , Skip < Take < Enumerate < Repeat < u32 > > > > > ;
100
100
101
101
fn reverse_bits ( byte : u8 ) -> u8 {
@@ -163,7 +163,7 @@ pub struct Bitv {
163
163
// FIXME(Gankro): NopeNopeNopeNopeNope (wait for IndexGet to be a thing)
164
164
impl Index < uint , bool > for Bitv {
165
165
#[ inline]
166
- fn index < ' a > ( & ' a self , i : & uint ) -> & ' a bool {
166
+ fn index ( & self , i : & uint ) -> & bool {
167
167
if self . get ( * i) . expect ( "index out of bounds" ) {
168
168
& TRUE
169
169
} else {
@@ -580,8 +580,8 @@ impl Bitv {
580
580
/// ```
581
581
#[ inline]
582
582
#[ stable]
583
- pub fn iter < ' a > ( & ' a self ) -> Bits < ' a > {
584
- Bits { bitv : self , next_idx : 0 , end_idx : self . nbits }
583
+ pub fn iter ( & self ) -> Iter {
584
+ Iter { bitv : self , next_idx : 0 , end_idx : self . nbits }
585
585
}
586
586
587
587
/// Returns `true` if all bits are 0.
@@ -1018,15 +1018,15 @@ impl cmp::PartialEq for Bitv {
1018
1018
impl cmp:: Eq for Bitv { }
1019
1019
1020
1020
/// An iterator for `Bitv`.
1021
- #[ unstable = "needs to be newtyped" ]
1022
- pub struct Bits < ' a > {
1021
+ #[ stable ]
1022
+ pub struct Iter < ' a > {
1023
1023
bitv : & ' a Bitv ,
1024
1024
next_idx : uint ,
1025
1025
end_idx : uint ,
1026
1026
}
1027
1027
1028
1028
#[ stable]
1029
- impl < ' a > Iterator < bool > for Bits < ' a > {
1029
+ impl < ' a > Iterator < bool > for Iter < ' a > {
1030
1030
#[ inline]
1031
1031
fn next ( & mut self ) -> Option < bool > {
1032
1032
if self . next_idx != self . end_idx {
@@ -1045,7 +1045,7 @@ impl<'a> Iterator<bool> for Bits<'a> {
1045
1045
}
1046
1046
1047
1047
#[ stable]
1048
- impl < ' a > DoubleEndedIterator < bool > for Bits < ' a > {
1048
+ impl < ' a > DoubleEndedIterator < bool > for Iter < ' a > {
1049
1049
#[ inline]
1050
1050
fn next_back ( & mut self ) -> Option < bool > {
1051
1051
if self . next_idx != self . end_idx {
@@ -1058,10 +1058,10 @@ impl<'a> DoubleEndedIterator<bool> for Bits<'a> {
1058
1058
}
1059
1059
1060
1060
#[ stable]
1061
- impl < ' a > ExactSizeIterator < bool > for Bits < ' a > { }
1061
+ impl < ' a > ExactSizeIterator < bool > for Iter < ' a > { }
1062
1062
1063
1063
#[ stable]
1064
- impl < ' a > RandomAccessIterator < bool > for Bits < ' a > {
1064
+ impl < ' a > RandomAccessIterator < bool > for Iter < ' a > {
1065
1065
#[ inline]
1066
1066
fn indexable ( & self ) -> uint {
1067
1067
self . end_idx - self . next_idx
@@ -1332,7 +1332,7 @@ impl BitvSet {
1332
1332
/// assert_eq!(bv[0], true);
1333
1333
/// ```
1334
1334
#[ inline]
1335
- pub fn get_ref < ' a > ( & ' a self ) -> & ' a Bitv {
1335
+ pub fn get_ref ( & self ) -> & Bitv {
1336
1336
& self . bitv
1337
1337
}
1338
1338
@@ -1412,8 +1412,8 @@ impl BitvSet {
1412
1412
/// ```
1413
1413
#[ inline]
1414
1414
#[ stable]
1415
- pub fn iter < ' a > ( & ' a self ) -> BitPositions < ' a > {
1416
- BitPositions { set : self , next_idx : 0 u}
1415
+ pub fn iter ( & self ) -> SetIter {
1416
+ SetIter { set : self , next_idx : 0 u}
1417
1417
}
1418
1418
1419
1419
/// Iterator over each u32 stored in `self` union `other`.
@@ -1434,16 +1434,16 @@ impl BitvSet {
1434
1434
/// ```
1435
1435
#[ inline]
1436
1436
#[ stable]
1437
- pub fn union < ' a > ( & ' a self , other : & ' a BitvSet ) -> TwoBitPositions < ' a > {
1437
+ pub fn union < ' a > ( & ' a self , other : & ' a BitvSet ) -> Union < ' a > {
1438
1438
fn or ( w1 : u32 , w2 : u32 ) -> u32 { w1 | w2 }
1439
1439
1440
- TwoBitPositions {
1440
+ Union ( TwoBitPositions {
1441
1441
set : self ,
1442
1442
other : other,
1443
1443
merge : or,
1444
1444
current_word : 0u32 ,
1445
1445
next_idx : 0 u
1446
- }
1446
+ } )
1447
1447
}
1448
1448
1449
1449
/// Iterator over each uint stored in `self` intersect `other`.
@@ -1464,16 +1464,16 @@ impl BitvSet {
1464
1464
/// ```
1465
1465
#[ inline]
1466
1466
#[ stable]
1467
- pub fn intersection < ' a > ( & ' a self , other : & ' a BitvSet ) -> Take < TwoBitPositions < ' a > > {
1467
+ pub fn intersection < ' a > ( & ' a self , other : & ' a BitvSet ) -> Intersection < ' a > {
1468
1468
fn bitand ( w1 : u32 , w2 : u32 ) -> u32 { w1 & w2 }
1469
1469
let min = cmp:: min ( self . bitv . len ( ) , other. bitv . len ( ) ) ;
1470
- TwoBitPositions {
1470
+ Intersection ( TwoBitPositions {
1471
1471
set : self ,
1472
1472
other : other,
1473
1473
merge : bitand,
1474
1474
current_word : 0u32 ,
1475
1475
next_idx : 0
1476
- } . take ( min)
1476
+ } . take ( min) )
1477
1477
}
1478
1478
1479
1479
/// Iterator over each uint stored in the `self` setminus `other`.
@@ -1501,16 +1501,16 @@ impl BitvSet {
1501
1501
/// ```
1502
1502
#[ inline]
1503
1503
#[ stable]
1504
- pub fn difference < ' a > ( & ' a self , other : & ' a BitvSet ) -> TwoBitPositions < ' a > {
1504
+ pub fn difference < ' a > ( & ' a self , other : & ' a BitvSet ) -> Difference < ' a > {
1505
1505
fn diff ( w1 : u32 , w2 : u32 ) -> u32 { w1 & !w2 }
1506
1506
1507
- TwoBitPositions {
1507
+ Difference ( TwoBitPositions {
1508
1508
set : self ,
1509
1509
other : other,
1510
1510
merge : diff,
1511
1511
current_word : 0u32 ,
1512
1512
next_idx : 0
1513
- }
1513
+ } )
1514
1514
}
1515
1515
1516
1516
/// Iterator over each u32 stored in the symmetric difference of `self` and `other`.
@@ -1532,16 +1532,16 @@ impl BitvSet {
1532
1532
/// ```
1533
1533
#[ inline]
1534
1534
#[ stable]
1535
- pub fn symmetric_difference < ' a > ( & ' a self , other : & ' a BitvSet ) -> TwoBitPositions < ' a > {
1535
+ pub fn symmetric_difference < ' a > ( & ' a self , other : & ' a BitvSet ) -> SymmetricDifference < ' a > {
1536
1536
fn bitxor ( w1 : u32 , w2 : u32 ) -> u32 { w1 ^ w2 }
1537
1537
1538
- TwoBitPositions {
1538
+ SymmetricDifference ( TwoBitPositions {
1539
1539
set : self ,
1540
1540
other : other,
1541
1541
merge : bitxor,
1542
1542
current_word : 0u32 ,
1543
1543
next_idx : 0
1544
- }
1544
+ } )
1545
1545
}
1546
1546
1547
1547
/// Unions in-place with the specified other bit vector.
@@ -1760,15 +1760,14 @@ impl<S: hash::Writer> hash::Hash<S> for BitvSet {
1760
1760
}
1761
1761
1762
1762
/// An iterator for `BitvSet`.
1763
- #[ unstable = "needs to be newtyped" ]
1764
- pub struct BitPositions < ' a > {
1763
+ #[ stable ]
1764
+ pub struct SetIter < ' a > {
1765
1765
set : & ' a BitvSet ,
1766
1766
next_idx : uint
1767
1767
}
1768
1768
1769
1769
/// An iterator combining two `BitvSet` iterators.
1770
- #[ unstable = "needs to be newtyped" ]
1771
- pub struct TwoBitPositions < ' a > {
1770
+ struct TwoBitPositions < ' a > {
1772
1771
set : & ' a BitvSet ,
1773
1772
other : & ' a BitvSet ,
1774
1773
merge : fn ( u32 , u32 ) -> u32 ,
@@ -1777,7 +1776,16 @@ pub struct TwoBitPositions<'a> {
1777
1776
}
1778
1777
1779
1778
#[ stable]
1780
- impl < ' a > Iterator < uint > for BitPositions < ' a > {
1779
+ pub struct Union < ' a > ( TwoBitPositions < ' a > ) ;
1780
+ #[ stable]
1781
+ pub struct Intersection < ' a > ( Take < TwoBitPositions < ' a > > ) ;
1782
+ #[ stable]
1783
+ pub struct Difference < ' a > ( TwoBitPositions < ' a > ) ;
1784
+ #[ stable]
1785
+ pub struct SymmetricDifference < ' a > ( TwoBitPositions < ' a > ) ;
1786
+
1787
+ #[ stable]
1788
+ impl < ' a > Iterator < uint > for SetIter < ' a > {
1781
1789
fn next ( & mut self ) -> Option < uint > {
1782
1790
while self . next_idx < self . set . bitv . len ( ) {
1783
1791
let idx = self . next_idx ;
@@ -1833,8 +1841,29 @@ impl<'a> Iterator<uint> for TwoBitPositions<'a> {
1833
1841
}
1834
1842
}
1835
1843
1844
+ #[ stable]
1845
+ impl < ' a > Iterator < uint > for Union < ' a > {
1846
+ #[ inline] fn next ( & mut self ) -> Option < uint > { self . 0 . next ( ) }
1847
+ #[ inline] fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . 0 . size_hint ( ) }
1848
+ }
1836
1849
1850
+ #[ stable]
1851
+ impl < ' a > Iterator < uint > for Intersection < ' a > {
1852
+ #[ inline] fn next ( & mut self ) -> Option < uint > { self . 0 . next ( ) }
1853
+ #[ inline] fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . 0 . size_hint ( ) }
1854
+ }
1837
1855
1856
+ #[ stable]
1857
+ impl < ' a > Iterator < uint > for Difference < ' a > {
1858
+ #[ inline] fn next ( & mut self ) -> Option < uint > { self . 0 . next ( ) }
1859
+ #[ inline] fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . 0 . size_hint ( ) }
1860
+ }
1861
+
1862
+ #[ stable]
1863
+ impl < ' a > Iterator < uint > for SymmetricDifference < ' a > {
1864
+ #[ inline] fn next ( & mut self ) -> Option < uint > { self . 0 . next ( ) }
1865
+ #[ inline] fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . 0 . size_hint ( ) }
1866
+ }
1838
1867
1839
1868
1840
1869
#[ cfg( test) ]
0 commit comments