mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-28 10:33:10 +00:00
Merge pull request #711 from proxima-one/add_flat_map_iter
Add `flat_map_iter` to `maybe_rayon`
This commit is contained in:
commit
8c275c49f2
@ -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"
|
||||
|
||||
@ -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")]
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user