PopulatedVecDeque

Struct PopulatedVecDeque 

Source
pub struct PopulatedVecDeque<T>(/* private fields */);
Expand description

A populated double-ended queue implemented with a growable ring buffer. This type is guaranteed to contain at least one element, so the underlying VecDeque is guaranteed to be non-empty.

Implementations§

Source§

impl<T> PopulatedVecDeque<T>

Source

pub fn new(value: T) -> PopulatedVecDeque<T>

Creates a singleton populated deque i.e. a deque with a single element.

Source

pub fn with_capacity(capacity: NonZeroUsize, value: T) -> PopulatedVecDeque<T>

Creates a populated deque with a single element and space for at least capacity elements.

Source

pub fn inserted( vec_deque: VecDeque<T>, index: usize, value: T, ) -> PopulatedVecDeque<T>

Creates a populated deque with the given element inserted at the specified index.

use std::collections::VecDeque;
use std::num::NonZeroUsize;
use populated::PopulatedVecDeque;

let vec_deque = vec![1].into();
let vec_deque = PopulatedVecDeque::inserted(vec_deque, 0, 2);
assert_eq!(vec_deque.get(0), Some(&2));
assert_eq!(vec_deque.get(1), Some(&1));
Source

pub fn get(&self, index: usize) -> Option<&T>

Provides a reference to the element at the given index.

Element at index 0 is the front of the queue.

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>

Provides a mutable reference to the element at the given index.

Element at index 0 is the front of the queue.

Source

pub fn swap(&mut self, i: usize, j: usize)

Swaps elements at indices i and j.

i and j may be equal.

Element at index 0 is the front of the queue.

Source

pub fn into_inner(self) -> VecDeque<T>

Source

pub fn pushed_back(vec_deque: VecDeque<T>, value: T) -> PopulatedVecDeque<T>

Constructs a PopulatedVecDeque from a VecDeque by pushing back a single element.

use std::collections::VecDeque;
use std::num::NonZeroUsize;
use populated::PopulatedVecDeque;

let vec_deque = VecDeque::from([1, 2, 3]);
let populated_vec_deque = PopulatedVecDeque::pushed_back(vec_deque, 42);
assert_eq!(populated_vec_deque.len(), NonZeroUsize::new(4).unwrap());
assert_eq!(populated_vec_deque.back(), &42);
Source

pub fn push_back(&mut self, value: T)

Appends an element to the back of the deque.

Source

pub fn pushed_front(value: T, vec_deque: VecDeque<T>) -> PopulatedVecDeque<T>

Constructs a PopulatedVecDeque from a VecDeque by pushing front a single element.

use std::collections::VecDeque;
use std::num::NonZeroUsize;
use populated::PopulatedVecDeque;

let vec_deque = VecDeque::from([1, 2, 3]);
let populated_vec_deque = PopulatedVecDeque::pushed_front(42, vec_deque);
assert_eq!(populated_vec_deque.len(), NonZeroUsize::new(4).unwrap());
assert_eq!(populated_vec_deque.front(), &42);
Source

pub fn push_front(&mut self, value: T)

Prepends an element to the deque.

Source

pub fn pop_back(self) -> (VecDeque<T>, T)

Removes the last element from the deque and returns it, along with the remaining deque.

Source

pub fn pop_front(self) -> (T, VecDeque<T>)

Removes the first element and returns it, along with the remaining deque.

Source

pub fn front(&self) -> &T

Provides a reference to the front element.

Source

pub fn front_mut(&mut self) -> &mut T

Provides a mutable reference to the front element.

Source

pub fn back(&self) -> &T

Provides a reference to the back element.

Source

pub fn back_mut(&mut self) -> &mut T

Provides a mutable reference to the back element.

Source

pub fn len(&self) -> NonZeroUsize

Returns number of elements in the populated deque.

Source

pub fn capacity(&self) -> NonZeroUsize

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

Source

pub fn reserve(&mut self, additional: usize)

Source

pub fn reserve_exact(&mut self, additional: usize)

Source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

Source

pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>

Source

pub fn shrink_to_fit(&mut self)

Source

pub fn shrink_to(&mut self, min_capacity: usize)

Source

pub fn truncate(&mut self, len: NonZeroUsize)

Source

pub fn truncate_into(self, len: usize) -> VecDeque<T>

Truncates the deque to the given length.

Source

pub fn range(&self, range: impl RangeBounds<usize>) -> Iter<'_, T>

