Skip to main content

ScatteredMap

Struct ScatteredMap 

Source
pub struct ScatteredMap<K: 'static, V: 'static> { /* private fields */ }
Expand description

A swiss-table-style lookup table initialized with link-time data. Each item in the map must have a unique hash.

For a flat list in arbitrary link order, use crate::ScatteredSlice. For a sorted list without per-item handles, use crate::ScatteredSortedSlice. For static handles at scatter sites, use crate::ScatteredReferencedSlice; when sorted order is required as well, use crate::ScatteredSortedReferencedSlice.

§Performance notes

The map’s metadata section is only ever written to once, and then becomes read-only. This means that we can avoid tombstone logic.

Metadata is arranged in 16-slot SIMD groups for optimal performance.

//! Example for `ScatteredMap`.
use scattered_collect::{gather, map::ScatteredMap, scatter};

#[derive(Debug, Eq, PartialEq, Ord, PartialOrd)]
struct MyId(u32);

#[gather]
static MAP: ScatteredMap<&'static str, MyId>;

#[scatter(MAP)]
static APPLE: (&'static str, MyId) = ("apple", MyId(1));

#[scatter(MAP)]
static BANANA: (&'static str, MyId) = ("banana", MyId(2));

#[scatter(MAP)]
static ORANGE: (&'static str, MyId) = ("orange", MyId(3));

fn main() {
    println!("APPLE: {:?}", APPLE);
    println!("BANANA: {:?}", BANANA);
    println!("ORANGE: {:?}", ORANGE);

    println!("Entries:");
    for (key, value) in &MAP {
        println!(" - {}: {:?}", key, value);
    }
}

Implementations§

Source§

impl<K: ConstHash + PartialEq + 'static, V: 'static> ScatteredMap<K, V>

Source

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

Lookup a value by key.

Source

pub fn entries(&self) -> impl Iterator<Item = (&K, &V)>

Iterate over the entries in the map.

Source

pub fn keys(&self) -> impl Iterator<Item = &K>

Iterate over the keys in the map.

Source

pub fn values(&self) -> impl Iterator<Item = &V>

Iterate over the values in the map.

Source

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

True when a key is present in the map.

Source

pub fn len(&self) -> usize

The number of records in the map.

Source

pub fn is_empty(&self) -> bool

True if the map has no records.

Trait Implementations§

Source§

impl<K: 'static, V: 'static> IntoIterator for &'static ScatteredMap<K, V>

Source§

type Item = (&'static K, &'static V)

The type of the elements being iterated over.
Source§

type IntoIter = Map<Iter<'static, MapRecord<K, V>>, fn(&MapRecord<K, V>) -> (&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 ScatteredMap<K, V>

§

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

§

impl<K, V> Send for ScatteredMap<K, V>
where K: Sync, V: Sync,

§

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

§

impl<K, V> Unpin for ScatteredMap<K, V>

§

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

§

impl<K, V> UnwindSafe for ScatteredMap<K, V>

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 = 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.