Crates.io | squeue |
lib.rs | squeue |
version | 0.10.3 |
source | src |
created_at | 2023-02-02 07:32:01.081739 |
updated_at | 2024-03-17 14:46:41.184107 |
description | SQueue is a sized queue. |
homepage | https://gitlab.com/liberecofr/squeue |
repository | https://gitlab.com/liberecofr/squeue/tree/main |
max_upload_size | |
id | 774594 |
size | 43,581 |
SQueue is a sized queue implemented in Rust.
This is just a simple wrapper over a standard Rust VecDeque. It makes a few opinionated choices, so as to choose whether one should pop/push on front/back, and trims the API to the minimum so that it can only serve as a simple FIFO queue.
The main difference between this and using a standard queue, is that this one is capped in size, and will drop the oldest items when pushing more than its allowed capacity.
On top of this, provides a sync thread-safe implementation, which can be shared between threads. But nothing crazy, just a simple wrapper, really.
Project spawned from HashLRU.
SQueue is between the toy project and something you could use. It comes with with a rather complete test harness and tries to have reasonable documentation, so that's a plus. OTOH it is quite young, and to my knowledge not used in production anywhere.
In doubt, use vanilla VecDeque.
use squeue::Queue;
let mut queue: Queue<usize> = Queue::new(3);
assert_eq!(None, queue.push(1));
assert_eq!(None, queue.push(2));
assert_eq!(None, queue.push(3));
assert_eq!(Some(1), queue.push(4));
assert_eq!(3, queue.len());
Taken from a random CI job:
running 6 tests
test tests::bench_read_usize_builtin_vecdeque ... bench: 0 ns/iter (+/- 0)
test tests::bench_read_usize_squeue_queue ... bench: 0 ns/iter (+/- 0)
test tests::bench_read_usize_squeue_sync_queue ... bench: 16 ns/iter (+/- 0)
test tests::bench_write_usize_builtin_vecdeque ... bench: 10 ns/iter (+/- 28)
test tests::bench_write_usize_squeue_queue ... bench: 3 ns/iter (+/- 0)
test tests::bench_write_usize_squeue_sync_queue ... bench: 21 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 6 measured; 0 filtered out; finished in 11.75s
Not the results of thorough intensive benchmarking but the general idea is:
To run the benchmarks:
cd bench
rustup default nightly
cargo bench
SQueue is licensed under the MIT license.