diff options
| author | Andrew Poelstra <apoelstra@wpsoftware.net> | 2014-06-30 07:25:58 -0700 |
|---|---|---|
| committer | Andrew Poelstra <apoelstra@wpsoftware.net> | 2014-07-02 12:36:02 -0700 |
| commit | da0d4be378d289e9e90a48deec674d42205ae4c9 (patch) | |
| tree | 628be29241bcda5c23965df212063b8e8bc5da21 | |
| parent | 7a7ae993ce694bf75a11632b394916e055a4d8ec (diff) | |
collections::bitv: remove some ancient interfaces
Removes the following methods from `Bitv`:
- `to_vec`: translates a `Bitv` into a bulky `Vec<uint>` 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<bool>`
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!)
| -rw-r--r-- | src/libcollections/bitv.rs | 27 |
1 files 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 @@ -269,15 +269,6 @@ impl Bitv { } /** - * 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<uint> { - 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 * size of the `Bitv` is not a multiple of 8 then trailing bits @@ -308,13 +299,6 @@ impl Bitv { } /** - * Transform `self` into a `Vec<bool>` by turning each bit into a `bool`. - */ - pub fn to_bools(&self) -> Vec<bool> { - Vec::from_fn(self.nbits, |i| self[i]) - } - - /** * Compare a bitvector to a vector of `bool`. * * Both the bitvector and vector must have the same length. @@ -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::<Vec<bool>>(), 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) }); } |
