Skip to main content

OrdinalMap

Struct OrdinalMap 

Source
pub struct OrdinalMap<K, V> { /* private fields */ }
Expand description

Map Ordinal keys to values. Map operations are constant time (provided that K::ordinal() is constant time).

This implementation allocates a boxed slice [Option<V>; K::ORDINAL_SIZE] on the first insertion. For non-allocating map, consider using OrdinalArrayMap.

This implementation is sparse (not every key has an associated value). For a total map, see OrdinalTotalMap and OrdinalTotalArrayMap.

Implementations§

Source§

impl<K: Ordinal, V> OrdinalMap<K, V>

Source

pub fn new() -> Self

Create a new empty map. This operation does not allocate memory, but first insertion allocates the whole map.

Source

pub fn get<'a>(&'a self, key: &K) -> Option<&'a V>

Returns a reference to the value corresponding to the key.

Source

pub fn get_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V>

Returns a mutable reference to the value corresponding to the key.

Source

pub fn contains_key(&self, key: &K) -> bool

Returns true if the map contains the key.

Source

pub fn len(&self) -> usize

Returns the number of elements in the map. This is an O(K::ORDINAL_SIZE) operation.

Source

pub fn is_empty(&self) -> bool

Return true if the map container no elements.

Source

pub fn insert(&mut self, key: K, value: V) -> Option<V>

Insert a value into the map, returning the previous value if it existed.

Source

pub fn entry(&mut self, key: K) -> Entry<'_, K, V>

Get an entry in the map for the given key.

Source

pub fn remove(&mut self, key: &K) -> Option<V>

Remove a value from the map, returning it if it existed.

Source

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

Iterate over the map.

Source

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

Iterate over the map mutably.

Source

pub fn keys(&self) -> Keys<'_, K, V>

Iterate over the keys of the map.

Source

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

Iterate over the values of the map.

Source

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

Iterate over the mutable references to the values of the map.

Source

pub fn drain(&mut self) -> Drain<'_, K, V>

Clears the map, returning all key-value pairs as an iterator.

Source

pub fn clear(&mut self)

Remove all elements from the map.

Trait Implementations§

Source§

impl<K, V: Clone> Clone for OrdinalMap<K, V>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<K: Ordinal + Debug, V: Debug> Debug for OrdinalMap<K, V>

Source§

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

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

impl<K: Ordinal, V> Default for OrdinalMap<K, V>

Source§

fn default() -> Self

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

impl<K: Ordinal, V> FromIterator<(K, V)> for OrdinalMap<K, V>

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<K: Ordinal, V> IntoIterator for OrdinalMap<K, V>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, V>

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, K: Ordinal, V> IntoIterator for &'a OrdinalMap<K, V>

Source§

type Item = (K, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K, V>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for OrdinalMap<K, V>

§

impl<K, V> RefUnwindSafe for OrdinalMap<K, V>

§

impl<K, V> Send for OrdinalMap<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for OrdinalMap<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for OrdinalMap<K, V>
where K: Unpin,

§

impl<K, V> UnsafeUnpin for OrdinalMap<K, V>

§

impl<K, V> UnwindSafe for OrdinalMap<K, V>
where K: UnwindSafe, V: 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.