https://github.com/bugadani/slidingwindow
Rust implementation of a sliding window
https://github.com/bugadani/slidingwindow
Last synced: about 1 year ago
JSON representation
Rust implementation of a sliding window
- Host: GitHub
- URL: https://github.com/bugadani/slidingwindow
- Owner: bugadani
- License: mit
- Created: 2020-05-04T07:46:00.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-15T12:33:24.000Z (about 6 years ago)
- Last Synced: 2025-04-09T07:41:34.777Z (about 1 year ago)
- Language: Rust
- Size: 26.4 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
SlidingWindow [](https://crates.io/crates/sliding_window)
=============
Sliding windows are used to hold the N most recent samples of a data stream.
[Documentation](https://docs.rs/sliding_window/0.1.0/sliding_window/)
Example
-------
```rust
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));
```