Crates.io | ringvec |
lib.rs | ringvec |
version | 0.1.0 |
source | src |
created_at | 2021-08-26 07:43:00.514607 |
updated_at | 2021-08-26 07:43:00.514607 |
description | A simple ring buffer implementation based on a vector |
homepage | https://github.com/stjepangolemac/ringvec |
repository | https://github.com/stjepangolemac/ringvec |
max_upload_size | |
id | 442478 |
size | 9,492 |
A simple ring buffer implementation based on a vector. No dependencies except criterion for benchmarking.
use ringvec::RingVec;
fn main() {
let mut v = RingVec::new(3);
assert!(v.is_empty());
assert!(!v.is_full());
v.push(1);
v.push(2);
v.push(3);
v.push_force(4);
v.push_force(5);
assert!(!v.is_empty());
assert!(v.is_full());
assert_eq!(v.peek_oldest(), Some(&3));
assert_eq!(v.peek_newest(), Some(&5));
assert_eq!(v.pop(), Some(3));
assert!(!v.is_empty());
assert!(!v.is_full());
assert_eq!(v.pop(), Some(4));
assert_eq!(v.pop(), Some(5));
assert!(v.is_empty());
assert!(!v.is_full());
}
It's optimized for peeking, but not slow when pushing too. I might've messed something up when it comes to benchmarking peeking.