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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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);

pub fn capacity(&self) -> usize[src]

Returns the number of elements the VecDeque can hold without reallocating.

Examples

use kalloc::vecque::Vecque;

let buf: Vecque<i32> = Vecque::with_capacity(10).unwrap();
assert!(buf.capacity() >= 10);

Trait Implementations

impl<T> Default for Vecque<T>[src]

fn default() -> Vecque<T>[src]

Creates an empty VecDeque<T>.

impl<T> Index<usize> for Vecque<T>[src]

type Output = T

The returned type after indexing.

fn index(&self, index: usize) -> &T[src]

Performs the indexing (container[index]) operation. Read more

impl<T> IndexMut<usize> for Vecque<T>[src]

fn index_mut(&mut self, index: usize) -> &mut T[src]

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations

impl<T> RefUnwindSafe for Vecque<T> where
    T: RefUnwindSafe

impl<T> Send for Vecque<T> where
    T: Send

impl<T> Sync for Vecque<T> where
    T: Sync

impl<T> Unpin for Vecque<T> where
    T: Unpin

impl<T> UnwindSafe for Vecque<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.