BiVec

Struct BiVec 

Source
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: i32

Implementations§

Source§

impl<T: Clone> BiVec<T>

Source

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>

Source

pub fn new(min_degree: i32) -> Self

Source

pub fn from_vec(min_degree: i32, data: Vec<T>) -> Self

Source

pub fn into_vec(self) -> Vec<T>

Source

pub fn with_capacity(min_degree: i32, capacity: i32) -> Self

Source

pub const fn min_degree(&self) -> i32

Source

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);
Source

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);
Source

pub fn is_empty(&self) -> bool

Source

pub fn push(&mut self, x: T)

Source

pub fn get(&self, idx: i32) -> Option<&T>

Source

pub fn get_max(&self, idx: i32) -> &T

Get the idxth element if it exists; the last element otherwise

Source

pub fn last(&self) -> Option<&T>

Source

pub fn iter(&self) -> Iter<'_, T>

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Source

pub fn iter_enum(&self) -> impl DoubleEndedIterator<Item = (i32, &T)>

Source

pub fn iter_mut_enum( &mut self, ) -> impl DoubleEndedIterator<Item = (i32, &mut T)>

Source

pub fn into_iter_enum(self) -> impl DoubleEndedIterator<Item = (i32, T)>

Source

pub fn extend_with<F>(&mut self, max: i32, f: F)
where F: FnMut(i32) -> T,

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.

Source

pub fn reserve(&mut self, num: usize)

Source

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);
Source

pub fn range(&self) -> Range<i32>

Trait Implementations§

Source§

impl<T: Clone> Clone for BiVec<T>

Source§

fn clone(&self) -> BiVec<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for BiVec<T>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for BiVec<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, T: Deserialize<'de>> Deserialize<'de> for BiVec<T>

Source§

fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<A> Extend<A> for BiVec<A>

Source§

fn extend<T>(&mut self, iter: T)
where T: IntoIterator<Item = A>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T> Index<i32> for BiVec<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, i: i32) -> &T

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<i32> for BiVec<T>

Source§

fn index_mut(&mut self, i: i32) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T> IntoIterator for &'a BiVec<T>

Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for &'a mut BiVec<T>

Source§

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?
Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for BiVec<T>

Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

type Item = T

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: PartialEq> PartialEq for BiVec<T>

Source§

fn eq(&self, other: &BiVec<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Serialize> Serialize for BiVec<T>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: Eq> Eq for BiVec<T>

Source§

impl<T> StructuralPartialEq for BiVec<T>

Auto Trait Implementations§

§

impl<T> Freeze for BiVec<T>

§

impl<T> RefUnwindSafe for BiVec<T>
where T: RefUnwindSafe,

§

impl<T> Send for BiVec<T>
where T: Send,

§

impl<T> Sync for BiVec<T>
where T: Sync,

§

impl<T> Unpin for BiVec<T>
where T: Unpin,

§

impl<T> UnwindSafe for BiVec<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,