提交 da0d4be3 编写于 作者: A Andrew Poelstra

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!)
上级 7a7ae993
......@@ -268,15 +268,6 @@ pub fn any(&self) -> bool {
!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<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
......@@ -307,13 +298,6 @@ fn bit (bitv: &Bitv, byte: uint, bit: uint) -> u8 {
)
}
/**
* 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`.
*
......@@ -328,11 +312,6 @@ pub fn eq_vec(&self, v: &[bool]) -> bool {
}
true
}
pub fn ones(&self, f: |uint| -> bool) -> bool {
range(0u, self.nbits).advance(|i| !self.get(i) || f(i))
}
}
/**
......@@ -1157,7 +1136,7 @@ fn test_from_bools() {
#[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 @@ fn test_big_difference() {
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 @@ fn test_small_clear() {
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)
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册