Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions rusty_iterators/iterators/pararell/RATIONALE.md
Original file line number Diff line number Diff line change
@@ -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/
Empty file.
Empty file.
20 changes: 20 additions & 0 deletions rusty_iterators/iterators/pararell/_consumers.py
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions rusty_iterators/iterators/pararell/_folders.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions rusty_iterators/iterators/pararell/_iter.py
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions rusty_iterators/iterators/pararell/_producers.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions rusty_iterators/iterators/pararell/_reducers.py
Original file line number Diff line number Diff line change
@@ -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
Loading