#sliding #fixed-size #heapless #element #data #index #oldest

no-std sliding_window

固定大小、无堆的滑动窗口

3个版本

0.1.2 2020年5月15日
0.1.1 2020年5月10日
0.1.0 2020年5月8日

#1860数据结构

Download history 3/week @ 2024-01-08 22/week @ 2024-02-19 31/week @ 2024-02-26 10/week @ 2024-03-04 10/week @ 2024-03-11 22/week @ 2024-03-18 19/week @ 2024-03-25

每月下载 61
2 crates 中使用

MIT 许可证

13KB
279

SlidingWindow crates.io

滑动窗口用于存储数据流中最近的N个样本。

文档

示例

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:

此crate提供了一种无堆、固定大小的滑动窗口。

滑动窗口用于存储数据流中最近的N个样本。

示例

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));

依赖关系

~240KB