Merge pull request #711 from proxima-one/add_flat_map_iter

Add `flat_map_iter` to `maybe_rayon`
This commit is contained in:
Daniel Lubarov 2022-09-07 15:03:50 -07:00 committed by GitHub
commit 8c275c49f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 4 deletions

View File

@ -5,7 +5,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
plonky2 = { path = "../plonky2" }
plonky2 = { path = "../plonky2", default-features = false, features = ["rand", "rand_chacha", "timing", "gate_testing"] }
plonky2_util = { path = "../util" }
anyhow = "1.0.40"
env_logger = "0.9.0"

View File

@ -1,6 +1,6 @@
#[cfg(not(feature = "parallel"))]
use std::{
iter::{IntoIterator, Iterator},
iter::{FlatMap, IntoIterator, Iterator},
slice::{Chunks, ChunksExact, ChunksExactMut, ChunksMut},
};
@ -223,13 +223,21 @@ impl<T: Send> MaybeParChunksMut<T> for [T] {
}
}
#[cfg(not(feature = "parallel"))]
pub trait ParallelIteratorMock {
type Item;
fn find_any<P>(self, predicate: P) -> Option<Self::Item>
where
P: Fn(&Self::Item) -> bool + Sync + Send;
fn flat_map_iter<U, F>(self, map_op: F) -> FlatMap<Self, U, F>
where
Self: Sized,
U: IntoIterator,
F: Fn(Self::Item) -> U;
}
#[cfg(not(feature = "parallel"))]
impl<T: Iterator> ParallelIteratorMock for T {
type Item = T::Item;
@ -239,6 +247,15 @@ impl<T: Iterator> ParallelIteratorMock for T {
{
self.find(predicate)
}
fn flat_map_iter<U, F>(self, map_op: F) -> FlatMap<Self, U, F>
where
Self: Sized,
U: IntoIterator,
F: Fn(Self::Item) -> U,
{
self.flat_map(map_op)
}
}
#[cfg(feature = "parallel")]

View File

@ -115,7 +115,7 @@ pub struct MerkleCapTarget(pub Vec<HashOutTarget>);
pub struct BytesHash<const N: usize>(pub [u8; N]);
impl<const N: usize> BytesHash<N> {
#[cfg(feature = "parallel")]
#[cfg(feature = "rand")]
pub fn rand_from_rng<R: rand::Rng>(rng: &mut R) -> Self {
let mut buf = [0; N];
rng.fill_bytes(&mut buf);

View File

@ -9,7 +9,7 @@ default = ["parallel"]
parallel = ["maybe_rayon/parallel"]
[dependencies]
plonky2 = { path = "../plonky2" }
plonky2 = { path = "../plonky2", default-features = false, features = ["rand", "timing", "rand_chacha"] }
plonky2_util = { path = "../util" }
anyhow = "1.0.40"
env_logger = "0.9.0"