Crates.io | limited-queue |
lib.rs | limited-queue |
version | 0.1.5 |
source | src |
created_at | 2024-07-08 14:17:06.354883 |
updated_at | 2024-07-12 19:08:01.716794 |
description | a limited queue that overrides the oldest data if trying to push a data when the queue is full. |
homepage | |
repository | |
max_upload_size | |
id | 1296005 |
size | 15,975 |
A circular queue that overrides the oldest data if trying to push a data when the queue is full.
All operations are of O(1)
complexity, except the constructor with O(Vec::with_capacity)
.
The optional method pop
is provided when T
satisfies trait bound Default
.
There is a similar library circular-queue
I found, but without the basic peek
and pop
operations. The comparison for now is listed below:
LimitedQueue |
circular-queue |
|
---|---|---|
Algorithm | circular queue (front-rear, without additional element slot) | circular queue (based on len and capacity provided by Vec ) |
Element trait bound needed | No, optionally Default for pop method |
- |
push , size-related methods |
✅ | ✅ |
peek , pop support |
✅: peek ✅: pop for T: Default |
❌ |
Indexing | ✅ - [0, len) - support [idx] - support get(idx) - optionally mutable ( [idx] ) |
❌ |
Iterator | ✅ - front to rear |
✅ - both ways - optionally mutable |
clear complexity |
O(1) |
O(Vec::clear) |
serde support |
❌ (TODO) | ✅ |
We welcome any kinds of contributions, please don't be hesitate to submit issues & PRs.
Please run scripts/setup.sh
to setup for committing. Currently, the script registers a git pre-commit hook.