@@ -1451,7 +1451,7 @@ impl BitSet {
1451
1451
/// ```
1452
1452
#[ inline]
1453
1453
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1454
- pub fn iter < ' a > ( & ' a self ) -> bit_set:: Iter < ' a > {
1454
+ pub fn iter ( & self ) -> bit_set:: Iter {
1455
1455
SetIter ( BlockIter :: from_blocks ( self . bit_vec . blocks ( ) ) )
1456
1456
}
1457
1457
@@ -1803,14 +1803,13 @@ impl hash::Hash for BitSet {
1803
1803
1804
1804
#[ derive( Clone ) ]
1805
1805
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1806
- struct BlockIter < T > where
1807
- T : Iterator < Item =u32 > {
1806
+ struct BlockIter < T > where T : Iterator < Item =u32 > {
1808
1807
head : u32 ,
1809
1808
head_offset : usize ,
1810
- tail : T
1809
+ tail : T ,
1811
1810
}
1812
- impl < ' a , T > BlockIter < T > where
1813
- T : Iterator < Item =u32 > {
1811
+
1812
+ impl < ' a , T > BlockIter < T > where T : Iterator < Item =u32 > {
1814
1813
fn from_blocks ( mut blocks : T ) -> BlockIter < T > {
1815
1814
let h = blocks. next ( ) . unwrap_or ( 0 ) ;
1816
1815
BlockIter { tail : blocks, head : h, head_offset : 0 }
@@ -1850,16 +1849,20 @@ impl<'a, T> Iterator for BlockIter<T> where T: Iterator<Item=u32> {
1850
1849
while self . head == 0 {
1851
1850
match self . tail . next ( ) {
1852
1851
Some ( w) => self . head = w,
1853
- _ => return None
1852
+ None => return None
1854
1853
}
1855
1854
self . head_offset += u32:: BITS ;
1856
1855
}
1857
1856
1858
- let t = self . head & !self . head + 1 ;
1859
- // remove the least significant bit
1857
+ // from the current block, isolate the
1858
+ // LSB and subtract 1, producing k:
1859
+ // a block with a number of set bits
1860
+ // equal to the index of the LSB
1861
+ let k = ( self . head & ( !self . head + 1 ) ) - 1 ;
1862
+ // update block, removing the LSB
1860
1863
self . head &= self . head - 1 ;
1861
- // return index of lsb
1862
- Some ( self . head_offset + ( u32:: count_ones ( t- 1 ) as usize ) )
1864
+ // return offset + ( index of LSB)
1865
+ Some ( self . head_offset + ( u32:: count_ones ( k ) as usize ) )
1863
1866
}
1864
1867
1865
1868
#[ inline]
@@ -1886,11 +1889,15 @@ impl<'a> Iterator for TwoBitPositions<'a> {
1886
1889
1887
1890
#[ inline]
1888
1891
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1889
- let ( a, al) = self . set . size_hint ( ) ;
1890
- let ( b, bl) = self . set . size_hint ( ) ;
1892
+ let ( a, au) = self . set . size_hint ( ) ;
1893
+ let ( b, bu) = self . other . size_hint ( ) ;
1894
+
1895
+ let upper = match ( au, bu) {
1896
+ ( Some ( au) , Some ( bu) ) => Some ( cmp:: max ( au, bu) ) ,
1897
+ _ => None
1898
+ } ;
1891
1899
1892
- assert_eq ! ( a, b) ;
1893
- ( a, cmp:: max ( al, bl) )
1900
+ ( cmp:: max ( a, b) , upper)
1894
1901
}
1895
1902
}
1896
1903
0 commit comments