pub struct CyclicArray<T> { /* private fields */ }Expand description
Basic circular buffer, or what Goodrich and Kloss call a circular deque.
This implementation allows push and pop from both ends of the buffer and supports insert and remove from arbitrary offsets.
Unlike the VecDeque in the standard library, this array has a fixed size
and will panic if a push is performed while the array is already full.
Implementations§
Source§impl<T> CyclicArray<T>
impl<T> CyclicArray<T>
Sourcepub fn combine(a: CyclicArray<T>, b: CyclicArray<T>) -> Self
pub fn combine(a: CyclicArray<T>, b: CyclicArray<T>) -> Self
Take the elements from the two other cyclic arrays into a new cyclic array with the combined capacity.
Sourcepub fn from(capacity: usize, other: CyclicArray<T>) -> Self
pub fn from(capacity: usize, other: CyclicArray<T>) -> Self
Take the elements from the other cyclic array into a new cyclic array with the given capacity.
Sourcepub fn split(self) -> (CyclicArray<T>, CyclicArray<T>)
pub fn split(self) -> (CyclicArray<T>, CyclicArray<T>)
Split this cyclic buffer into two equal sized buffers.
The second buffer may be empty if all elements fit within the first buffer.
Sourcepub fn push_front(&mut self, value: T)
pub fn push_front(&mut self, value: T)
Sourcepub fn pop_back(&mut self) -> Option<T>
pub fn pop_back(&mut self) -> Option<T>
Removes the last element and returns it, or None if the cyclic array
is empty.
Sourcepub fn pop_front(&mut self) -> Option<T>
pub fn pop_front(&mut self) -> Option<T>
Removes the first element and returns it, or None if the cyclic array
is empty.
Sourcepub fn insert(&mut self, index: usize, value: T)
pub fn insert(&mut self, index: usize, value: T)
Inserts an element at position index within the array, possibly
shifting some elements to the left or the right as needed.
Sourcepub fn remove(&mut self, index: usize) -> T
pub fn remove(&mut self, index: usize) -> T
Removes and returns the element at position index within the array,
shifting some elements to the left or to the right.
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.
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
Returns a mutable reference to an element.