@@ -88,14 +88,14 @@ use core::fmt;
8888use core:: iter:: { Cloned , Chain , Enumerate , Repeat , Skip , Take } ;
8989use core:: iter;
9090use core:: num:: Int ;
91- use core:: slice:: { Iter , IterMut } ;
91+ use core:: slice;
9292use core:: { u8, u32, uint} ;
9393
9494use core:: hash;
9595use Vec ;
9696
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 > ;
9999type MatchWords < ' a > = Chain < Enumerate < Blocks < ' a > > , Skip < Take < Enumerate < Repeat < u32 > > > > > ;
100100
101101fn reverse_bits ( byte : u8 ) -> u8 {
@@ -163,7 +163,7 @@ pub struct Bitv {
163163// FIXME(Gankro): NopeNopeNopeNopeNope (wait for IndexGet to be a thing)
164164impl Index < uint , bool > for Bitv {
165165 #[ inline]
166- fn index < ' a > ( & ' a self , i : & uint ) -> & ' a bool {
166+ fn index ( & self , i : & uint ) -> & bool {
167167 if self . get ( * i) . expect ( "index out of bounds" ) {
168168 & TRUE
169169 } else {
@@ -580,8 +580,8 @@ impl Bitv {
580580 /// ```
581581 #[ inline]
582582 #[ 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 }
585585 }
586586
587587 /// Returns `true` if all bits are 0.
@@ -1018,15 +1018,15 @@ impl cmp::PartialEq for Bitv {
10181018impl cmp:: Eq for Bitv { }
10191019
10201020/// An iterator for `Bitv`.
1021- #[ unstable = "needs to be newtyped" ]
1022- pub struct Bits < ' a > {
1021+ #[ stable ]
1022+ pub struct Iter < ' a > {
10231023 bitv : & ' a Bitv ,
10241024 next_idx : uint ,
10251025 end_idx : uint ,
10261026}
10271027
10281028#[ stable]
1029- impl < ' a > Iterator < bool > for Bits < ' a > {
1029+ impl < ' a > Iterator < bool > for Iter < ' a > {
10301030 #[ inline]
10311031 fn next ( & mut self ) -> Option < bool > {
10321032 if self . next_idx != self . end_idx {
@@ -1045,7 +1045,7 @@ impl<'a> Iterator<bool> for Bits<'a> {
10451045}
10461046
10471047#[ stable]
1048- impl < ' a > DoubleEndedIterator < bool > for Bits < ' a > {
1048+ impl < ' a > DoubleEndedIterator < bool > for Iter < ' a > {
10491049 #[ inline]
10501050 fn next_back ( & mut self ) -> Option < bool > {
10511051 if self . next_idx != self . end_idx {
@@ -1058,10 +1058,10 @@ impl<'a> DoubleEndedIterator<bool> for Bits<'a> {
10581058}
10591059
10601060#[ stable]
1061- impl < ' a > ExactSizeIterator < bool > for Bits < ' a > { }
1061+ impl < ' a > ExactSizeIterator < bool > for Iter < ' a > { }
10621062
10631063#[ stable]
1064- impl < ' a > RandomAccessIterator < bool > for Bits < ' a > {
1064+ impl < ' a > RandomAccessIterator < bool > for Iter < ' a > {
10651065 #[ inline]
10661066 fn indexable ( & self ) -> uint {
10671067 self . end_idx - self . next_idx
@@ -1332,7 +1332,7 @@ impl BitvSet {
13321332 /// assert_eq!(bv[0], true);
13331333 /// ```
13341334 #[ inline]
1335- pub fn get_ref < ' a > ( & ' a self ) -> & ' a Bitv {
1335+ pub fn get_ref ( & self ) -> & Bitv {
13361336 & self . bitv
13371337 }
13381338
@@ -1412,8 +1412,8 @@ impl BitvSet {
14121412 /// ```
14131413 #[ inline]
14141414 #[ 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}
14171417 }
14181418
14191419 /// Iterator over each u32 stored in `self` union `other`.
@@ -1434,16 +1434,16 @@ impl BitvSet {
14341434 /// ```
14351435 #[ inline]
14361436 #[ 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 > {
14381438 fn or ( w1 : u32 , w2 : u32 ) -> u32 { w1 | w2 }
14391439
1440- TwoBitPositions {
1440+ Union ( TwoBitPositions {
14411441 set : self ,
14421442 other : other,
14431443 merge : or,
14441444 current_word : 0u32 ,
14451445 next_idx : 0 u
1446- }
1446+ } )
14471447 }
14481448
14491449 /// Iterator over each uint stored in `self` intersect `other`.
@@ -1464,16 +1464,16 @@ impl BitvSet {
14641464 /// ```
14651465 #[ inline]
14661466 #[ 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 > {
14681468 fn bitand ( w1 : u32 , w2 : u32 ) -> u32 { w1 & w2 }
14691469 let min = cmp:: min ( self . bitv . len ( ) , other. bitv . len ( ) ) ;
1470- TwoBitPositions {
1470+ Intersection ( TwoBitPositions {
14711471 set : self ,
14721472 other : other,
14731473 merge : bitand,
14741474 current_word : 0u32 ,
14751475 next_idx : 0
1476- } . take ( min)
1476+ } . take ( min) )
14771477 }
14781478
14791479 /// Iterator over each uint stored in the `self` setminus `other`.
@@ -1501,16 +1501,16 @@ impl BitvSet {
15011501 /// ```
15021502 #[ inline]
15031503 #[ 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 > {
15051505 fn diff ( w1 : u32 , w2 : u32 ) -> u32 { w1 & !w2 }
15061506
1507- TwoBitPositions {
1507+ Difference ( TwoBitPositions {
15081508 set : self ,
15091509 other : other,
15101510 merge : diff,
15111511 current_word : 0u32 ,
15121512 next_idx : 0
1513- }
1513+ } )
15141514 }
15151515
15161516 /// Iterator over each u32 stored in the symmetric difference of `self` and `other`.
@@ -1532,16 +1532,16 @@ impl BitvSet {
15321532 /// ```
15331533 #[ inline]
15341534 #[ 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 > {
15361536 fn bitxor ( w1 : u32 , w2 : u32 ) -> u32 { w1 ^ w2 }
15371537
1538- TwoBitPositions {
1538+ SymmetricDifference ( TwoBitPositions {
15391539 set : self ,
15401540 other : other,
15411541 merge : bitxor,
15421542 current_word : 0u32 ,
15431543 next_idx : 0
1544- }
1544+ } )
15451545 }
15461546
15471547 /// Unions in-place with the specified other bit vector.
@@ -1760,15 +1760,14 @@ impl<S: hash::Writer> hash::Hash<S> for BitvSet {
17601760}
17611761
17621762/// An iterator for `BitvSet`.
1763- #[ unstable = "needs to be newtyped" ]
1764- pub struct BitPositions < ' a > {
1763+ #[ stable ]
1764+ pub struct SetIter < ' a > {
17651765 set : & ' a BitvSet ,
17661766 next_idx : uint
17671767}
17681768
17691769/// An iterator combining two `BitvSet` iterators.
1770- #[ unstable = "needs to be newtyped" ]
1771- pub struct TwoBitPositions < ' a > {
1770+ struct TwoBitPositions < ' a > {
17721771 set : & ' a BitvSet ,
17731772 other : & ' a BitvSet ,
17741773 merge : fn ( u32 , u32 ) -> u32 ,
@@ -1777,7 +1776,16 @@ pub struct TwoBitPositions<'a> {
17771776}
17781777
17791778#[ 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 > {
17811789 fn next ( & mut self ) -> Option < uint > {
17821790 while self . next_idx < self . set . bitv . len ( ) {
17831791 let idx = self . next_idx ;
@@ -1833,8 +1841,29 @@ impl<'a> Iterator<uint> for TwoBitPositions<'a> {
18331841 }
18341842}
18351843
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+ }
18361849
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+ }
18371855
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+ }
18381867
18391868
18401869#[ cfg( test) ]
0 commit comments