Move BitIterator into root of crate.

This commit is contained in:
Sean Bowe 2017-06-17 19:46:40 -06:00
parent 5cf6acd21a
commit fd3774118a
3 changed files with 34 additions and 33 deletions

View File

@ -3,6 +3,7 @@ use std::fmt;
use std::cmp::Ordering;
use std::borrow::Borrow;
use ::BitIterator;
use super::{
Engine,
Group,
@ -14,7 +15,6 @@ use super::{
Field,
SnarkField,
SqrtField,
BitIterator,
Convert,
Cow,
multiexp,

View File

@ -3,6 +3,7 @@ use std::fmt;
use std::borrow::Borrow;
use serde::{Serialize, Deserialize};
use super::BitIterator;
use super::{Cow, Convert};
@ -247,38 +248,6 @@ pub trait SnarkField<E: Engine>: PrimeField<E> + Group<E>
fn root_of_unity(&E) -> Self;
}
pub struct BitIterator<T> {
t: T,
n: usize
}
impl<T: AsRef<[u64]>> BitIterator<T> {
fn new(t: T) -> Self {
let bits = 64 * t.as_ref().len();
BitIterator {
t: t,
n: bits
}
}
}
impl<T: AsRef<[u64]>> Iterator for BitIterator<T> {
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)
}
}
}
#[cfg(test)]
mod tests;

View File

@ -181,3 +181,35 @@ impl<T, E> Convert<T, E> for T {
Cow::Borrowed(self)
}
}
pub struct BitIterator<T> {
t: T,
n: usize
}
impl<T: AsRef<[u64]>> BitIterator<T> {
fn new(t: T) -> Self {
let bits = 64 * t.as_ref().len();
BitIterator {
t: t,
n: bits
}
}
}
impl<T: AsRef<[u64]>> Iterator for BitIterator<T> {
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)
}
}
}