From da0d4be378d289e9e90a48deec674d42205ae4c9 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Mon, 30 Jun 2014 07:25:58 -0700 Subject: [PATCH] collections::bitv: remove some ancient interfaces Removes the following methods from `Bitv`: - `to_vec`: translates a `Bitv` into a bulky `Vec` of 0's and 1's replace with: `bitv.iter().map(|b| if b {1} else {0}).collect()` - `to_bools`: translates a `Bitv` into a `Vec` replace with: `bitv.iter().collect()` - `ones`: internal iterator over all 1 bits in a `Bitv` replace with: `BitvSet::from_bitv(bitv).iter().advance(fn)` These methods had specific functionality which can be replicated more generally by the modern iterator system. (Also `to_vec` was not even unit tested!) --- src/libcollections/bitv.rs | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index 18e3390dff5..3aeb15eef6f 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -268,15 +268,6 @@ impl Bitv { !self.none() } - /** - * Converts `self` to a vector of `uint` with the same length. - * - * Each `uint` in the resulting vector has either value `0u` or `1u`. - */ - pub fn to_vec(&self) -> Vec { - Vec::from_fn(self.nbits, |i| if self.get(i) { 1 } else { 0 }) - } - /** * Organise the bits into bytes, such that the first bit in the * `Bitv` becomes the high-order bit of the first byte. If the @@ -307,13 +298,6 @@ impl Bitv { ) } - /** - * Transform `self` into a `Vec` by turning each bit into a `bool`. - */ - pub fn to_bools(&self) -> Vec { - Vec::from_fn(self.nbits, |i| self[i]) - } - /** * Compare a bitvector to a vector of `bool`. * @@ -328,11 +312,6 @@ impl Bitv { } true } - - pub fn ones(&self, f: |uint| -> bool) -> bool { - range(0u, self.nbits).advance(|i| !self.get(i) || f(i)) - } - } /** @@ -1157,7 +1136,7 @@ mod tests { #[test] fn test_to_bools() { let bools = vec!(false, false, true, false, false, true, true, false); - assert_eq!(from_bytes([0b00100110]).to_bools(), bools); + assert_eq!(from_bytes([0b00100110]).iter().collect::>(), bools); } #[test] @@ -1225,7 +1204,7 @@ mod tests { fn test_small_clear() { let mut b = Bitv::new(14, true); b.clear(); - b.ones(|i| { + BitvSet::from_bitv(b).iter().advance(|i| { fail!("found 1 at {:?}", i) }); } @@ -1234,7 +1213,7 @@ mod tests { fn test_big_clear() { let mut b = Bitv::new(140, true); b.clear(); - b.ones(|i| { + BitvSet::from_bitv(b).iter().advance(|i| { fail!("found 1 at {:?}", i) }); }