Skip to main content

InlineScanMap

Struct InlineScanMap 

Source
pub struct InlineScanMap<K, V, const SZ: usize> { /* private fields */ }
Expand description

A general-purpose map implemented using linear scanning.

This type is an implementation detail of the `frozen_collections` crate. This API is therefore not stable and may change at any time. Please do not use this type directly, and instead use the public API provided by the `frozen_collections` crate.
A frozen collection differs from the traditional Rust collections, such as [`HashMap`](std::collections::HashMap) and [`HashSet`](std::collections::HashSet) types in three key ways. First, creating a frozen collection performs an analysis over the input data to determine the best implementation strategy. Depending on the situation, this analysis is performed at build time or runtime, and it can take a relatively long time when a collection is very large. Second, once created, the keys in frozen collections are immutable. And third, querying a frozen collection is typically considerably faster, which is the whole point.

§Type Parameters

  • K: The key type.
  • V: The value type.
  • SZ: The number of entries in the map.

Implementations§

Source§

impl<K, V, const SZ: usize> InlineScanMap<K, V, SZ>

Source

pub fn new(entries: Vec<(K, V)>) -> Self
where K: Eq,

Creates a frozen map.

§Panics

Panics if the number of entries in the array differs from the size of the map as specified by the SZ generic argument.

Source

pub const fn new_raw(dedupped_entries: [(K, V); SZ]) -> Self

Creates a frozen map.

§Expectations

Callers must ensure:

  • Entries are deduplicated.
Source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where Q: ?Sized + Equivalent<K>,

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type.

Source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where Q: ?Sized + Equivalent<K>,

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

The key may be any borrowed form of the map’s key type.

Source

pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
where Q: ?Sized + Equivalent<K>,

Returns the key-value pair corresponding to the supplied key.

This is potentially useful:

  • for key types where non-identical keys can be considered equal;

  • for getting the &K stored key value from a borrowed &Q lookup key; or

  • for getting a reference to a key with the same lifetime as the collection.

  • The supplied key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where Q: ?Sized + Equivalent<K>,

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

The key may be any borrowed form of the map’s key type.

Source

pub fn get_disjoint_mut<Q, const N: usize>( &mut self, keys: [&Q; N], ) -> [Option<&mut V>; N]
where Q: ?Sized + Eq + Equivalent<K>,

Gets multiple mutable values from the map.

§Panics

Panics if the same key is specified multiple times.

Source

pub unsafe fn get_disjoint_unchecked_mut<Q, const N: usize>( &mut self, keys: [&Q; N], ) -> [Option<&mut V>; N]
where Q: ?Sized + Equivalent<K>,

Gets multiple mutable values from the map.

§Safety

Calling this method with overlapping keys is undefined behavior even if the resulting references are not used.

Source

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

An iterator visiting all entries in arbitrary order.

Source

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

An iterator producing mutable references to all entries in arbitrary order.

Source

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

An iterator visiting all keys in arbitrary order.

Source

pub fn into_keys(self) -> IntoKeys<K, V>

A consuming iterator visiting all keys in arbitrary order.

Source

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

An iterator visiting all values in arbitrary order.

Source

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

An iterator visiting all values mutably in arbitrary order.

Source

pub fn into_values(self) -> IntoValues<K, V>

A consuming iterator visiting all values in arbitrary order.

Source

pub const fn len(&self) -> usize

Returns the number of elements in the collection.

Source

pub const fn is_empty(&self) -> bool

Returns true if the collection contains no elements.

Trait Implementations§

Source§

impl<K: Clone, V: Clone, const SZ: usize> Clone for InlineScanMap<K, V, SZ>

Source§

fn clone(&self) -> InlineScanMap<K, V, SZ>

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<K, V, const SZ: usize> Debug for InlineScanMap<K, V, SZ>
where K: Debug, V: Debug,

Source§

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

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

impl<Q, K, V, const SZ: usize> Index<&Q> for InlineScanMap<K, V, SZ>
where Q: ?Sized + Equivalent<K>,

Source§

type Output = V

The returned type after indexing.
Source§

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

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

impl<'a, K, V, const SZ: usize> IntoIterator for &'a InlineScanMap<K, V, SZ>

Source§

