-
-
Notifications
You must be signed in to change notification settings - Fork 0
SlidingWindowIteratorIterator
Class SlidingWindowIteratorIterator.
Provides a sliding window over an iterator with sequential keys.
This iterator returns overlapping windows of elements with keys
starting from 0 and incrementing sequentially.
- Full name:
\FastForward\Iterator\SlidingWindowIteratorIterator - Parent class:
\FastForward\Iterator\CountableIteratorIterator
Initializes the SlidingWindowIteratorIterator.
public __construct(iterable $iterator, int $windowSize): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$iterator |
iterable | the iterator containing values |
$windowSize |
int | the number of elements per window (must be >= 1) |
Throws:
if $windowSize is less than 1
Advances to the next element, maintaining the sliding window.
public next(): voidRetrieves the current sliding window of elements.
public current(): array<int,mixed>Return Value:
the current window of elements
Returns the current sequential key.
public key(): intReturn Value:
the current key, starting from 0
Determines whether the current window is valid.
public valid(): boolThe iterator continues filling the window until the required size is met. If fewer elements than the window size exist, iteration stops.
Return Value:
true if a valid window exists, false otherwise
Resets the iterator, allowing re-iteration.
public rewind(): voidCounts the number of elements in the iterable.
public count(): intIf the inner iterator implements Countable, it uses that. Otherwise, it counts the elements by iterating through them.
Return Value:
the number of elements in the iterable