Returns an iterator that yields references to the values.

Source

pub fn range_mut(&mut self, range: impl RangeBounds<usize>) -> IterMut<'_, T>

Returns an iterator that allows modifying each value. The iterator yields mutable references to the values.

Source

pub fn clear(self) -> VecDeque<T>

Clears the deque, removing all values. Returns the cleared deque that is not populated.

Source

pub fn insert(&mut self, index: usize, element: T)

Inserts an element at index within the deque, shifting all elements with indices greater than or equal to index towards the back.

Element at index 0 is the front of the queue.

Source

pub fn remove(self, index: usize) -> (Option<T>, VecDeque<T>)

Removes and returns the element at index from the deque. Whichever end is closer to the removal point will be moved to make room, and all the affected elements will be moved to new positions. Returns None if index is out of bounds.

Element at index 0 is the front of the queue.

Source

pub fn split_off(&mut self, at: NonZeroUsize) -> VecDeque<T>

Splits the deque into two at the given index.

Returns a newly allocated VecDeque. self contains elements [0, at), and the returned deque contains elements [at, len).

at must be non-zero to ensure that the deque being mutated stays populated.

Note that the capacity of self does not change.

Element at index 0 is the front of the queue.

Source

pub fn split_into(self, at: usize) -> (VecDeque<T>, VecDeque<T>)

Source

pub fn append(&mut self, other: &mut VecDeque<T>)

Moves all the elements of other into self, leaving other empty.

Source

pub fn retain(self, f: impl FnMut(&T) -> bool) -> VecDeque<T>

Retains only the elements specified by the predicate.

In other words, remove all elements e for which f(&e) returns false. This method operates in place on the underlying VecDeque, visiting each element exactly once in the original order, and preserves the order of the retained elements.

Since there is no guarantee that all elements will not be removed, the method returns the underlying VecDeque.

Source

pub fn retain_mut(self, f: impl FnMut(&mut T) -> bool) -> VecDeque<T>

Retains only the elements specified by the predicate.

In other words, remove all elements e for which f(&e) returns false. This method operates in place on the underlying VecDeque, visiting each element exactly once in the original order, and preserves the order of the retained elements.

Since there is no guarantee that all elements will not be removed, the method returns the underlying VecDeque.

Source

pub fn resize_with(&mut self, new_len: NonZeroUsize, f: impl FnMut() -> T)

Source

pub fn resize_with_into( self, new_len: usize, f: impl FnMut() -> T, ) -> VecDeque<T>

Source

pub fn rotate_left(&mut self, n: usize)

Rotates the double-ended queue n places to the left.

Equivalently,

  • Rotates item n into the first position.
  • Pops the first n items and pushes them to the end.
  • Rotates len() - n places to the right.
Source

pub fn rotate_right(&mut self, n: usize)

Rotates the double-ended queue n places to the right.

Equivalently,

  • Rotates the first item into position n.
  • Pops the last n items and pushes them to the front.
  • Rotates len() - n places to the left.
Source

pub fn binary_search_by( &self, f: impl FnMut(&T) -> Ordering, ) -> Result<usize, usize>

Binary searches this PopulatedVecDeque with a comparator function.

The comparator function should return an order code that indicates whether its argument is Less, Equal or Greater the desired target. If the PopulatedVecDeque is not sorted or if the comparator function does not implement an order consistent with the sort order of the underlying VecDeque, the returned result is unspecified and meaningless.

If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. If the value is not found then Result::Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.

See also binary_search, binary_search_by_key, and partition_point.

Source

pub fn binary_search_by_key<K: Ord>( &self, key: &K, f: impl FnMut(&T) -> K, ) -> Result<usize, usize>

Binary searches this PopulatedVecDeque with a key extraction function.

Assumes that the deque is sorted by the key, for instance with make_contiguous().sort_by_key() using the same key extraction function. If the deque is not sorted by the key, the returned result is unspecified and meaningless.

If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. If the value is not found then Result::Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.

See also binary_search, binary_search_by, and partition_point.

Source

pub fn partition_point(&self, predicate: impl FnMut(&T) -> bool) -> usize

Source§

impl<T: PartialEq> PopulatedVecDeque<T>

Source

pub fn contains(&self, x: &T) -> bool

Returns true if the deque contains an element equal to the given value.

This operation is O(n).

Note that if you have a sorted PopulatedVecDeque, binary_search may be faster.

Source§

impl<T: Ord> PopulatedVecDeque<T>

