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>
impl<T> PopulatedVecDeque<T>
Sourcepub fn new(value: T) -> PopulatedVecDeque<T>
pub fn new(value: T) -> PopulatedVecDeque<T>
Creates a singleton populated deque i.e. a deque with a single element.
Sourcepub fn with_capacity(capacity: NonZeroUsize, value: T) -> PopulatedVecDeque<T>
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.
Sourcepub fn inserted(
vec_deque: VecDeque<T>,
index: usize,
value: T,
) -> PopulatedVecDeque<T>
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));Sourcepub fn get(&self, index: usize) -> Option<&T>
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.
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
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.
Sourcepub fn swap(&mut self, i: usize, j: usize)
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.
pub fn into_inner(self) -> VecDeque<T>
Sourcepub fn pushed_back(vec_deque: VecDeque<T>, value: T) -> PopulatedVecDeque<T>
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);Sourcepub fn pushed_front(value: T, vec_deque: VecDeque<T>) -> PopulatedVecDeque<T>
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);Sourcepub fn push_front(&mut self, value: T)
pub fn push_front(&mut self, value: T)
Prepends an element to the deque.
Sourcepub fn pop_back(self) -> (VecDeque<T>, T)
pub fn pop_back(self) -> (VecDeque<T>, T)
Removes the last element from the deque and returns it, along with the remaining deque.
Sourcepub fn pop_front(self) -> (T, VecDeque<T>)
pub fn pop_front(self) -> (T, VecDeque<T>)
Removes the first element and returns it, along with the remaining deque.
Sourcepub fn len(&self) -> NonZeroUsize
pub fn len(&self) -> NonZeroUsize
Returns number of elements in the populated deque.
Sourcepub fn capacity(&self) -> NonZeroUsize
pub fn capacity(&self) -> NonZeroUsize
Returns the number of elements the deque can hold without reallocating.
pub fn reserve(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>
pub fn shrink_to_fit(&mut self)
pub fn shrink_to(&mut self, min_capacity: usize)
pub fn truncate(&mut self, len: NonZeroUsize)
Sourcepub fn truncate_into(self, len: usize) -> VecDeque<T>
pub fn truncate_into(self, len: usize) -> VecDeque<T>
Truncates the deque to the given length.
Sourcepub fn range(&self, range: impl RangeBounds<usize>) -> Iter<'_, T>
pub fn range(&self, range: impl RangeBounds<usize>) -> Iter<'_, T>
Returns an iterator that yields references to the values.
Sourcepub fn range_mut(&mut self, range: impl RangeBounds<usize>) -> IterMut<'_, T>
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.
Sourcepub fn clear(self) -> VecDeque<T>
pub fn clear(self) -> VecDeque<T>
Clears the deque, removing all values. Returns the cleared deque that is not populated.
Sourcepub fn insert(&mut self, index: usize, element: T)
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.
Sourcepub fn remove(self, index: usize) -> (Option<T>, VecDeque<T>)
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.
Sourcepub fn split_off(&mut self, at: NonZeroUsize) -> VecDeque<T>
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.
pub fn split_into(self, at: usize) -> (VecDeque<T>, VecDeque<T>)
Sourcepub fn append(&mut self, other: &mut VecDeque<T>)
pub fn append(&mut self, other: &mut VecDeque<T>)
Moves all the elements of other into self, leaving other empty.
Sourcepub fn retain(self, f: impl FnMut(&T) -> bool) -> VecDeque<T>
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.
Sourcepub fn retain_mut(self, f: impl FnMut(&mut T) -> bool) -> VecDeque<T>
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.
pub fn resize_with(&mut self, new_len: NonZeroUsize, f: impl FnMut() -> T)
pub fn resize_with_into( self, new_len: usize, f: impl FnMut() -> T, ) -> VecDeque<T>
Sourcepub fn rotate_left(&mut self, n: usize)
pub fn rotate_left(&mut self, n: usize)
Rotates the double-ended queue n places to the left.
Equivalently,
- Rotates item
ninto the first position. - Pops the first
nitems and pushes them to the end. - Rotates
len() - nplaces to the right.
Sourcepub fn rotate_right(&mut self, n: usize)
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
nitems and pushes them to the front. - Rotates
len() - nplaces to the left.
Sourcepub fn binary_search_by(
&self,
f: impl FnMut(&T) -> Ordering,
) -> Result<usize, usize>
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.
Sourcepub fn binary_search_by_key<K: Ord>(
&self,
key: &K,
f: impl FnMut(&T) -> K,
) -> Result<usize, usize>
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.
pub fn partition_point(&self, predicate: impl FnMut(&T) -> bool) -> usize
Source§impl<T: PartialEq> PopulatedVecDeque<T>
impl<T: PartialEq> PopulatedVecDeque<T>
Source§impl<T: Ord> PopulatedVecDeque<T>
impl<T: Ord> PopulatedVecDeque<T>
Sourcepub fn binary_search(&self, x: &T) -> Result<usize, usize>
pub fn binary_search(&self, x: &T) -> Result<usize, usize>
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>
impl<T: Clone> PopulatedVecDeque<T>
pub fn resize(&mut self, new_len: NonZeroUsize, value: T)
pub fn resize_into(self, new_len: usize, value: T) -> VecDeque<T>
Source§impl<T> PopulatedVecDeque<T>
impl<T> PopulatedVecDeque<T>
pub fn iter(&self) -> PopulatedIter<'_, T>
pub fn iter_mut(&mut self) -> PopulatedIterMut<'_, T>
Trait Implementations§
Source§impl<T: Clone> Clone for PopulatedVecDeque<T>
impl<T: Clone> Clone for PopulatedVecDeque<T>
Source§fn clone(&self) -> PopulatedVecDeque<T>
fn clone(&self) -> PopulatedVecDeque<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for PopulatedVecDeque<T>
impl<T: Debug> Debug for PopulatedVecDeque<T>
Source§impl<T> Extend<T> for PopulatedVecDeque<T>
impl<T> Extend<T> for PopulatedVecDeque<T>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T> From<PopulatedVec<T>> for PopulatedVecDeque<T>
impl<T> From<PopulatedVec<T>> for PopulatedVecDeque<T>
Source§fn from(populated_vec: PopulatedVec<T>) -> PopulatedVecDeque<T>
fn from(populated_vec: PopulatedVec<T>) -> PopulatedVecDeque<T>
Source§impl<T> From<PopulatedVecDeque<T>> for VecDeque<T>
impl<T> From<PopulatedVecDeque<T>> for VecDeque<T>
Source§fn from(populated_vec_deque: PopulatedVecDeque<T>) -> VecDeque<T>
fn from(populated_vec_deque: PopulatedVecDeque<T>) -> VecDeque<T>
Source§impl<T> FromPopulatedIterator<T> for PopulatedVecDeque<T>
impl<T> FromPopulatedIterator<T> for PopulatedVecDeque<T>
Source§fn from_populated_iter(iter: impl IntoPopulatedIterator<Item = T>) -> Self
fn from_populated_iter(iter: impl IntoPopulatedIterator<Item = T>) -> Self
PopulatedIterator into Self.Source§impl<T> Index<usize> for PopulatedVecDeque<T>
impl<T> Index<usize> for PopulatedVecDeque<T>
Source§impl<T> IndexMut<usize> for PopulatedVecDeque<T>
impl<T> IndexMut<usize> for PopulatedVecDeque<T>
Source§impl<'a, T> IntoIterator for &'a PopulatedVecDeque<T>
impl<'a, T> IntoIterator for &'a PopulatedVecDeque<T>
Source§impl<'a, T> IntoIterator for &'a mut PopulatedVecDeque<T>
impl<'a, T> IntoIterator for &'a mut PopulatedVecDeque<T>
Source§impl<T> IntoIterator for PopulatedVecDeque<T>
impl<T> IntoIterator for PopulatedVecDeque<T>
Source§impl<'a, T> IntoPopulatedIterator for &'a PopulatedVecDeque<T>
impl<'a, T> IntoPopulatedIterator for &'a PopulatedVecDeque<T>
type PopulatedIntoIter = PopulatedIter<'a, T>
Source§fn into_populated_iter(self) -> PopulatedIter<'a, T>
fn into_populated_iter(self) -> PopulatedIter<'a, T>
PopulatedIterator.Source§impl<'a, T> IntoPopulatedIterator for &'a mut PopulatedVecDeque<T>
impl<'a, T> IntoPopulatedIterator for &'a mut PopulatedVecDeque<T>
type PopulatedIntoIter = PopulatedIterMut<'a, T>
Source§fn into_populated_iter(self) -> PopulatedIterMut<'a, T>
fn into_populated_iter(self) -> PopulatedIterMut<'a, T>
PopulatedIterator.Source§impl<T> IntoPopulatedIterator for PopulatedVecDeque<T>
impl<T> IntoPopulatedIterator for PopulatedVecDeque<T>
type PopulatedIntoIter = PopulatedIntoIter<T>
Source§fn into_populated_iter(self) -> PopulatedIntoIter<T>
fn into_populated_iter(self) -> PopulatedIntoIter<T>
PopulatedIterator.