@@ -978,6 +978,21 @@ impl Default for BitvSet {
978
978
fn default ( ) -> BitvSet { BitvSet :: new ( ) }
979
979
}
980
980
981
+ impl FromIterator < bool > for BitvSet {
982
+ fn from_iter < I : Iterator < bool > > ( iterator : I ) -> BitvSet {
983
+ let mut ret = BitvSet :: new ( ) ;
984
+ ret. extend ( iterator) ;
985
+ ret
986
+ }
987
+ }
988
+
989
+ impl Extendable < bool > for BitvSet {
990
+ #[ inline]
991
+ fn extend < I : Iterator < bool > > ( & mut self , iterator : I ) {
992
+ self . get_mut_ref ( ) . extend ( iterator) ;
993
+ }
994
+ }
995
+
981
996
impl BitvSet {
982
997
/// Create a new bit vector set with initially no contents.
983
998
///
@@ -1958,6 +1973,17 @@ mod tests {
1958
1973
assert_eq ! ( bitv. to_string( ) . as_slice( ) , "1011" ) ;
1959
1974
}
1960
1975
1976
+ #[ test]
1977
+ fn test_bitv_set_from_bools ( ) {
1978
+ let bools = vec ! [ true , false , true , true ] ;
1979
+ let a: BitvSet = bools. iter ( ) . map ( |n| * n) . collect ( ) ;
1980
+ let mut b = BitvSet :: new ( ) ;
1981
+ b. insert ( 0 ) ;
1982
+ b. insert ( 2 ) ;
1983
+ b. insert ( 3 ) ;
1984
+ assert_eq ! ( a, b) ;
1985
+ }
1986
+
1961
1987
#[ test]
1962
1988
fn test_to_bools ( ) {
1963
1989
let bools = vec ! ( false , false , true , false , false , true , true , false ) ;
@@ -1977,7 +2003,7 @@ mod tests {
1977
2003
#[ test]
1978
2004
fn test_bitv_set_iterator ( ) {
1979
2005
let bools = [ true , false , true , true ] ;
1980
- let bitv = BitvSet :: from_bitv ( bools. iter ( ) . map ( |n| * n) . collect ( ) ) ;
2006
+ let bitv: BitvSet = bools. iter ( ) . map ( |n| * n) . collect ( ) ;
1981
2007
1982
2008
let idxs: Vec < uint > = bitv. iter ( ) . collect ( ) ;
1983
2009
assert_eq ! ( idxs, vec!( 0 , 2 , 3 ) ) ;
0 commit comments