pub struct VecQueue<T> { /* private fields */ }Expand description
A queue that uses a vector to store the elements.
It is similar to std::collections::VecDeque, but it provides a few additional methods
that are used by Orengine's projects.
Implementations§
Source§impl<T> VecQueue<T>
impl<T> VecQueue<T>
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more elements to be inserted in the given VecQueue.
The collection may reserve more space to speculatively avoid frequent reallocations.
After calling reserve, capacity will be greater than or equal to self.len() + additional.
Does nothing if capacity is already sufficient.
Sourcepub fn extend_to(&mut self, capacity: usize)
pub fn extend_to(&mut self, capacity: usize)
Extends the vector to the given capacity.
§Panics
Panics if the provided capacity is not a power of two or is less than the current capacity.
Sourcepub fn push_priority_value(&mut self, value: T)
pub fn push_priority_value(&mut self, value: T)
Pushes the provided value to the front of the queue.
§Example
use orengine_utils::VecQueue;
let mut queue = VecQueue::new();
queue.push_priority_value(1); // [1, _, _]
queue.push(2); // [1, 2, _]
queue.push_priority_value(3); // [3, 1, 2]
assert_eq!(queue.pop(), Some(3));
assert_eq!(queue.pop(), Some(1));
assert_eq!(queue.pop(), Some(2));Sourcepub fn pop_less_priority_value(&mut self) -> Option<T>
pub fn pop_less_priority_value(&mut self) -> Option<T>
Removes the last element and returns it, or None if the queue is empty.
§Example
use orengine_utils::VecQueue;
let mut queue = VecQueue::new();
queue.push(1); // [1, _, _]
queue.push(2); // [1, 2, _]
queue.push(3); // [1, 2, 3]
assert_eq!(queue.pop_less_priority_value(), Some(3));
assert_eq!(queue.pop(), Some(1));
assert_eq!(queue.pop(), Some(2));Sourcepub unsafe fn extend_from_slice(&mut self, slice: &[T])
pub unsafe fn extend_from_slice(&mut self, slice: &[T])
Sourcepub unsafe fn take_batch<R, F: FnOnce(&[T], &[T]) -> R>(
&mut self,
f: F,
limit: usize,
) -> R
pub unsafe fn take_batch<R, F: FnOnce(&[T], &[T]) -> R>( &mut self, f: F, limit: usize, ) -> R
Accepts a function that will be called with the slices of the queue to move.
§Safety
The function should copy all elements from the provided slices.
§Example
use orengine_utils::VecQueue;
let mut queue = VecQueue::new();
for i in 0..10 {
queue.push(i);
}
let mut receiver = Vec::with_capacity(10);
unsafe {
let popped = queue.take_batch(|first_slice, second_slice| {
receiver.extend_from_slice(first_slice);
receiver.extend_from_slice(second_slice);
first_slice.len() + second_slice.len()
}, 8);
assert_eq!(popped, 8);
}
assert_eq!(receiver, (0..8).collect::<Vec<_>>());
assert_eq!(queue.len(), 2);
assert_eq!(queue.pop(), Some(8));
assert_eq!(queue.pop(), Some(9));Sourcepub fn clear_with<F: Fn(T)>(&mut self, f: F)
pub fn clear_with<F: Fn(T)>(&mut self, f: F)
Clears the queue by calling the provided function on each element.