diff --git a/rusty_iterators/iterators/pararell/RATIONALE.md b/rusty_iterators/iterators/pararell/RATIONALE.md new file mode 100644 index 0000000..7e3d919 --- /dev/null +++ b/rusty_iterators/iterators/pararell/RATIONALE.md @@ -0,0 +1,8 @@ +# The general idea behind pararell iteration + +## Sources + +- https://smallcultfollowing.com/babysteps/blog/2016/02/19/parallel-iterators-part-1-foundations/ +- https://smallcultfollowing.com/babysteps/blog/2016/02/25/parallel-iterators-part-2-producers/ +- https://smallcultfollowing.com/babysteps/blog/2016/11/14/parallel-iterators-part-3-consumers/ +- https://geo-ant.github.io/blog/2022/implementing-parallel-iterators-rayon/ diff --git a/rusty_iterators/iterators/pararell/__init__.py b/rusty_iterators/iterators/pararell/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rusty_iterators/iterators/pararell/_bridge.py b/rusty_iterators/iterators/pararell/_bridge.py new file mode 100644 index 0000000..e69de29 diff --git a/rusty_iterators/iterators/pararell/_consumers.py b/rusty_iterators/iterators/pararell/_consumers.py new file mode 100644 index 0000000..3e50277 --- /dev/null +++ b/rusty_iterators/iterators/pararell/_consumers.py @@ -0,0 +1,20 @@ +from __future__ import annotations + +from abc import ABC, abstractmethod +from typing import TYPE_CHECKING, Self + +if TYPE_CHECKING: + from ._folders import FolderInterface + from ._reducers import ReducerInterface + + +class ConsumerInterface[T, R](ABC): + __slots__ = () + + @abstractmethod + def as_folder(self) -> FolderInterface[T, R]: + raise NotImplementedError + + @abstractmethod + def split(self, n: int) -> tuple[Self, Self, ReducerInterface[R]]: + raise NotImplementedError diff --git a/rusty_iterators/iterators/pararell/_folders.py b/rusty_iterators/iterators/pararell/_folders.py new file mode 100644 index 0000000..b37298f --- /dev/null +++ b/rusty_iterators/iterators/pararell/_folders.py @@ -0,0 +1,16 @@ +from __future__ import annotations + +from abc import ABC, abstractmethod +from typing import Self + + +class FolderInterface[T, R](ABC): + __slots__ = () + + @abstractmethod + def consume(self, item: T) -> Self: + raise NotImplementedError + + @abstractmethod + def complete(self) -> R: + raise NotImplementedError diff --git a/rusty_iterators/iterators/pararell/_iter.py b/rusty_iterators/iterators/pararell/_iter.py new file mode 100644 index 0000000..cdb4e50 --- /dev/null +++ b/rusty_iterators/iterators/pararell/_iter.py @@ -0,0 +1,11 @@ +from __future__ import annotations + +from abc import ABC, abstractmethod + + +class PararellIterInterface[T](ABC): + __slots__ = () + + @abstractmethod + def size_hint(self) -> int: + raise NotImplementedError diff --git a/rusty_iterators/iterators/pararell/_producers.py b/rusty_iterators/iterators/pararell/_producers.py new file mode 100644 index 0000000..3a7a314 --- /dev/null +++ b/rusty_iterators/iterators/pararell/_producers.py @@ -0,0 +1,19 @@ +from __future__ import annotations + +from abc import ABC, abstractmethod +from typing import TYPE_CHECKING, Self + +if TYPE_CHECKING: + from rusty_iterators.iterators._sync import IterInterface + + +class ProducerInterface[T](ABC): + __slots__ = () + + @abstractmethod + def as_iter(self) -> IterInterface[T]: + raise NotImplementedError + + @abstractmethod + def split(self, n: int) -> tuple[Self, Self]: + raise NotImplementedError diff --git a/rusty_iterators/iterators/pararell/_reducers.py b/rusty_iterators/iterators/pararell/_reducers.py new file mode 100644 index 0000000..2fdd00e --- /dev/null +++ b/rusty_iterators/iterators/pararell/_reducers.py @@ -0,0 +1,11 @@ +from __future__ import annotations + +from abc import ABC, abstractmethod + + +class ReducerInterface[R](ABC): + __slots__ = () + + @abstractmethod + def reduce(self, left: R, right: R) -> R: + raise NotImplementedError