Struct kalloc::vecque::Vecque [−][src]
pub struct Vecque<T> { /* fields omitted */ }
Expand description
A double-ended queue implemented with two vector.
The “default” usage of this type as a queue is to use push_back
or push_front
to
add to the back or front of the queue, and pop_front
or pop_back
to remove from
the front or back of the queue.
Since Vecque
is simulated by two vector(stack), its elements are not necessarily
contiguous in memory.
Implementations
impl<T> Vecque<T>
[src]
impl<T> Vecque<T>
[src]pub const fn new() -> Self
[src]
pub const fn new() -> Self
[src]Creates an empty Vecque
.
Examples
use kalloc::vecque::Vecque; let vector: Vecque<u32> = Vecque::new();
pub fn reserve(&mut self, additional: usize) -> Result<(), AllocError>
[src]
pub fn reserve(&mut self, additional: usize) -> Result<(), AllocError>
[src]Reserves capacity for at least additional
more elements to be inserted in the given
Vecque
. The collection may reserve more space to avoid frequent reallocations.
Panics
Panics if the new capacity overflows usize
.
Examples
use kalloc::vecque::Vecque; let mut buf = Vecque::new(); buf.push_back(1); buf.reserve(10); assert!(buf.capacity() >= 11);
pub fn with_capacity(capacity: usize) -> Result<Self, AllocError>
[src]
pub fn with_capacity(capacity: usize) -> Result<Self, AllocError>
[src]Creates an empty Vecque
with space for at least capacity
elements.
Examples
use kalloc::vecque::Vecque; let vector: Vecque<u32> = Vecque::with_capacity(10).unwrap();
pub fn get(&self, index: usize) -> Option<&T>
[src]
pub fn get(&self, index: usize) -> Option<&T>
[src]Provides a reference to the element at the given index.
Element at index 0 is the front of the queue.
Examples
use kalloc::vecque::Vecque; let mut buf = Vecque::new(); buf.push_back(3); buf.push_back(4); buf.push_back(5); assert_eq!(buf.get(1), Some(&4));
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
[src]
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
[src]Provides a mutable reference to the element at the given index.
Element at index 0 is the front of the queue.
Examples
use kalloc::vecque::Vecque; let mut buf = Vecque::new(); buf.push_back(3).unwrap(); buf.push_back(4).unwrap(); buf.push_back(5).unwrap(); if let Some(elem) = buf.get_mut(1) { *elem = 7; } assert_eq!(buf[1], 7);
pub fn front(&self) -> Option<&T>
[src]
pub fn front(&self) -> Option<&T>
[src]Provides a reference to the front element, or None
if the Vecque
is
empty.
Examples
use kalloc::vecque::Vecque; let mut d = Vecque::new(); assert_eq!(d.front(), None); d.push_back(1); d.push_back(2); assert_eq!(d.front(), Some(&1));
pub fn front_mut(&mut self) -> Option<&mut T>
[src]
pub fn front_mut(&mut self) -> Option<&mut T>
[src]Provides a mutable reference to the front element, or None
if the
Vecque
is empty.
Examples
use kalloc::vecque::Vecque; let mut d = Vecque::new(); assert_eq!(d.front_mut(), None); d.push_back(1); d.push_back(2); match d.front_mut() { Some(x) => *x = 9, None => (), } assert_eq!(d.front(), Some(&9));
pub fn back(&self) -> Option<&T>
[src]
pub fn back(&self) -> Option<&T>
[src]Provides a reference to the back element, or None
if the Vecque
is
empty.
Examples
use kalloc::vecque::Vecque; let mut d = Vecque::new(); assert_eq!(d.back(), None); d.push_back(1); d.push_back(2); assert_eq!(d.back(), Some(&2));
pub fn back_mut(&mut self) -> Option<&mut T>
[src]
pub fn back_mut(&mut self) -> Option<&mut T>
[src]Provides a mutable reference to the back element, or None
if the
Vecque
is empty.
Examples
use kalloc::vecque::Vecque; let mut d = Vecque::new(); assert_eq!(d.back(), None); d.push_back(1); d.push_back(2); match d.back_mut() { Some(x) => *x = 9, None => (), } assert_eq!(d.back(), Some(&9));
pub fn pop_front(&mut self) -> Option<T>
[src]
pub fn pop_front(&mut self) -> Option<T>
[src]Removes the first element and returns it, or None
if the Vecque
is
empty.
Examples
use kalloc::vecque::Vecque; let mut d = Vecque::new(); d.push_back(1); d.push_back(2); assert_eq!(d.pop_front(), Some(1)); assert_eq!(d.pop_front(), Some(2)); assert_eq!(d.pop_front(), None);
pub fn pop_back(&mut self) -> Option<T>
[src]
pub fn pop_back(&mut self) -> Option<T>
[src]Removes the last element from the Vecque
and returns it, or None
if
it is empty.
Examples
use kalloc::vecque::Vecque; let mut buf = Vecque::new(); assert_eq!(buf.pop_back(), None); buf.push_back(1); buf.push_back(3); assert_eq!(buf.pop_back(), Some(3));
pub fn push_front(&mut self, value: T) -> Result<(), AllocError>
[src]
pub fn push_front(&mut self, value: T) -> Result<(), AllocError>
[src]Prepends an element to the Vecque
.
Examples
use kalloc::vecque::Vecque; let mut d = Vecque::new(); d.push_front(1).unwrap(); d.push_front(2).unwrap(); assert_eq!(d.front(), Some(&2));
pub fn push_back(&mut self, value: T) -> Result<(), AllocError>
[src]
pub fn push_back(&mut self, value: T) -> Result<(), AllocError>
[src]Appends an element to the back of the Vecque
.
Examples
use kalloc::vecque::Vecque; let mut buf = Vecque::new(); buf.push_back(1).unwrap(); buf.push_back(3).unwrap(); assert_eq!(3, *buf.back().unwrap());
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
[src]Returns the number of elements in the Vecque
.
Examples
use kalloc::vecque::Vecque; let mut v = Vecque::new(); assert_eq!(v.len(), 0); v.push_back(1); assert_eq!(v.len(), 1);
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
[src]Returns true
if the Vecque
is empty.
Examples
use kalloc::vecque::Vecque; let mut v = Vecque::new(); assert!(v.is_empty()); v.push_front(1); assert!(!v.is_empty());
pub fn shrink_to_fit(&mut self) -> Result<(), AllocError>
[src]
pub fn shrink_to_fit(&mut self) -> Result<(), AllocError>
[src]Shrinks the capacity of the Vecque
as much as possible.
It will drop down as close as possible to the length but the allocator may still inform the
Vecque
that there is space for a few more elements.
Examples
use kalloc::vecque::Vecque; let mut buf = Vecque::with_capacity(15).unwrap(); buf.push_front(1).unwrap(); assert_eq!(buf.capacity(), 15); buf.shrink_to_fit().unwrap(); assert!(buf.capacity() >= 1);
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Vecque<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Vecque<T> where
T: Send,
T: Send,
impl<T> Sync for Vecque<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Vecque<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Vecque<T> where
T: UnwindSafe,
T: UnwindSafe,