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!)
This commit is contained in:
parent
7a7ae993ce
commit
da0d4be378
@ -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<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 @@ 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`.
|
||||
*
|
||||
@ -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)
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user