double_vec_queue-0.1.0 has been yanked.
double_vec_queue
A simple queue implementation using two vectors for efficient FIFO operations.
Overview
This crate provides a Queue<T> data structure that uses a dual-vector approach:
- Inbox: stores newly pushed elements
- Outbox: stores elements ready to be popped (in reverse order for efficient access)
This design enables amortized O(1) push and pop operations while minimizing allocations.
Features
- Generic queue implementation for any type
T - Efficient push/pop operations with amortized O(1) complexity
- Support for peeking at the front element
- Iteration support (by value, reference, and mutable reference)
- Conversion from
Vec<T> - Standard Rust iterator traits
Usage
Add this to your Cargo.toml:
[]
= "0.1"
Examples
Basic Operations
use Queue;
let mut queue = new;
// Push elements
queue.push;
queue.push;
queue.push;
// Pop elements (FIFO order)
assert_eq!;
assert_eq!;
// Peek at the front
assert_eq!;
// Pop the remaining element
assert_eq!;
assert_eq!;
Creating from a Vec
use Queue;
let queue = from_vec;
Iteration
use Queue;
let mut queue = from_vec;
// Iterate by reference
for item in &queue
// Iterate by mutable reference
for item in &mut queue
// Iterate by value (consumes queue)
for item in queue
Implementation Details
The queue uses a dual-vector strategy where:
- Elements are pushed into the
inboxvector - When popping, if the
outboxis empty, all elements frominboxare moved tooutboxin reverse order - This provides amortized O(1) time complexity for both push and pop operations
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.