use std::marker::PhantomData;
#[allow(dead_code)]
pub trait ParallelIter<'data,DiscQ, T>
where Self:Sized,
DiscQ: DiscreteQueue<Output=Self::RefItem>
{
type RefItem;
fn parallel_iter(&'data self) -> ParallelIterator<DiscQ, Self::RefItem>;
}
#[allow(dead_code)]
pub trait IntoParallelIter<'data,DiscQ,T>
where Self:Sized,
DiscQ: DiscreteQueue<Output=Self::IntoItem>
{
type IntoItem;
fn into_parallel_iter(self) -> ParallelIterator<DiscQ,Self::IntoItem>;
}
#[allow(clippy::len_without_is_empty)]
pub trait DiscreteQueue
{
type Output;
fn pop(&mut self) -> Option<Self::Output>;
fn pull(&mut self) -> Option<Vec<Self::Output>>;
fn is_active(&self) -> bool;
fn len(&self) -> Option<usize>;
}
pub struct ParallelIterator<DiscQ,T>
where DiscQ: DiscreteQueue<Output=T>,
{
pub iter:DiscQ,
t: PhantomData<T>
}
impl<DiscQ,T> ParallelIterator<DiscQ,T>
where DiscQ: DiscreteQueue<Output=T>,
{
pub fn new(iter:DiscQ) -> Self {
Self {
iter,
t:PhantomData
}
}
}
#[allow(clippy::len_without_is_empty)]
pub trait AtomicIterator {
type AtomicItem;
fn atomic_next(&mut self) -> Option<Self::AtomicItem>;
fn atomic_pull(&mut self) -> Option<Vec<Self::AtomicItem>>;
fn len(&self) -> Option<usize>;
fn is_active(&self) -> bool;
}
impl<DiscQ,T> AtomicIterator for ParallelIterator<DiscQ,T>
where DiscQ:DiscreteQueue<Output = T>,
{
type AtomicItem = DiscQ::Output;
fn atomic_next(&mut self) -> Option<Self::AtomicItem> {
self.iter.pop()
}
fn len(&self) -> Option<usize> {
self.iter.len()
}
fn is_active(&self) -> bool {
self.iter.is_active()
}
fn atomic_pull(&mut self) -> Option<Vec<Self::AtomicItem>> {
self.iter.pull()
}
}