@@ -111,7 +111,7 @@ impl SmallBitv {
111111
112112#[ deriving( Clone ) ]
113113struct BigBitv {
114- storage : ~ [ uint ]
114+ storage : Vec < uint >
115115}
116116
117117/**
@@ -131,7 +131,7 @@ fn big_mask(nbits: uint, elem: uint) -> uint {
131131}
132132
133133impl BigBitv {
134- pub fn new ( storage : ~ [ uint ] ) -> BigBitv {
134+ pub fn new ( storage : Vec < uint > ) -> BigBitv {
135135 BigBitv { storage : storage}
136136 }
137137
@@ -193,7 +193,7 @@ impl BigBitv {
193193 pub fn get ( & self , i : uint ) -> bool {
194194 let w = i / uint:: BITS ;
195195 let b = i % uint:: BITS ;
196- let x = 1 & self . storage [ w ] >> b;
196+ let x = 1 & self . storage . get ( w ) >> b;
197197 x == 1
198198 }
199199
@@ -202,15 +202,15 @@ impl BigBitv {
202202 let w = i / uint:: BITS ;
203203 let b = i % uint:: BITS ;
204204 let flag = 1 << b;
205- self . storage [ w ] = if x { self . storage [ w ] | flag }
206- else { self . storage [ w ] & !flag } ;
205+ * self . storage . get_mut ( w ) = if x { * self . storage . get ( w ) | flag }
206+ else { * self . storage . get ( w ) & !flag } ;
207207 }
208208
209209 #[ inline]
210210 pub fn equals ( & self , b : & BigBitv , nbits : uint ) -> bool {
211211 for ( i, elt) in b. storage . iter ( ) . enumerate ( ) {
212212 let mask = big_mask ( nbits, i) ;
213- if mask & self . storage [ i ] != mask & * elt {
213+ if mask & * self . storage . get ( i ) != mask & * elt {
214214 return false ;
215215 }
216216 }
@@ -278,13 +278,13 @@ impl Bitv {
278278 let s =
279279 if init {
280280 if exact {
281- slice :: from_elem ( nelems, !0 u)
281+ Vec :: from_elem ( nelems, !0 u)
282282 } else {
283- let mut v = slice :: from_elem ( nelems-1 , !0 u) ;
283+ let mut v = Vec :: from_elem ( nelems-1 , !0 u) ;
284284 v. push ( ( 1 <<nbits % uint:: BITS ) -1 ) ;
285285 v
286286 }
287- } else { slice :: from_elem ( nelems, 0 u) } ;
287+ } else { Vec :: from_elem ( nelems, 0 u) } ;
288288 Big ( BigBitv :: new ( s) )
289289 } ;
290290 Bitv { rep : rep, nbits : nbits}
@@ -451,8 +451,8 @@ impl Bitv {
451451 *
452452 * Each `uint` in the resulting vector has either value `0u` or `1u`.
453453 */
454- pub fn to_vec ( & self ) -> ~ [ uint ] {
455- slice :: from_fn ( self . nbits , |x| self . init_to_vec ( x) )
454+ pub fn to_vec ( & self ) -> Vec < uint > {
455+ Vec :: from_fn ( self . nbits , |x| self . init_to_vec ( x) )
456456 }
457457
458458 /**
@@ -461,7 +461,7 @@ impl Bitv {
461461 * size of the `Bitv` is not a multiple of 8 then trailing bits
462462 * will be filled-in with false/0
463463 */
464- pub fn to_bytes ( & self ) -> ~ [ u8 ] {
464+ pub fn to_bytes ( & self ) -> Vec < u8 > {
465465 fn bit ( bitv : & Bitv , byte : uint , bit : uint ) -> u8 {
466466 let offset = byte * 8 + bit;
467467 if offset >= bitv. nbits {
@@ -473,7 +473,7 @@ impl Bitv {
473473
474474 let len = self . nbits /8 +
475475 if self . nbits % 8 == 0 { 0 } else { 1 } ;
476- slice :: from_fn ( len, |i|
476+ Vec :: from_fn ( len, |i|
477477 bit ( self , i, 0 ) |
478478 bit ( self , i, 1 ) |
479479 bit ( self , i, 2 ) |
@@ -486,10 +486,10 @@ impl Bitv {
486486 }
487487
488488 /**
489- * Transform `self` into a `[ bool] ` by turning each bit into a `bool`.
489+ * Transform `self` into a `Vec< bool> ` by turning each bit into a `bool`.
490490 */
491- pub fn to_bools ( & self ) -> ~ [ bool ] {
492- slice :: from_fn ( self . nbits , |i| self [ i] )
491+ pub fn to_bools ( & self ) -> Vec < bool > {
492+ Vec :: from_fn ( self . nbits , |i| self [ i] )
493493 }
494494
495495 /**
@@ -659,7 +659,7 @@ pub struct BitvSet {
659659impl BitvSet {
660660 /// Creates a new bit vector set with initially no contents
661661 pub fn new ( ) -> BitvSet {
662- BitvSet { size : 0 , bitv : BigBitv :: new ( ~ [ 0 ] ) }
662+ BitvSet { size : 0 , bitv : BigBitv :: new ( vec ! ( 0 ) ) }
663663 }
664664
665665 /// Creates a new bit vector set from the given bit vector
@@ -673,7 +673,7 @@ impl BitvSet {
673673 match rep {
674674 Big ( b) => BitvSet { size : size, bitv : b } ,
675675 Small ( SmallBitv { bits} ) =>
676- BitvSet { size : size, bitv : BigBitv { storage : ~ [ bits] } } ,
676+ BitvSet { size : size, bitv : BigBitv { storage : vec ! ( bits) } } ,
677677 }
678678 }
679679
@@ -705,9 +705,9 @@ impl BitvSet {
705705 self . bitv . storage . grow ( other. capacity ( ) / uint:: BITS , & 0 ) ;
706706 }
707707 for ( i, & w) in other. bitv . storage . iter ( ) . enumerate ( ) {
708- let old = self . bitv . storage [ i ] ;
708+ let old = * self . bitv . storage . get ( i ) ;
709709 let new = f ( old, w) ;
710- self . bitv . storage [ i ] = new;
710+ * self . bitv . storage . get_mut ( i ) = new;
711711 self . size += nbits ( new) - nbits ( old) ;
712712 }
713713 }
@@ -863,7 +863,7 @@ impl MutableSet<uint> for BitvSet {
863863
864864 // Attempt to truncate our storage
865865 let mut i = self . bitv . storage . len ( ) ;
866- while i > 1 && self . bitv . storage [ i - 1 ] == 0 {
866+ while i > 1 && * self . bitv . storage . get ( i - 1 ) == 0 {
867867 i -= 1 ;
868868 }
869869 self . bitv . storage . truncate ( i) ;
@@ -878,12 +878,12 @@ impl BitvSet {
878878 /// w1, w2) where the bit location is the number of bits offset so far,
879879 /// and w1/w2 are the words coming from the two vectors self, other.
880880 fn commons < ' a > ( & ' a self , other : & ' a BitvSet )
881- -> Map < ' static , ( ( uint , & ' a uint ) , & ' a ~ [ uint ] ) , ( uint , uint , uint ) ,
882- Zip < Enumerate < slice:: Items < ' a , uint > > , Repeat < & ' a ~ [ uint ] > > > {
881+ -> Map < ' static , ( ( uint , & ' a uint ) , & ' a Vec < uint > ) , ( uint , uint , uint ) ,
882+ Zip < Enumerate < slice:: Items < ' a , uint > > , Repeat < & ' a Vec < uint > > > > {
883883 let min = cmp:: min ( self . bitv . storage . len ( ) , other. bitv . storage . len ( ) ) ;
884884 self . bitv . storage . slice ( 0 , min) . iter ( ) . enumerate ( )
885885 . zip ( Repeat :: new ( & other. bitv . storage ) )
886- . map ( |( ( i, & w) , o_store) | ( i * uint:: BITS , w, o_store[ i ] ) )
886+ . map ( |( ( i, & w) , o_store) | ( i * uint:: BITS , w, * o_store. get ( i ) ) )
887887 }
888888
889889 /// Visits each word in `self` or `other` that extends beyond the other. This
@@ -946,7 +946,6 @@ mod tests {
946946 use bitv;
947947
948948 use std:: uint;
949- use std:: slice;
950949 use rand;
951950 use rand:: Rng ;
952951
@@ -964,8 +963,8 @@ mod tests {
964963 #[test]
965964 fn test_0_elements() {
966965 let act = Bitv::new(0u, false);
967- let exp = slice ::from_elem::<bool> (0u, false);
968- assert!(act.eq_vec(exp));
966+ let exp = Vec ::from_elem(0u, false);
967+ assert!(act.eq_vec(exp.as_slice() ));
969968 }
970969
971970 #[test]
@@ -1299,12 +1298,12 @@ mod tests {
12991298 fn test_to_bytes() {
13001299 let mut bv = Bitv::new(3, true);
13011300 bv.set(1, false);
1302- assert_eq!(bv.to_bytes(), ~[ 0b10100000] );
1301+ assert_eq!(bv.to_bytes(), vec!( 0b10100000) );
13031302
13041303 let mut bv = Bitv::new(9, false);
13051304 bv.set(2, true);
13061305 bv.set(8, true);
1307- assert_eq!(bv.to_bytes(), ~[ 0b00100000, 0b10000000] );
1306+ assert_eq!(bv.to_bytes(), vec!( 0b00100000, 0b10000000) );
13081307 }
13091308
13101309 #[test]
@@ -1315,7 +1314,7 @@ mod tests {
13151314
13161315 #[test]
13171316 fn test_to_bools() {
1318- let bools = ~[ false, false, true, false, false, true, true, false] ;
1317+ let bools = vec!( false, false, true, false, false, true, true, false) ;
13191318 assert_eq!(from_bytes([0b00100110]).to_bools(), bools);
13201319 }
13211320
@@ -1334,8 +1333,8 @@ mod tests {
13341333 let bools = [true, false, true, true];
13351334 let bitv = BitvSet::from_bitv(from_bools(bools));
13361335
1337- let idxs: ~[ uint] = bitv.iter().collect();
1338- assert_eq!(idxs, ~[ 0, 2, 3] );
1336+ let idxs: Vec< uint> = bitv.iter().collect();
1337+ assert_eq!(idxs, vec!( 0, 2, 3) );
13391338 }
13401339
13411340 #[test]
@@ -1579,7 +1578,7 @@ mod tests {
15791578 #[ bench]
15801579 fn bench_big_bitv_small ( b : & mut BenchHarness ) {
15811580 let mut r = rng ( ) ;
1582- let mut bitv = BigBitv :: new ( ~ [ 0 ] ) ;
1581+ let mut bitv = BigBitv :: new ( vec ! ( 0 ) ) ;
15831582 b. iter ( || {
15841583 bitv. set ( ( r. next_u32 ( ) as uint ) % uint:: BITS , true ) ;
15851584 & bitv
@@ -1589,7 +1588,7 @@ mod tests {
15891588 #[ bench]
15901589 fn bench_big_bitv_big ( b : & mut BenchHarness ) {
15911590 let mut r = rng ( ) ;
1592- let mut storage = ~ [ ] ;
1591+ let mut storage = vec ! ( ) ;
15931592 storage. grow ( BENCH_BITS / uint:: BITS , & 0 u) ;
15941593 let mut bitv = BigBitv :: new ( storage) ;
15951594 b. iter ( || {
0 commit comments