pub struct BiVec<T> {
pub(crate) data: Vec<T>,
pub(crate) min_degree: i32,
}Expand description
A BiVec is like a Vec, except we allow indices to be negative. It has a min_degree property which tells us where the starting index is.
Note that properties like length and capacity are defined to be the maximum index allowed. For
example, if v.min_degree = -2 and v.len() = 3, it means we can access v[-2], v[-1], v[0], v[1], v[2] but not v[3].
Fields§
§data: Vec<T>§min_degree: i32Implementations§
Source§impl<T: Clone> BiVec<T>
impl<T: Clone> BiVec<T>
Sourcepub fn extend_negative(&mut self, min_degree: i32, default: T)
pub fn extend_negative(&mut self, min_degree: i32, default: T)
If min_degree < self.min_degree, set self.min_degree to min_degree and pad the
remaining spaces with default.
§Example
let mut v = BiVec::from_vec(-2, vec![3, 4, 6, 2]);
v.extend_negative(-4, 0);
assert_eq!(v[1], 2);
assert_eq!(v[-4], 0);
assert_eq!(v.min_degree(), -4);Source§impl<T> BiVec<T>
impl<T> BiVec<T>
pub fn new(min_degree: i32) -> Self
pub fn from_vec(min_degree: i32, data: Vec<T>) -> Self
pub fn into_vec(self) -> Vec<T>
pub fn with_capacity(min_degree: i32, capacity: i32) -> Self
pub const fn min_degree(&self) -> i32
Sourcepub fn max_degree(&self) -> i32
pub fn max_degree(&self) -> i32
This returns the largest degree in the bivector. This is equal to self.len() - 1.
§Example
let v = BiVec::from_vec(-2, vec![3, 4, 6, 8, 2]);
assert_eq!(v.max_degree(), 2);Sourcepub fn len(&self) -> i32
pub fn len(&self) -> i32
This returns the “length” of the bivector, defined to be the smallest i such that
v[i]
is not defined.
§Example
let v = BiVec::from_vec(-2, vec![3, 4, 6, 8, 2]);
assert_eq!(v.len(), 3);pub fn is_empty(&self) -> bool
pub fn push(&mut self, x: T)
pub fn get(&self, idx: i32) -> Option<&T>
Sourcepub fn get_max(&self, idx: i32) -> &T
pub fn get_max(&self, idx: i32) -> &T
Get the idxth element if it exists; the last element otherwise
pub fn last(&self) -> Option<&T>
pub fn iter(&self) -> Iter<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn iter_enum(&self) -> impl DoubleEndedIterator<Item = (i32, &T)>
pub fn iter_mut_enum( &mut self, ) -> impl DoubleEndedIterator<Item = (i32, &mut T)>
pub fn into_iter_enum(self) -> impl DoubleEndedIterator<Item = (i32, T)>
Sourcepub fn extend_with<F>(&mut self, max: i32, f: F)
pub fn extend_with<F>(&mut self, max: i32, f: F)
Extends the bivec such that max_degree() is at least max. If max_degree() is
already at least max, the function does nothing. Otherwise, it fills the new entries
with the return value of F(i), where i is the index of the new entry.
pub fn reserve(&mut self, num: usize)
Sourcepub fn split_borrow_mut(&mut self, i: i32, j: i32) -> (&mut T, &mut T)
pub fn split_borrow_mut(&mut self, i: i32, j: i32) -> (&mut T, &mut T)
Mutably borrows i and j. Panic if i != j.
§Example
let mut v = BiVec::from_vec(1, vec![3, 5, 2]);
let (x, y) = v.split_borrow_mut(1, 3);
assert_eq!(*x, 3);
assert_eq!(*y, 2);
let (x, y) = v.split_borrow_mut(3, 2);
assert_eq!(*x, 2);
assert_eq!(*y, 5);pub fn range(&self) -> Range<i32>
Trait Implementations§
Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for BiVec<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for BiVec<T>
Source§fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<A> Extend<A> for BiVec<A>
impl<A> Extend<A> for BiVec<A>
Source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = A>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = A>,
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)