Move BitIterator into root of crate.
This commit is contained in:
parent
5cf6acd21a
commit
fd3774118a
@ -3,6 +3,7 @@ use std::fmt;
|
|||||||
|
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
|
use ::BitIterator;
|
||||||
use super::{
|
use super::{
|
||||||
Engine,
|
Engine,
|
||||||
Group,
|
Group,
|
||||||
@ -14,7 +15,6 @@ use super::{
|
|||||||
Field,
|
Field,
|
||||||
SnarkField,
|
SnarkField,
|
||||||
SqrtField,
|
SqrtField,
|
||||||
BitIterator,
|
|
||||||
Convert,
|
Convert,
|
||||||
Cow,
|
Cow,
|
||||||
multiexp,
|
multiexp,
|
||||||
|
@ -3,6 +3,7 @@ use std::fmt;
|
|||||||
|
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
use super::BitIterator;
|
||||||
|
|
||||||
use super::{Cow, Convert};
|
use super::{Cow, Convert};
|
||||||
|
|
||||||
@ -247,38 +248,6 @@ pub trait SnarkField<E: Engine>: PrimeField<E> + Group<E>
|
|||||||
fn root_of_unity(&E) -> Self;
|
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)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
|
32
src/lib.rs
32
src/lib.rs
@ -181,3 +181,35 @@ impl<T, E> Convert<T, E> for T {
|
|||||||
Cow::Borrowed(self)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user