3 releases

0.1.2 May 15, 2020
0.1.1 May 10, 2020
0.1.0 May 8, 2020

#2275 in Data structures

Download history 32/week @ 2024-07-21 15/week @ 2024-07-28 59/week @ 2024-08-04 2/week @ 2024-08-11 9/week @ 2024-08-18 3/week @ 2024-08-25 22/week @ 2024-09-01 43/week @ 2024-09-08 44/week @ 2024-09-15 55/week @ 2024-09-22 69/week @ 2024-09-29 44/week @ 2024-10-06 75/week @ 2024-10-13 15/week @ 2024-10-20 10/week @ 2024-10-27 138/week @ 2024-11-03

239 downloads per month
Used in 2 crates

MIT license

13KB
279 lines

SlidingWindow crates.io

Sliding windows are used to hold the N most recent samples of a data stream.

Documentation

Example

use sliding_window::*;
use sliding_window::typenum::consts::*;

// Create a SlidingWindow with a window size of 4 elements
let mut sw: SlidingWindow<_, U4> = SlidingWindow::new();

// Insert some data
sw.insert(1);
sw.insert(2);
sw.insert(3);
sw.insert(4);

// The 0 index always returns the oldest element in the window
assert_eq!(1, sw[0]);

// When full, inserting a new element removes and returns the oldest
assert_eq!(Some(1), sw.insert(5));

lib.rs:

This crate provides a heapless, fixed size sliding window.

Sliding windows are used to hold the N most recent samples of a data stream.

Example

use sliding_window::*;
use sliding_window::typenum::consts::*;

// Create a SlidingWindow with a window size of 4 elements
let mut sw: SlidingWindow<_, U4> = SlidingWindow::new();

// Insert some data
sw.insert(1);
sw.insert(2);
sw.insert(3);
sw.insert(4);

// The 0 index always returns the oldest element in the window
assert_eq!(1, sw[0]);

// When full, inserting a new element removes and returns the oldest
assert_eq!(Some(1), sw.insert(5));

Dependencies

~245KB