pub fn window(comptime T: type, buffer: []const T, size: usize, advance: usize) WindowIterator(T)
Returns an iterator with a sliding window of slices for buffer. The sliding window has length size and on every iteration moves forward by advance.
buffer
size
advance
Extract data for moving average with: window(u8, "abcdefg", 3, 1) will return slices "abc", "bcd", "cde", "def", "efg", null, in that order.
window(u8, "abcdefg", 3, 1)
Chunk or split every N items with: window(u8, "abcdefg", 3, 3) will return slices "abc", "def", "g", null, in that order.
window(u8, "abcdefg", 3, 3)
Pick every even index with: window(u8, "abcdefg", 1, 2) will return slices "a", "c", "e", "g" null, in that order.
window(u8, "abcdefg", 1, 2)
The size and advance must be not be zero.
T: type
buffer: []const T
size: usize
advance: usize
3042 3043 3044 3045 3046 3047 3048 3049 3050 3051
pub fn window(comptime T: type, buffer: []const T, size: usize, advance: usize) WindowIterator(T) { assert(size != 0); assert(advance != 0); return .{ .index = if (buffer.len > 0) 0 else null, .buffer = buffer, .size = size, .advance = advance, }; }
Returns an iterator with a sliding window of slices for
buffer. The sliding window has lengthsizeand on every iteration moves forward byadvance.Extract data for moving average with:
window(u8, "abcdefg", 3, 1)will return slices "abc", "bcd", "cde", "def", "efg", null, in that order.Chunk or split every N items with:
window(u8, "abcdefg", 3, 3)will return slices "abc", "def", "g", null, in that order.Pick every even index with:
window(u8, "abcdefg", 1, 2)will return slices "a", "c", "e", "g" null, in that order.The
sizeandadvancemust be not be zero.