]> git.lizzy.rs Git - rust.git/commitdiff
bitv: correct build failures
authorJosh Stone <cuviper@gmail.com>
Wed, 10 Dec 2014 05:47:10 +0000 (21:47 -0800)
committerAlexis Beingessner <a.beingessner@gmail.com>
Sat, 20 Dec 2014 14:10:03 +0000 (09:10 -0500)
- Fix typos on Blocks and MutBlocks.
- Use slice_to_mut() for creating blocks_mut().
- Deref the block parameter in get().
- Access nbits separately from mutating set in pop().

src/libcollections/bit.rs

index 41a5ccb7a0645e4da98e9245f4f0dea00cf60ad0..9ea7d52b7c6fb25cdca33bc3ccf30fac0a1d7b99 100644 (file)
@@ -87,8 +87,8 @@
 
 use vec::Vec;
 
-type Blocks<'a> = Cloned<Items<'a, u32>>
-type MutBlocks<'a> MutItems<'a, u32>;
+type Blocks<'a> = Cloned<Items<'a, u32>>;
+type MutBlocks<'a> MutItems<'a, u32>;
 type MatchWords<'a> = Chain<Enumerate<Blocks<'a>>, Skip<Take<Enumerate<Repeat<u32>>>>>;
 
 // Take two BitV's, and return iterators of their words, where the shorter one
@@ -199,7 +199,7 @@ fn process<F>(&mut self, other: &Bitv, mut op: F) -> bool where F: FnMut(u32, u3
     /// Iterator over mutable refs to  the underlying blocks of data.
     fn blocks_mut(&mut self) -> MutBlocks {
         let blocks = blocks_for_bits(self.len());
-        self.storage[..blocks].iter_mut()
+        self.storage.slice_to_mut(blocks).iter_mut()
     }
 
     /// Iterator over the underlying blocks of data
@@ -336,7 +336,7 @@ pub fn get(&self, i: uint) -> Option<bool> {
         assert!(i < self.nbits);
         let w = i / u32::BITS;
         let b = i % u32::BITS;
-        self.storage.get(w).map(|block|
+        self.storage.get(w).map(|&block|
             (block & (1 << b)) != 0
         )
     }
@@ -835,10 +835,11 @@ pub fn pop(&mut self) -> Option<bool> {
         if self.is_empty() {
             None
         } else {
-            let ret = self[self.nbits - 1];
+            let i = self.nbits - 1;
+            let ret = self[i];
             // Second rule of Bitv Club
-            self.set(self.nbits - 1, false);
-            self.nbits -= 1;
+            self.set(i, false);
+            self.nbits = i;
             Some(ret)
         }
     }