pub struct CircularQueue<T> { /* private fields */ }Expand description
§About
All functions operate in O(1) time unless otherwise noted.
See the module-level documentation for more information.
Implementations§
Source§impl<T> CircularQueue<T>
impl<T> CircularQueue<T>
Sourcepub fn new(capacity: usize) -> CircularQueue<T>
pub fn new(capacity: usize) -> CircularQueue<T>
Creates a queue that contains (at least) capacity number of elements,
and initializes all positions to None in O(n) time.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the total capacity of the queue.
This is the maximum number of elements the queue can hold, determined at instantiation. It does not reflect the number of currently available slots. To find the number of free slots, subtract the current size from the capacity.
Sourcepub fn enqueue(&mut self, item: T)
pub fn enqueue(&mut self, item: T)
Adds an element to the back of the queue. This operation has no size or
capacity checks for efficiency and performance, may overwrite existing
slots. Use the enqueue_with_check() operation to prevent data overwrites
at the slight performance cost of an additional runtime check.
Sourcepub fn enqueue_with_check(&mut self, item: T) -> Result<(), &str>
pub fn enqueue_with_check(&mut self, item: T) -> Result<(), &str>
Adds an element to the back of the queue. This operation checks that
there is sufficient queue capacity to add an element and errors if you
attempt to add more elements than the queue’s capacity. The
enqueue() operation is slightly more performanant but does not
automatically prevent overwrites.