-
-
Notifications
You must be signed in to change notification settings - Fork 0
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 exposed by the inner iterator.
public count(): intIf the inner iterator implements
-
See: \Countable, this method SHALL return the value provided by that implementation. Otherwise, it MUST count elements by iterating over the iterator. If the inner iterator is not cloneable, this method SHALL wrap the current object in an
-
See: \IteratorIterator instance and count through that wrapper to avoid performing an invalid clone operation. If the inner iterator is cloneable, this method SHOULD count over a clone so that the original iterator state is preserved as much as possible.
Return Value:
the total number of elements available from the inner iterator