use crate::par::par_empty::ParEmpty;
use iter::atomic_iter::AtomicIter;
use orx_concurrent_iter::*;
use std::ops::{Add, Range, Sub};
pub trait IntoPar {
type ConIter: ConcurrentIter;
fn into_par(self) -> ParEmpty<Self::ConIter>;
}
impl<const N: usize, T: Send + Sync + Default> IntoPar for [T; N] {
type ConIter = ConIterOfArray<N, T>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self.into_con_iter())
}
}
impl<const N: usize, T: Send + Sync + Default> IntoPar for ConIterOfArray<N, T> {
type ConIter = ConIterOfArray<N, T>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self)
}
}
impl<T: Send + Sync, Iter> IntoPar for ConIterOfIter<T, Iter>
where
Iter: Iterator<Item = T>,
{
type ConIter = ConIterOfIter<T, Iter>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self)
}
}
impl<Idx> IntoPar for Range<Idx>
where
Idx: Send
+ Sync
+ Clone
+ Copy
+ From<usize>
+ Into<usize>
+ Add<Idx, Output = Idx>
+ Sub<Idx, Output = Idx>
+ Ord,
Range<Idx>: Iterator<Item = Idx>,
{
type ConIter = ConIterOfRange<Idx>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self.con_iter())
}
}
impl<Idx> IntoPar for ConIterOfRange<Idx>
where
Idx: Send
+ Sync
+ Clone
+ Copy
+ From<usize>
+ Into<usize>
+ Add<Idx, Output = Idx>
+ Sub<Idx, Output = Idx>
+ Ord,
Range<Idx>: Iterator<Item = Idx>,
{
type ConIter = ConIterOfRange<Idx>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self)
}
}
impl<'a, T: Send + Sync> IntoPar for &'a [T] {
type ConIter = ConIterOfSlice<'a, T>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self.into_con_iter())
}
}
impl<'a, T: Send + Sync> IntoPar for ConIterOfSlice<'a, T> {
type ConIter = ConIterOfSlice<'a, T>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self)
}
}
impl<'a, T: Send + Sync + Clone, C: AtomicIter<&'a T> + ConcurrentIter<Item = &'a T>> IntoPar
for Cloned<'a, T, C>
{
type ConIter = Cloned<'a, T, C>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self)
}
}
impl<T: Send + Sync> IntoPar for Vec<T> {
type ConIter = ConIterOfVec<T>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self.into_con_iter())
}
}
impl<T: Send + Sync> IntoPar for ConIterOfVec<T> {
type ConIter = ConIterOfVec<T>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self)
}
}
mod impl_std_collections {
use crate::{par::par_empty::ParEmpty, IntoPar};
use orx_concurrent_iter::*;
use std::collections::{
BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque,
};
impl<T: Send + Sync> IntoPar for VecDeque<T> {
type ConIter = ConIterOfIter<T, std::collections::vec_deque::IntoIter<T>>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self.into_iter().into_con_iter())
}
}
impl<T: Send + Sync> IntoPar for BTreeSet<T> {
type ConIter = ConIterOfIter<T, std::collections::btree_set::IntoIter<T>>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self.into_iter().into_con_iter())
}
}
impl<T: Send + Sync> IntoPar for HashSet<T> {
type ConIter = ConIterOfIter<T, std::collections::hash_set::IntoIter<T>>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self.into_iter().into_con_iter())
}
}
impl<K: Send + Sync, V: Send + Sync> IntoPar for BTreeMap<K, V> {
type ConIter = ConIterOfIter<(K, V), std::collections::btree_map::IntoIter<K, V>>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self.into_iter().into_con_iter())
}
}
impl<K: Send + Sync, V: Send + Sync> IntoPar for HashMap<K, V> {
type ConIter = ConIterOfIter<(K, V), std::collections::hash_map::IntoIter<K, V>>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self.into_iter().into_con_iter())
}
}
impl<T: Send + Sync> IntoPar for LinkedList<T> {
type ConIter = ConIterOfIter<T, std::collections::linked_list::IntoIter<T>>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self.into_iter().into_con_iter())
}
}
impl<T: Send + Sync> IntoPar for BinaryHeap<T> {
type ConIter = ConIterOfIter<T, std::collections::binary_heap::IntoIter<T>>;
fn into_par(self) -> ParEmpty<Self::ConIter> {
ParEmpty::new(self.into_iter().into_con_iter())
}
}
}