Struct IdMap

Source
pub struct IdMap<T> { /* private fields */ }
Expand description

A container that gives each item a unique id. Internally all elements are stored contiguously.

Implementations§

Source§

impl<T> IdMap<T>

Source

pub fn new() -> Self

Creates an empty IdMap<T>.

Source

pub fn with_capacity(cap: usize) -> Self

Creates an IdMap<T> with the specified capacity.

Source

pub fn clear(&mut self)

Removes all values from the map.

Source

pub fn next_id(&self) -> Id

Returns the id that a subsequent call to insert() will produce.

Source

pub fn len(&self) -> usize

Returns the number of id-value pairs in the map.

Source

pub fn capacity(&self) -> usize

Returns the number of id-value pairs the map can hold before reallocating.

Source

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

Resizes the map such that that capacity() >= cap.

Source

pub fn shrink_to_fit(&mut self)

Resizes the map to minimize allocated memory.

Source

pub fn as_set(&self) -> &IdSet

Returns a reference to the set of valid ids.

Source

pub fn insert(&mut self, val: T) -> Id

Inserts a value into an empty slot in the map and returns its id.

Source

pub fn insert_at(&mut self, id: Id, val: T) -> Option<T>

Inserts a value at a specific id, returning the old value if it existed.

Source

pub fn remove(&mut self, id: Id) -> Option<T>

Removes an id from the map, returning its value if it was previously in the map.

Source

pub fn get_or_insert(&mut self, id: Id, val: T) -> &mut T

If the id has a value, returns it, otherwise inserts a new value.

Source

pub fn get_or_insert_with<F: FnOnce() -> T>(&mut self, id: Id, f: F) -> &mut T

If the id has a value, returns it, otherwise inserts a new value with the provided closure.

Source

pub fn remove_set(&mut self, set: &IdSet)

Removes all ids in the set from the map.

Source

pub fn retain<F: FnMut(Id, &T) -> bool>(&mut self, pred: F)

Remove all values not satisfying the predicate.

Source

pub fn contains(&self, id: Id) -> bool

Returns true if the map contains a value for the specified id.

Source

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

Returns a reference to the value at the specified id if it is in the map.

Source

pub fn get_mut(&mut self, id: Id) -> Option<&mut T>

Returns a mutable reference to the value at the specified id if it is in the map.

Source

pub fn ids(&self) -> Ids<'_>

An iterator over ids, in increasing order.

Source

pub fn values(&self) -> Values<'_, T>

An iterator over values, in order of increasing id.

Source

pub fn values_mut(&mut self) -> ValuesMut<'_, T>

A mutable iterator over values, in order of increasing id.

Source

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

An iterator over id-value pairs, in order of increasing id.

Source

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

A mutable iterator over id-value pairs, in order of increasing id.

Source

pub fn into_iter(self) -> IntoIter<T>

A consuming iterator over id-value pairs, in order of increasing id.

Trait Implementations§

Source§

impl<T: Clone> Clone for IdMap<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for IdMap<T>

Source§

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

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

impl<T> Default for IdMap<T>

Source§

fn default() -> Self

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

impl<T> Drop for IdMap<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> Extend<T> for IdMap<T>

Source§

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

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> FromIterator<(usize, T)> for IdMap<T>

Source§

fn from_iter<I: IntoIterator<Item = (Id, T)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T> FromIterator<T> for IdMap<T>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T> Index<usize> for IdMap<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, id: Id) -> &Self::Output

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

impl<T> IndexMut<usize> for IdMap<T>

Source§

fn index_mut(&mut self, id: Id) -> &mut Self::Output

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

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

Source§

type Item = (usize, &'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) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

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

Source§

type Item = (usize, &'a mut T)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, T>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for IdMap<T>

Source§

type Item = (usize, 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) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: PartialEq> PartialEq for IdMap<T>

Source§

fn eq(&self, other: &Self) -> 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: Eq> Eq for IdMap<T>

Auto Trait Implementations§

§

impl<T> Freeze for IdMap<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for IdMap<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.