Binary searches this PopulatedVecDeque for a given element. If the PopulatedVecDeque is not sorted, the returned result is unspecified and meaningless.

If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. If the value is not found then Result::Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.

See also binary_search_by, binary_search_by_key, and partition_point.

Source§

impl<T: Clone> PopulatedVecDeque<T>

Source

pub fn resize(&mut self, new_len: NonZeroUsize, value: T)

Source

pub fn resize_into(self, new_len: usize, value: T) -> VecDeque<T>

Source§

impl<T> PopulatedVecDeque<T>

Source

pub fn iter(&self) -> PopulatedIter<'_, T>

Source

pub fn iter_mut(&mut self) -> PopulatedIterMut<'_, T>

Trait Implementations§

Source§

impl<T: Clone> Clone for PopulatedVecDeque<T>

Source§

fn clone(&self) -> PopulatedVecDeque<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for PopulatedVecDeque<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Extend<T> for PopulatedVecDeque<T>

Source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

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

impl<T> From<PopulatedVec<T>> for PopulatedVecDeque<T>

Source§

fn from(populated_vec: PopulatedVec<T>) -> PopulatedVecDeque<T>

Converts to this type from the input type.
Source§

impl<T> From<PopulatedVecDeque<T>> for VecDeque<T>

Source§

fn from(populated_vec_deque: PopulatedVecDeque<T>) -> VecDeque<T>

Converts to this type from the input type.
Source§

impl<T> FromPopulatedIterator<T> for PopulatedVecDeque<T>

Source§

fn from_populated_iter(iter: impl IntoPopulatedIterator<Item = T>) -> Self

Converts a PopulatedIterator into Self.
Source§

impl<T> Index<NonZero<usize>> for PopulatedVecDeque<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: NonZeroUsize) -> &Self::Output

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

impl<T> Index<usize> for PopulatedVecDeque<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

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

impl<T> IndexMut<NonZero<usize>> for PopulatedVecDeque<T>

Source§

fn index_mut(&mut self, index: NonZeroUsize) -> &mut Self::Output

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

impl<T> IndexMut<usize> for PopulatedVecDeque<T>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

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

impl<'a, T> IntoIterator for &'a PopulatedVecDeque<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for &'a mut PopulatedVecDeque<T>

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for PopulatedVecDeque<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoPopulatedIterator for &'a PopulatedVecDeque<T>

Source§

type PopulatedIntoIter = PopulatedIter<'a, T>

Source§

fn into_populated_iter(self) -> PopulatedIter<'a, T>

Converts the type into a PopulatedIterator.
Source§

impl<'a, T> IntoPopulatedIterator for &'a mut PopulatedVecDeque<T>

Source§

type PopulatedIntoIter = PopulatedIterMut<'a, T>

Source§

fn into_populated_iter(self) -> PopulatedIterMut<'a, T>

Converts the type into a PopulatedIterator.
Source§

impl<T> IntoPopulatedIterator for PopulatedVecDeque<T>

Source§

type PopulatedIntoIter = PopulatedIntoIter<T>

Source§

fn into_populated_iter(self) -> PopulatedIntoIter<T>

Converts the type into a PopulatedIterator.
Source§

impl<T: Ord> Ord for PopulatedVecDeque<T>

Source§

fn cmp(&self, other: &PopulatedVecDeque<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq> PartialEq<PopulatedVecDeque<T>> for VecDeque<T>

Source§

fn eq(&self, other: &PopulatedVecDeque<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialEq> PartialEq<VecDeque<T>> for PopulatedVecDeque<T>

Source§

fn eq(&self, other: &VecDeque<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialEq> PartialEq for PopulatedVecDeque<T>

Source§

fn eq(&self, other: &PopulatedVecDeque<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for PopulatedVecDeque<T>

Source§

fn partial_cmp(&self, other: &PopulatedVecDeque<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> TryFrom<VecDeque<T>> for PopulatedVecDeque<T>

Source§

type Error = VecDeque<T>

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

fn try_from(vec_deque: VecDeque<T>) -> Result<PopulatedVecDeque<T>, Self::Error>

Performs the conversion.
Source§

impl<T: Eq> Eq for PopulatedVecDeque<T>

Source§

impl<T> StructuralPartialEq for PopulatedVecDeque<T>

Auto Trait Implementations§

§

impl<T> Freeze for PopulatedVecDeque<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for PopulatedVecDeque<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.