Struct trait_based_collection::queue::CircularDeque
source · [−]pub struct CircularDeque<T> {
pub mode: ExpansionMode,
/* private fields */
}
Expand description
A circular deque capable of expanding its capacity when needed. It is implemented using Vec
,
so the elements are stored contiguously in memory. The main difference between this and a
Deque
is that this one does not use nodes. This data structure implements both LIFO and
FIFO.
Depending on the expansion mode, once the capacity is reached, the deque will behave differently
depending on the mode. For more information, see the ExpansionMode
documentation.
Examples
use trait_based_collection::{prelude::*, CircularDeque};
let mut deque = CircularDeque::with_mode(2, ExpansionMode::Ignore);
deque.add(1);
deque.add(2);
deque.add(3);
assert_eq!(deque.len(), 2);
assert_eq!(deque.remove(), Some(1));
assert_eq!(deque.remove(), Some(2));
assert_eq!(deque.remove(), None);
Fields
mode: ExpansionMode
The current mode of expansion of the deque that determinate the behaviour the collection is
full. See ExpansionMode
for more information.
Trait Implementations
sourceimpl<'a, T> Collection<'a, T> for CircularDeque<T>where
T: 'a,
impl<'a, T> Collection<'a, T> for CircularDeque<T>where
T: 'a,
sourcefn new_default() -> Self
fn new_default() -> Self
Creates a new
Collection
with a default capacity. Read moresourcefn with_capacity(capacity: usize) -> Self
fn with_capacity(capacity: usize) -> Self
Creates a new
Collection
with a specific capacity. Read moresourcefn with_approximate_capacity(approx_capacity: usize) -> Self
fn with_approximate_capacity(approx_capacity: usize) -> Self
Creates a new
Collection
with a capacity that is at least the specified capacity. Read moresourcefn add(&mut self, value: T)
fn add(&mut self, value: T)
Adds an item to the
Collection
. Read moresourcefn remove(&mut self) -> Option<T>
fn remove(&mut self) -> Option<T>
Removes an item from the
Collection
. Read moresourcefn clear(&mut self)
fn clear(&mut self)
Clears all items from the
Collection
while keeping the capacity. Read moresourcefn peek(&'a self) -> Option<Self::ItemRef>
fn peek(&'a self) -> Option<Self::ItemRef>
Returns an immutable reference of the item that will be removed next. Read more
sourcefn peek_mut(&'a mut self) -> Option<Self::ItemMut>
fn peek_mut(&'a mut self) -> Option<Self::ItemMut>
Returns a mutable reference of the item that will be removed next. Read more
sourcefn get(&'a self, index: usize) -> Option<Self::ItemRef>
fn get(&'a self, index: usize) -> Option<Self::ItemRef>
Returns a immutable reference to the n-th item in the
Collection
. Read moresourcefn get_mut(&'a mut self, index: usize) -> Option<Self::ItemMut>
fn get_mut(&'a mut self, index: usize) -> Option<Self::ItemMut>
Returns a mutable reference to the n-th item in the
Collection
. Read moresourcefn len(&self) -> usize
fn len(&self) -> usize
Returns the number of items in the
Collection
. Read moresourcefn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Checks if the
Collection
is empty. Read moresourceimpl<T: Debug> Debug for CircularDeque<T>
impl<T: Debug> Debug for CircularDeque<T>
sourceimpl<T> Default for CircularDeque<T>
impl<T> Default for CircularDeque<T>
sourceimpl<'a, T> DequeCollection<'a, T> for CircularDeque<T>where
T: 'a,
impl<'a, T> DequeCollection<'a, T> for CircularDeque<T>where
T: 'a,
sourcefn push_front(&mut self, value: T)
fn push_front(&mut self, value: T)
Pushes a new element to the front of the queue. Read more
sourcefn peek_back_mut(&'a mut self) -> Option<Self::ItemMut>
fn peek_back_mut(&'a mut self) -> Option<Self::ItemMut>
sourcefn peek_front(&'a self) -> Option<Self::ItemRef>
fn peek_front(&'a self) -> Option<Self::ItemRef>
sourceimpl<T> Display for CircularDeque<T>where
T: Display,
impl<T> Display for CircularDeque<T>where
T: Display,
sourceimpl<T> Drop for CircularDeque<T>
impl<T> Drop for CircularDeque<T>
sourceimpl<T> Extend<T> for CircularDeque<T>
impl<T> Extend<T> for CircularDeque<T>
sourcefn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<'a, T> FixedSizeCollection<'a, T> for CircularDeque<T>where
T: 'a,
impl<'a, T> FixedSizeCollection<'a, T> for CircularDeque<T>where
T: 'a,
sourcefn with_mode(capacity: usize, mode: ExpansionMode) -> Self
fn with_mode(capacity: usize, mode: ExpansionMode) -> Self
sourcefn capacity(&self) -> usize
fn capacity(&self) -> usize
Returns the maximum amount of items that the collection can hold without expanding. Read more
sourcefn expand(&mut self, extra_size: usize)
fn expand(&mut self, extra_size: usize)
Expands the capacity of the collection by at least the specified amount. This amount or more
will be dded to the capacity. Read more
sourcefn mode(&self) -> &ExpansionMode
fn mode(&self) -> &ExpansionMode
Returns the
ExpansionMode
of the collection . This is used to determine how the
collection will behave when it is full. Read moresourcefn is_full(&self) -> bool
fn is_full(&self) -> bool
Checks if the number of items in the
FixedSizeCollection
is equal to the capacity. Read moresourceimpl<T> FromIterator<T> for CircularDeque<T>
impl<T> FromIterator<T> for CircularDeque<T>
sourcefn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
sourceimpl<T> Index<usize> for CircularDeque<T>
impl<T> Index<usize> for CircularDeque<T>
sourceimpl<T> IndexMut<usize> for CircularDeque<T>
impl<T> IndexMut<usize> for CircularDeque<T>
sourceimpl<'a, T> IntoIterator for &'a CircularDeque<T>
impl<'a, T> IntoIterator for &'a CircularDeque<T>
sourceimpl<'a, T> IntoIterator for &'a mut CircularDeque<T>
impl<'a, T> IntoIterator for &'a mut CircularDeque<T>
sourceimpl<T> IntoIterator for CircularDeque<T>
impl<T> IntoIterator for CircularDeque<T>
sourceimpl<'a, T> Iterators<'a, T> for CircularDeque<T>where
T: 'a,
impl<'a, T> Iterators<'a, T> for CircularDeque<T>where
T: 'a,
type ItemRef = &'a T
type ItemRef = &'a T
The type of reference the immutable iterator (
Iter
) iterates over the items in the
Collection
. The reference is only valid for the duration of the iteration. Read moretype ItemMut = &'a mut T
type ItemMut = &'a mut T
The type of mutable reference the mutable iterator (
IterMut
) iterates over the items in
the Collection
. The reference is only valid for the duration of the iteration. Read moretype Iter = CircularDequeIter<'a, T>
type Iter = CircularDequeIter<'a, T>
type IterMut = CircularDequeIterMut<'a, T>
type IterMut = CircularDequeIterMut<'a, T>
sourcefn iter(&'a self) -> Self::Iter
fn iter(&'a self) -> Self::Iter
Creates an immutable iterator over the items in the
Collection
without consuming them. Read moresourcefn iter_mut(&'a mut self) -> Self::IterMut
fn iter_mut(&'a mut self) -> Self::IterMut
Creates a mutable iterator over the items in the
Collection
without consuming them. Read moreAuto Trait Implementations
impl<T> RefUnwindSafe for CircularDeque<T>where
T: RefUnwindSafe,
impl<T> Send for CircularDeque<T>where
T: Send,
impl<T> Sync for CircularDeque<T>where
T: Sync,
impl<T> Unpin for CircularDeque<T>where
T: Unpin,
impl<T> UnwindSafe for CircularDeque<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more