Skip to main content

VecMap

Struct VecMap 

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

A collection that provides a map interface but is backed by vectors.

This is suitable for small key-value stores where the item count is not large enough to overcome the overhead of a more complex algorithm.

If this meets your use cases, then VecMap should be a drop-in replacement for std::collections::HashMap or crate::HashMap. Note that we are adding APIs on an as-needed basis. If the API you need is not present yet, please add it!

Because it uses vectors as a backing store, the map also iterates over items in insertion order, like crate::IndexMap.

This struct uses a struct-of-arrays (SoA) representation which tends to be more cache efficient and promotes autovectorization when using simple key or value types.

Implementations§

Source§

impl<K, V> VecMap<K, V>

Source

pub fn new() -> Self

Source

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

Source§

impl<K: Eq, V> VecMap<K, V>

Source

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

Source

pub fn entry_ref<'a, 'k>(&'a mut self, key: &'k K) -> EntryRef<'k, 'a, K, V>

Like Self::entry but takes its key by reference instead of by value.

This can be helpful if you have a key where cloning is expensive, as we can avoid cloning the key until a value is inserted under that entry.

Trait Implementations§

Source§

impl<K: Default, V: Default> Default for VecMap<K, V>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<K, V> Freeze for VecMap<K, V>
where Vec<K>: Freeze, Vec<V>: Freeze,

§

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

§

impl<K, V> Send for VecMap<K, V>
where Vec<K>: Send, Vec<V>: Send,

§

impl<K, V> Sync for VecMap<K, V>
where Vec<K>: Sync, Vec<V>: Sync,

§

impl<K, V> Unpin for VecMap<K, V>
where Vec<K>: Unpin, Vec<V>: Unpin,

§

impl<K, V> UnsafeUnpin for VecMap<K, V>
where Vec<K>: UnsafeUnpin, Vec<V>: UnsafeUnpin,

§

impl<K, V> UnwindSafe for VecMap<K, V>
where Vec<K>: UnwindSafe, Vec<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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.