https://github.com/shiritai/limited-queue
Rust implementation of limited queue library: A circular queue that overrides the oldest element if trying to push data when queue is full
https://github.com/shiritai/limited-queue
circular-queue crate limited-queue rust-library
Last synced: 7 months ago
JSON representation
Rust implementation of limited queue library: A circular queue that overrides the oldest element if trying to push data when queue is full
- Host: GitHub
- URL: https://github.com/shiritai/limited-queue
- Owner: Shiritai
- License: mit
- Created: 2024-07-08T14:00:34.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-07-12T19:07:46.000Z (over 1 year ago)
- Last Synced: 2025-07-03T02:05:36.847Z (7 months ago)
- Topics: circular-queue, crate, limited-queue, rust-library
- Language: Rust
- Homepage: https://crates.io/crates/limited-queue
- Size: 19.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Limited Queue
[](https://crates.io/crates/limited-queue)


[](https://crates.io/crates/limited-queue)
[](LICENSE)
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`.
## Comparison
There is a similar library [`circular-queue`](https://github.com/YaLTeR/circular-queue) I found, but without the basic `peek` and `pop` operations. The comparison for now is listed below:
||[`LimitedQueue`](https://github.com/Shiritai/limited-queue)| [`circular-queue`](https://github.com/YaLTeR/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.
## Setup
Please run `scripts/setup.sh` to setup for committing. Currently, the script registers a git pre-commit hook.