#[derive(Debug)]
|
|
pub struct BitIterator<E> {
|
|
t: E,
|
|
n: usize,
|
|
}
|
|
|
|
impl<E: AsRef<[u64]>> BitIterator<E> {
|
|
pub fn new(t: E) -> Self {
|
|
let n = t.as_ref().len() * 64;
|
|
|
|
BitIterator { t, n }
|
|
}
|
|
}
|
|
|
|
impl<E: AsRef<[u64]>> Iterator for BitIterator<E> {
|
|
type Item = bool;
|
|
|
|
fn next(&mut self) -> Option<bool> {
|
|
if self.n == 0 {
|
|
None
|
|
} else {
|
|
self.n -= 1;
|
|
let part = self.n / 64;
|
|
let bit = self.n - (64 * part);
|
|
|
|
Some(self.t.as_ref()[part] & (1 << bit) > 0)
|
|
}
|
|
}
|
|
}
|