[][src]Struct ccl::dhashmap::DHashMap

pub struct DHashMap<K, V> where
    K: Hash + Eq
{ /* fields omitted */ }

DHashMap is a threadsafe, versatile and concurrent hashmap with good performance and is balanced for both reads and writes.

The API mostly matches that of the standard library hashmap but there are some differences to due to the design.

One of those limits is iteration, you cannot iterate over the elements directly. Instead you have to iterate over chunks which can iterate over KV pairs. This is needed in order to use the calling thread stack as scratch space to avoid heap allocations.

Unsafe is used to avoid bounds checking when accessing chunks. This is guaranteed to be safe since we cannot possibly get a value higher than the amount of chunks. The amount of chunks cannot be altered after creation in any way.

This map is not lockfree but uses some clever locking internally. It has good average case performance but you should not rely on being able to hold any combination of references involving a mutable one as it may cause a deadlock.

Methods

impl<'a, K: 'a, V: 'a> DHashMap<K, V> where
    K: Hash + Eq
[src]

pub fn new(submaps_exp_of_two_pow: usize) -> Self[src]

Create a new DHashMap. The amount of chunks used is based on the formula 2^n where n is the value passed. The default method will automagically determine the optimal amount.

Will panic if the first parameter plugged into the formula 2^n produces a result higher than isize::MAX.

pub fn with_capacity(submaps_exp_of_two_pow: usize, capacity: usize) -> Self[src]

Create a new DHashMap with a specified capacity.

Will panic if the first parameter plugged into the formula 2^n produces a result higher than isize::MAX.

pub fn insert(&self, key: K, value: V)[src]

Insert an element into the map.

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

Check if the map contains the specified key.

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

Get a shared reference to an element contained within the map.

pub fn index(&'a self, key: &'a K) -> DHashMapRef<'a, K, V>[src]

Shortcut for a get followed by an unwrap.

pub fn get_mut(&'a self, key: &'a K) -> Option<DHashMapRefMut<'a, K, V>>[src]

Get a unique reference to an element contained within the map.

pub fn index_mut(&'a self, key: &'a K) -> DHashMapRefMut<'a, K, V>[src]

Shortcut for a get_mut followed by an unwrap.

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

Get the amount of elements stored within the map.

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

Check if the map is empty.

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

Remove an element from the map if it exists. Will return the K, V pair.

pub fn retain<F: Clone + FnMut(&K, &mut V) -> bool>(&self, f: F)[src]

Retain all elements that the specified function returns true for.

pub fn clear(&self)[src]

Clear all elements from the map.

pub fn alter<F: FnMut((&K, &mut V)) + Clone>(&self, f: F)[src]

Apply a function to every item in the map.

pub fn tables_read(&self) -> impl Iterator<Item = SMRInterface<K, V>>[src]

Iterate over chunks in a read only fashion.

pub fn tables_write(&self) -> impl Iterator<Item = SMRWInterface<K, V>>[src]

Iterate over chunks in a read-write fashion.

Trait Implementations

impl<K, V> Default for DHashMap<K, V> where
    K: Hash + Eq
[src]

fn default() -> Self[src]

Creates a new DHashMap and automagically determines the optimal amount of chunks.

Auto Trait Implementations

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

impl<K, V> Sync for DHashMap<K, V> where
    K: Send + Sync,
    V: Send + Sync

Blanket Implementations

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

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

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.

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

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

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