Struct CircularQueue

Source
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>

Source

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.

Source

pub fn front(&self) -> usize

Returns the index representing the front of the queue.

Source

pub fn back(&self) -> usize

Returns the index representing the back of the queue.

Source

pub fn size(&self) -> usize

Returns the number of elements in the queue.

Source

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.

Source

pub fn peek(&self) -> Option<&T>

Returns a reference to the front of the queue.

Source

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.

Source

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.

Source

pub fn dequeue(&mut self) -> Option<T>

Removes and returns the front element of the queue, if an element exists.

Auto Trait Implementations§

§

impl<T> Freeze for CircularQueue<T>

§

impl<T> RefUnwindSafe for CircularQueue<T>
where T: RefUnwindSafe,

§

impl<T> Send for CircularQueue<T>
where T: Send,

§

impl<T> Sync for CircularQueue<T>
where T: Sync,

§

impl<T> Unpin for CircularQueue<T>
where T: Unpin,

§

impl<T> UnwindSafe for CircularQueue<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V