Struct two_sided_vec::TwoSidedVec [−][src]
pub struct TwoSidedVec<T> { /* fields omitted */ }
A simple 'two sided' vector, that can grow both forwards and backwards.
The front and the back can be viewed as seperate and independent vectors,
with negative indexing accessing the back and positive indexing accessing the front.
This allows you to append to the back without modifying positive indexes.
Unless you actually need pushing to the back to appear to shift the front forward,
like VecDeque
does, this negative index system will probably be better for your situation.
Internally this allows a much simpler and faster implementation, since there's only a single pointer to the middle that grows up and down. Internally, we have to reallocate the buffer if we run out of capacity in either the negative or positive difes grow separately and Although bounds checks are slightly slower since they involve two comparisons, the access itself should be just as fast.
Methods
impl<T> TwoSidedVec<T>
[src]
impl<T> TwoSidedVec<T>
pub fn new() -> Self
[src]
pub fn new() -> Self
pub fn with_capacity(back: usize, front: usize) -> Self
[src]
pub fn with_capacity(back: usize, front: usize) -> Self
pub fn front(&self) -> &[T]
[src]
pub fn front(&self) -> &[T]
Take a slice of the front of this queue
pub fn back(&self) -> &[T]
[src]
pub fn back(&self) -> &[T]
Take a slice of the back of this queue
pub fn front_mut(&mut self) -> &mut [T]
[src]
pub fn front_mut(&mut self) -> &mut [T]
Take a mutable slice of the front of this queue
pub fn back_mut(&mut self) -> &mut [T]
[src]
pub fn back_mut(&mut self) -> &mut [T]
Take a mutable slice of the back of this queue
pub fn split(&self) -> (&[T], &[T])
[src]
pub fn split(&self) -> (&[T], &[T])
Take seperate slices of the back and the front of the vector respectively.
pub fn split_mut(&mut self) -> (&mut [T], &mut [T])
[src]
pub fn split_mut(&mut self) -> (&mut [T], &mut [T])
Take seperate mutable slices of the back and front of the vector respectively.
pub fn push_front(&mut self, value: T)
[src]
pub fn push_front(&mut self, value: T)
pub fn pop_front(&mut self) -> Option<T>
[src]
pub fn pop_front(&mut self) -> Option<T>
pub fn pop_back(&mut self) -> Option<T>
[src]
pub fn pop_back(&mut self) -> Option<T>
pub fn push_back(&mut self, value: T)
[src]
pub fn push_back(&mut self, value: T)
Push the specified value into the front of this queue,
without modifying its end
or touching the front of the queue.
This effectively preserves all positive indexes, which may or may not be useful for your situation.
pub fn reserve_back(&mut self, amount: usize)
[src]
pub fn reserve_back(&mut self, amount: usize)
pub fn reserve_front(&mut self, amount: usize)
[src]
pub fn reserve_front(&mut self, amount: usize)
pub fn capacity_back(&self) -> usize
[src]
pub fn capacity_back(&self) -> usize
pub fn capacity_front(&self) -> usize
[src]
pub fn capacity_front(&self) -> usize
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Return the length of the entire vector, which is the sum of the lengths of the front and back parts.
The length isn't where the vector ends,
since it could have elements in the back with negative indexes.
Use vec.start()
and vec.end()
if you want to know the start and end indexes.
The total length is exactly equivalent to vec.len_back() + vec.len_front()
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
pub fn len_back(&self) -> usize
[src]
pub fn len_back(&self) -> usize
Return the length of the back of the vector.
pub fn len_front(&self) -> usize
[src]
pub fn len_front(&self) -> usize
Return the length of the front of the vector
pub fn start(&self) -> isize
[src]
pub fn start(&self) -> isize
Give the (inclusive) start of the queue's elements. which may be negative if the queue's back isn't empty
This is exactly equivelant to -vec.back().len()
.
pub fn end(&self) -> isize
[src]
pub fn end(&self) -> isize
Give the (exclusive) end of the queue's elements, which may be less than the length if the queue's back contains some elements.
This is exactly equivalent to vec.front().len()
pub fn range(&self) -> Range<isize>
[src]
pub fn range(&self) -> Range<isize>
Return the [start, end)
range of the element indices,
equivalent to a tuple of (queue.start(), queue.end())
.
pub fn iter_entire(&self) -> Iter<T>
[src]
pub fn iter_entire(&self) -> Iter<T>
Iterate over the entire vector, including both the back and front.
pub fn get<I: TwoSidedIndex<T>>(&self, index: I) -> Option<&I::Output>
[src]
pub fn get<I: TwoSidedIndex<T>>(&self, index: I) -> Option<&I::Output>
pub fn get_mut<I: TwoSidedIndex<T>>(
&mut self,
index: I
) -> Option<&mut I::Output>
[src]
pub fn get_mut<I: TwoSidedIndex<T>>(
&mut self,
index: I
) -> Option<&mut I::Output>
pub unsafe fn get_unchecked<I: TwoSidedIndex<T>>(&self, index: I) -> &I::Output
[src]
pub unsafe fn get_unchecked<I: TwoSidedIndex<T>>(&self, index: I) -> &I::Output
pub unsafe fn get_unchecked_mut<I: TwoSidedIndex<T>>(
&mut self,
index: I
) -> &mut I::Output
[src]
pub unsafe fn get_unchecked_mut<I: TwoSidedIndex<T>>(
&mut self,
index: I
) -> &mut I::Output
pub fn start_ptr(&self) -> *mut T
[src]
pub fn start_ptr(&self) -> *mut T
Give a raw pointer to the start of the elements
pub fn middle_ptr(&self) -> *mut T
[src]
pub fn middle_ptr(&self) -> *mut T
Give a raw pointer to the middle of the elements
pub fn end_ptr(&self) -> *mut T
[src]
pub fn end_ptr(&self) -> *mut T
pub fn split_at(&self, index: isize) -> (&[T], &[T])
[src]
pub fn split_at(&self, index: isize) -> (&[T], &[T])
pub fn clear(&mut self)
[src]
pub fn clear(&mut self)
ⓘImportant traits for SignedEnumerate<I>pub fn enumerate_back(&self) -> SignedEnumerate<Iter<T>>
[src]
pub fn enumerate_back(&self) -> SignedEnumerate<Iter<T>>
Enumerate the indices and values of the elements in the back of the vector.
The primary advantage over regular enumeration is that it gives proper negative indices since the elements are in the back.
ⓘImportant traits for SignedEnumerate<I>pub fn enumerate_front(&self) -> SignedEnumerate<Iter<T>>
[src]
pub fn enumerate_front(&self) -> SignedEnumerate<Iter<T>>
Enumerate the indices and values of the elements in the front of the vector.
The only possible advantage over regular enumeration is that it
gives positive isize
indices for consistency with enumeration over the back.
ⓘImportant traits for SignedEnumerate<I>pub fn enumerate(&self) -> SignedEnumerate<Iter<T>>
[src]
pub fn enumerate(&self) -> SignedEnumerate<Iter<T>>
Enumerate the indices and values of each element in the front and back.
The primary advantage over regular enumeration is that it gives proper negative indices for elements that are in the back.
ⓘImportant traits for SignedEnumerate<I>pub fn enumerate_mut(&mut self) -> SignedEnumerate<IterMut<T>>
[src]
pub fn enumerate_mut(&mut self) -> SignedEnumerate<IterMut<T>>
Mutably enumerate the indices and values of each element in the front and back.
The primary advantage over regular enumeration is that it gives proper negative indices for elements that are in the back.
pub fn truncate_back(&mut self, len: usize)
[src]
pub fn truncate_back(&mut self, len: usize)
pub fn truncate_front(&mut self, len: usize)
[src]
pub fn truncate_front(&mut self, len: usize)
pub fn retain<F: FnMut(isize, &mut T) -> bool>(&mut self, pred: F)
[src]
pub fn retain<F: FnMut(isize, &mut T) -> bool>(&mut self, pred: F)
pub fn retain_back<F: FnMut(isize, &mut T) -> bool>(&mut self, pred: F)
[src]
pub fn retain_back<F: FnMut(isize, &mut T) -> bool>(&mut self, pred: F)
pub fn retain_front<F: FnMut(isize, &mut T) -> bool>(&mut self, pred: F)
[src]
pub fn retain_front<F: FnMut(isize, &mut T) -> bool>(&mut self, pred: F)
ⓘImportant traits for DrainFilterBack<'a, T, F>pub fn drain_filter_back<F: FnMut(isize, &mut T) -> bool>(
&mut self,
pred: F
) -> DrainFilterBack<T, F>
[src]
pub fn drain_filter_back<F: FnMut(isize, &mut T) -> bool>(
&mut self,
pred: F
) -> DrainFilterBack<T, F>
ⓘImportant traits for DrainFilterFront<'a, T, F>pub fn drain_filter_front<F: FnMut(isize, &mut T) -> bool>(
&mut self,
pred: F
) -> DrainFilterFront<T, F>
[src]
pub fn drain_filter_front<F: FnMut(isize, &mut T) -> bool>(
&mut self,
pred: F
) -> DrainFilterFront<T, F>
Trait Implementations
impl<T> TwoSidedExtend<T> for TwoSidedVec<T>
[src]
impl<T> TwoSidedExtend<T> for TwoSidedVec<T>
fn extend_back<I: IntoIterator<Item = T>>(&mut self, iter: I)
[src]
fn extend_back<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend_front<I: IntoIterator<Item = T>>(&mut self, iter: I)
[src]
fn extend_front<I: IntoIterator<Item = T>>(&mut self, iter: I)
impl<'a, T: Copy + 'a> TwoSidedExtend<&'a T> for TwoSidedVec<T>
[src]
impl<'a, T: Copy + 'a> TwoSidedExtend<&'a T> for TwoSidedVec<T>
fn extend_back<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
[src]
fn extend_back<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
fn extend_front<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
[src]
fn extend_front<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
impl<T: Clone> Clone for TwoSidedVec<T>
[src]
impl<T: Clone> Clone for TwoSidedVec<T>
fn clone(&self) -> Self
[src]
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<T> Default for TwoSidedVec<T>
[src]
impl<T> Default for TwoSidedVec<T>
impl<T: Debug> Debug for TwoSidedVec<T>
[src]
impl<T: Debug> Debug for TwoSidedVec<T>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<T> Drop for TwoSidedVec<T>
[src]
impl<T> Drop for TwoSidedVec<T>
impl<T, I: TwoSidedIndex<T>> Index<I> for TwoSidedVec<T>
[src]
impl<T, I: TwoSidedIndex<T>> Index<I> for TwoSidedVec<T>
type Output = I::Output
The returned type after indexing.
fn index(&self, index: I) -> &I::Output
[src]
fn index(&self, index: I) -> &I::Output
Performs the indexing (container[index]
) operation.
impl<T, I: TwoSidedIndex<T>> IndexMut<I> for TwoSidedVec<T>
[src]
impl<T, I: TwoSidedIndex<T>> IndexMut<I> for TwoSidedVec<T>
fn index_mut(&mut self, index: I) -> &mut I::Output
[src]
fn index_mut(&mut self, index: I) -> &mut I::Output
Performs the mutable indexing (container[index]
) operation.
impl<T> From<Vec<T>> for TwoSidedVec<T>
[src]
impl<T> From<Vec<T>> for TwoSidedVec<T>
impl<T: PartialEq<U>, U> PartialEq<TwoSidedVec<U>> for TwoSidedVec<T>
[src]
impl<T: PartialEq<U>, U> PartialEq<TwoSidedVec<U>> for TwoSidedVec<T>
fn eq(&self, other: &TwoSidedVec<U>) -> bool
[src]
fn eq(&self, other: &TwoSidedVec<U>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<T: Eq> Eq for TwoSidedVec<T>
[src]
impl<T: Eq> Eq for TwoSidedVec<T>
impl<T: Hash> Hash for TwoSidedVec<T>
[src]
impl<T: Hash> Hash for TwoSidedVec<T>
Auto Trait Implementations
impl<T> !Send for TwoSidedVec<T>
impl<T> !Send for TwoSidedVec<T>
impl<T> !Sync for TwoSidedVec<T>
impl<T> !Sync for TwoSidedVec<T>