IndexVec

Struct IndexVec 

Source
pub struct IndexVec<I, T>
where I: Idx,
{ /* private fields */ }
Expand description

A dense vector indexed by ID types.

This provides O(1) access and storage for dense ID-indexed data.

Implementations§

Source§

impl<I, T> IndexVec<I, T>
where I: Idx,

Source

pub fn new() -> IndexVec<I, T>

Create a new empty IndexVec.

Source

pub fn with_capacity(n: usize) -> IndexVec<I, T>

Create a new IndexVec with pre-allocated capacity.

Source

pub fn len(&self) -> usize

Get the number of elements in the IndexVec.

Source

pub fn is_empty(&self) -> bool

Check if the IndexVec is empty.

Source

pub fn push(&mut self, v: T) -> Result<I, IndexedVecError>

Push an element and return its ID.

Returns an error if the length would exceed the maximum representable by the ID type.

Source

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

Get an element by ID, returning None if the ID is out of bounds.

Source

pub fn as_slice(&self) -> &[T]

Get a slice of all elements.

Source

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

Consume this IndexVec and return the underlying Vec.

Source

pub fn swap_remove(&mut self, index: usize) -> T

Remove an element at the specified index and return it.

Source

pub fn contains(&self, item: &T) -> bool
where T: PartialEq,

Check if this IndexVec contains a specific element.

Source

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

Get an iterator over the elements in this IndexVec.

Source

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

Get a mutable iterator over the elements in this IndexVec.

Trait Implementations§

Source§

impl<I, T> Clone for IndexVec<I, T>
where I: Clone + Idx, T: Clone,

Source§

fn clone(&self) -> IndexVec<I, 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<I, T> Debug for IndexVec<I, T>
where I: Debug + Idx, T: Debug,

Source§

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

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

impl<I, T> Default for IndexVec<I, T>
where I: Idx,

Source§

fn default() -> IndexVec<I, T>

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

impl<I, T> Index<I> for IndexVec<I, T>
where I: Idx,

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: I) -> &<IndexVec<I, T> as Index<I>>::Output

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

impl<I, T> IndexMut<I> for IndexVec<I, T>
where I: Idx,

Source§

fn index_mut(&mut self, index: I) -> &mut <IndexVec<I, T> as Index<I>>::Output

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

impl<'a, I, T> IntoIterator for &'a IndexVec<I, T>
where I: Idx,

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

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

fn into_iter(self) -> <&'a IndexVec<I, T> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<I, T> IntoIterator for IndexVec<I, T>
where I: Idx,

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

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

fn into_iter(self) -> <IndexVec<I, T> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<I, T> LookupByIdx<I, T> for IndexVec<I, T>
where I: Idx,

Source§

fn get(&self, id: I) -> Option<&T>

Get the value for the given ID.
Source§

impl<I, T> PartialEq for IndexVec<I, T>
where I: PartialEq + Idx, T: PartialEq,

Source§

fn eq(&self, other: &IndexVec<I, 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<I, T> Eq for IndexVec<I, T>
where I: Eq + Idx, T: Eq,

Source§

impl<I, T> StructuralPartialEq for IndexVec<I, T>
where I: Idx,

Auto Trait Implementations§

§

impl<I, T> Freeze for IndexVec<I, T>

§

impl<I, T> RefUnwindSafe for IndexVec<I, T>

§

impl<I, T> Send for IndexVec<I, T>
where I: Send, T: Send,

§

impl<I, T> Sync for IndexVec<I, T>
where I: Sync, T: Sync,

§

impl<I, T> Unpin for IndexVec<I, T>
where I: Unpin, T: Unpin,

§

impl<I, T> UnwindSafe for IndexVec<I, T>
where I: UnwindSafe, 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<'a, F, I> BatchInvert<F> for I
where F: Field + ConstantTimeEq, I: IntoIterator<Item = &'a mut F>,

Source§

fn batch_invert(self) -> F

Consumes this iterator and inverts each field element (when nonzero). Zero-valued elements are left as zero. 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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V