type Item = (&'a 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
Source§

impl<'a, K, V, const SZ: usize> IntoIterator for &'a mut InlineScanMap<K, V, SZ>

Source§

type Item = (&'a K, &'a mut V)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'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
Source§

impl<K, V, const SZ: usize> IntoIterator for InlineScanMap<K, V, SZ>

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<K, V, const SZ: usize> Len for InlineScanMap<K, V, SZ>

Source§

fn len(&self) -> usize

Returns the number of elements in the collection.
Source§

fn is_empty(&self) -> bool

Returns true if the collection contains no elements.
Source§

impl<K, V, Q, const SZ: usize> MapExtras<K, V, Q> for InlineScanMap<K, V, SZ>
where Q: ?Sized + Equivalent<K>,

Source§

fn get_key_value(&self, key: &Q) -> Option<(&K, &V)>

Returns the key-value pair corresponding to the supplied key. Read more
Source§

fn get_disjoint_mut<const N: usize>( &mut self, keys: [&Q; N], ) -> [Option<&mut V>; N]
where Q: Eq,

Gets multiple mutable values from the map. Read more
Source§

unsafe fn get_disjoint_unchecked_mut<const N: usize>( &mut self, keys: [&Q; N], ) -> [Option<&mut V>; N]

Safety Read more
Source§

impl<K, V, const SZ: usize> MapIteration<K, V> for InlineScanMap<K, V, SZ>

Source§

type Iterator<'a> = Iter<'a, K, V> where K: 'a, V: 'a

The type of the iterator returned by Self::iter.
Source§

type KeyIterator<'a> = Keys<'a, K, V> where K: 'a, V: 'a

The type of the iterator returned by Self::keys.
Source§

type ValueIterator<'a> = Values<'a, K, V> where K: 'a, V: 'a

The type of the iterator returned by Self::values.
Source§

type MutIterator<'a> = IterMut<'a, K, V> where K: 'a, V: 'a

The type of the mutable iterator returned by Self::iter_mut.
Source§

type ValueMutIterator<'a> = ValuesMut<'a, K, V> where K: 'a, V: 'a

The type of the mutable iterator returned by Self::values_mut.
Source§

type IntoKeyIterator = IntoKeys<K, V>

The type of the iterator returned by Self::into_keys.
Source§

type IntoValueIterator = IntoValues<K, V>

The type of the iterator returned by Self::into_values.
Source§

fn iter(&self) -> Self::Iterator<'_>

An iterator visiting all entries in arbitrary order.
Source§

fn iter_mut(&mut self) -> Self::MutIterator<'_>

An iterator producing mutable references to all entries in arbitrary order.
Source§

fn keys(&self) -> Self::KeyIterator<'_>

An iterator visiting all keys in arbitrary order.
Source§

fn into_keys(self) -> Self::IntoKeyIterator

A consuming iterator visiting all keys in arbitrary order.
Source§

fn values(&self) -> Self::ValueIterator<'_>

An iterator visiting all values in arbitrary order.
Source§

fn values_mut(&mut self) -> Self::ValueMutIterator<'_>

An iterator visiting all values mutably in arbitrary order.
Source§

fn into_values(self) -> Self::IntoValueIterator

A consuming iterator visiting all values in arbitrary order.
Source§

impl<K, V, Q, const SZ: usize> MapQuery<Q, V> for InlineScanMap<K, V, SZ>
where Q: ?Sized + Equivalent<K>,

Source§

fn get(&self, key: &Q) -> Option<&V>

Returns a reference to the value corresponding to the key. Read more
Source§

fn get_mut(&mut self, key: &Q) -> Option<&mut V>

Returns a mutable reference to the value corresponding to the key. Read more
Source§

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

Returns true if the map contains a value for the specified key. Read more
Source§

impl<K, V, MT, const N: usize> PartialEq<MT> for InlineScanMap<K, V, N>
where K: PartialEq, V: PartialEq, MT: MapQuery<K, V>,

Source§

fn eq(&self, other: &MT) -> 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<K, V, const SZ: usize> Serialize for InlineScanMap<K, V, SZ>
where K: Serialize, V: Serialize,

Available on crate feature serde only.
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<K, V, const N: usize> Eq for InlineScanMap<K, V, N>
where K: Eq, V: Eq,

Source§

impl<K, V, Q, const SZ: usize> Map<K, V, Q> for InlineScanMap<K, V, SZ>
where Q: ?Sized + Equivalent<K>,

Auto Trait Implementations§

§

impl<K, V, const SZ: usize> Freeze for InlineScanMap<K, V, SZ>
where K: Freeze, V: Freeze,

§

impl<K, V, const SZ: usize> RefUnwindSafe for InlineScanMap<K, V, SZ>

§

impl<K, V, const SZ: usize> Send for InlineScanMap<K, V, SZ>
where K: Send, V: Send,

§

impl<K, V, const SZ: usize> Sync for InlineScanMap<K, V, SZ>
where K: Sync, V: Sync,

§

impl<K, V, const SZ: usize> Unpin for InlineScanMap<K, V, SZ>
where K: Unpin, V: Unpin,

§

impl<K, V, const SZ: usize> UnsafeUnpin for InlineScanMap<K, V, SZ>
where K: UnsafeUnpin, V: UnsafeUnpin,

§

impl<K, V, const SZ: usize> UnwindSafe for InlineScanMap<K, V, SZ>
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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

Compare self to key and return true if they are equal.
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.