[][src]Struct compact::CDict

pub struct CDict<K: Copy, V: Compact + Clone, A: Allocator = DefaultHeap> { /* fields omitted */ }

A simple linear-search key-value dictionary, implemented using two CompactVec's, one for keys, one for values.

The API loosely follows that of std::collections::HashMap. Spilling behaviour using Allocator is equivalent to CompactVec.

Implementations

impl<K: Eq + Copy, V: Compact + Clone, A: Allocator> CompactDict<K, V, A>[src]

pub fn new() -> Self[src]

Create new, empty dictionary

pub fn with_capacity(cap: usize) -> Self[src]

Create new, empty dictionary with a given capactity

pub fn len(&self) -> usize[src]

Amount of entries in the dictionary

pub fn is_empty(&self) -> bool[src]

Is the dictionary empty?

pub fn get(&self, query: K) -> Option<&V>[src]

Look up the value for key query, if it exists

pub fn get_mut(&mut self, query: K) -> Option<&mut V>[src]

Look up the value for keu query mutably, if it exists

pub fn get_mru(&mut self, query: K) -> Option<&V>[src]

Lookup up the value for key query, if it exists, but also swap the entry to the beginning of the key/value vectors, so a repeated lookup for that item will be faster

pub fn get_mfu(&mut self, query: K) -> Option<&V>[src]

Lookup up the value for key query, if it exists, but also swap the entry one index towards the beginning of the key/value vectors, so frequently repeated lookups for that item will be faster

pub fn contains_key(&self, query: K) -> bool[src]

Does the dictionary contain a value for query?

pub fn insert(&mut self, query: K, new_value: V) -> Option<V>[src]

Insert new value at key query and return the previous value at that key, if any existed

pub fn remove(&mut self, query: K) -> Option<V>[src]

Remove value at key query and return it, if it existed

pub fn keys(&self) -> Iter<'_, K>[src]

Iterator over all keys in the dictionary

pub fn values(&self) -> Iter<'_, V>[src]

Iterator over all values in the dictionary

pub fn values_mut(&mut self) -> IterMut<'_, V>[src]

Iterator over mutable references to all values in the dictionary

pub fn pairs<'a>(&'a self) -> impl Iterator<Item = (&'a K, &'a V)> + Clone + 'a[src]

Iterator over all key-value pairs in the dictionary

impl<K: Eq + Copy, I: Compact, A1: Allocator, A2: Allocator> CompactDict<K, CompactVec<I, A1>, A2>[src]

pub fn push_at(&mut self, query: K, item: I)[src]

Push a value onto the CompactVec at the key query

pub fn get_iter<'a>(&'a self, query: K) -> impl Iterator<Item = &'a I> + 'a[src]

Iterator over the CompactVec at the key query

pub fn remove_iter<'a>(&'a mut self, query: K) -> impl Iterator<Item = I> + 'a[src]

Remove the CompactVec at the key query and iterate over its elements (if it existed)

Trait Implementations

impl<K: Copy, V: Compact + Clone, A: Allocator> Clone for CompactDict<K, V, A>[src]

impl<K: Copy, V: Compact + Clone, A: Allocator> Compact for CompactDict<K, V, A>[src]

impl<K, V, A> Debug for CompactDict<K, V, A> where
    K: Copy + Eq + Debug,
    V: Compact + Debug,
    A: Allocator
[src]

impl<K: Copy + Eq, V: Compact + Clone, A: Allocator> Default for CompactDict<K, V, A>[src]

impl<K: Copy + Eq, V: Compact + Clone, A: Allocator> Extend<(K, V)> for CompactDict<K, V, A>[src]

fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)[src]

Extend a compact dictionary from an iterator over key-value pairs

impl<K: Copy + Eq, V: Compact + Clone, A: Allocator> FromIterator<(K, V)> for CompactDict<K, V, A>[src]

fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self[src]

Construct a compact dictionary from an interator over key-value pairs

Auto Trait Implementations

impl<K, V, A> RefUnwindSafe for CompactDict<K, V, A> where
    A: RefUnwindSafe,
    K: RefUnwindSafe,
    V: RefUnwindSafe

impl<K, V, A = DefaultHeap> !Send for CompactDict<K, V, A>

impl<K, V, A = DefaultHeap> !Sync for CompactDict<K, V, A>

impl<K, V, A> Unpin for CompactDict<K, V, A>

impl<K, V, A> UnwindSafe for CompactDict<K, V, A> where
    A: RefUnwindSafe,
    K: RefUnwindSafe,
    V: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.