Skip to content

Commit da0d4be

Browse files
committed
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!)
1 parent 7a7ae99 commit da0d4be

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

src/libcollections/bitv.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,6 @@ impl Bitv {
268268
!self.none()
269269
}
270270

271-
/**
272-
* Converts `self` to a vector of `uint` with the same length.
273-
*
274-
* Each `uint` in the resulting vector has either value `0u` or `1u`.
275-
*/
276-
pub fn to_vec(&self) -> Vec<uint> {
277-
Vec::from_fn(self.nbits, |i| if self.get(i) { 1 } else { 0 })
278-
}
279-
280271
/**
281272
* Organise the bits into bytes, such that the first bit in the
282273
* `Bitv` becomes the high-order bit of the first byte. If the
@@ -307,13 +298,6 @@ impl Bitv {
307298
)
308299
}
309300

310-
/**
311-
* Transform `self` into a `Vec<bool>` by turning each bit into a `bool`.
312-
*/
313-
pub fn to_bools(&self) -> Vec<bool> {
314-
Vec::from_fn(self.nbits, |i| self[i])
315-
}
316-
317301
/**
318302
* Compare a bitvector to a vector of `bool`.
319303
*
@@ -328,11 +312,6 @@ impl Bitv {
328312
}
329313
true
330314
}
331-
332-
pub fn ones(&self, f: |uint| -> bool) -> bool {
333-
range(0u, self.nbits).advance(|i| !self.get(i) || f(i))
334-
}
335-
336315
}
337316

338317
/**
@@ -1157,7 +1136,7 @@ mod tests {
11571136
#[test]
11581137
fn test_to_bools() {
11591138
let bools = vec!(false, false, true, false, false, true, true, false);
1160-
assert_eq!(from_bytes([0b00100110]).to_bools(), bools);
1139+
assert_eq!(from_bytes([0b00100110]).iter().collect::<Vec<bool>>(), bools);
11611140
}
11621141

11631142
#[test]
@@ -1225,7 +1204,7 @@ mod tests {
12251204
fn test_small_clear() {
12261205
let mut b = Bitv::new(14, true);
12271206
b.clear();
1228-
b.ones(|i| {
1207+
BitvSet::from_bitv(b).iter().advance(|i| {
12291208
fail!("found 1 at {:?}", i)
12301209
});
12311210
}
@@ -1234,7 +1213,7 @@ mod tests {
12341213
fn test_big_clear() {
12351214
let mut b = Bitv::new(140, true);
12361215
b.clear();
1237-
b.ones(|i| {
1216+
BitvSet::from_bitv(b).iter().advance(|i| {
12381217
fail!("found 1 at {:?}", i)
12391218
});
12401219
}

0 commit comments

Comments
 (0)