From 1b6a04ca5504955c571d1c97504fb45ea0befee4 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 8 Jan 2024 01:21:28 +0400 Subject: Initial vendor packages Signed-off-by: Valentin Popov --- vendor/rayon/src/iter/sum.rs | 110 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 vendor/rayon/src/iter/sum.rs (limited to 'vendor/rayon/src/iter/sum.rs') diff --git a/vendor/rayon/src/iter/sum.rs b/vendor/rayon/src/iter/sum.rs new file mode 100644 index 0000000..ddae810 --- /dev/null +++ b/vendor/rayon/src/iter/sum.rs @@ -0,0 +1,110 @@ +use super::plumbing::*; +use super::ParallelIterator; + +use std::iter::{self, Sum}; +use std::marker::PhantomData; + +pub(super) fn sum(pi: PI) -> S +where + PI: ParallelIterator, + S: Send + Sum + Sum, +{ + pi.drive_unindexed(SumConsumer::new()) +} + +fn add(left: T, right: T) -> T { + [left, right].into_iter().sum() +} + +struct SumConsumer { + _marker: PhantomData<*const S>, +} + +unsafe impl Send for SumConsumer {} + +impl SumConsumer { + fn new() -> SumConsumer { + SumConsumer { + _marker: PhantomData, + } + } +} + +impl Consumer for SumConsumer +where + S: Send + Sum + Sum, +{ + type Folder = SumFolder; + type Reducer = Self; + type Result = S; + + fn split_at(self, _index: usize) -> (Self, Self, Self) { + (SumConsumer::new(), SumConsumer::new(), SumConsumer::new()) + } + + fn into_folder(self) -> Self::Folder { + SumFolder { + sum: iter::empty::().sum(), + } + } + + fn full(&self) -> bool { + false + } +} + +impl UnindexedConsumer for SumConsumer +where + S: Send + Sum + Sum, +{ + fn split_off_left(&self) -> Self { + SumConsumer::new() + } + + fn to_reducer(&self) -> Self::Reducer { + SumConsumer::new() + } +} + +impl Reducer for SumConsumer +where + S: Send + Sum, +{ + fn reduce(self, left: S, right: S) -> S { + add(left, right) + } +} + +struct SumFolder { + sum: S, +} + +impl Folder for SumFolder +where + S: Sum + Sum, +{ + type Result = S; + + fn consume(self, item: T) -> Self { + SumFolder { + sum: add(self.sum, iter::once(item).sum()), + } + } + + fn consume_iter(self, iter: I) -> Self + where + I: IntoIterator, + { + SumFolder { + sum: add(self.sum, iter.into_iter().sum()), + } + } + + fn complete(self) -> S { + self.sum + } + + fn full(&self) -> bool { + false + } +} -- cgit v1.2.3