Method SlidingWindow
- Namespace
- Gamelogic.Extensions.Algorithms
- Assembly
- Gamelogic.Extensions.dll
SlidingWindow<T>(IEnumerable<T>, int)
Gives sliding window of the given size over the source.
public static IEnumerable<IReadOnlyBuffer<T>> SlidingWindow<T>(this IEnumerable<T> source, int windowSize)
Parameters
source
IEnumerable<T>The source to slide over.
windowSize
intThe size of the window. Must be positive.
Returns
- IEnumerable<IReadOnlyBuffer<T>>
An IEnumerable<T> of buffers of the given size. Each item represents a window at a certain position. Only full windows are returned. Suppose the source is the sequence 1, 2, 3, 4, 5. If we run the sliding window width a size of three, we get the sequences (1, 2, 3), (2, 3, 4), (3, 4, 5).
Type Parameters
T
The type of elements in the source.
Exceptions
- ArgumentOutOfRangeException
The
windowSize
is not positive.