[go: up one dir, main page]

[][src]Struct cht::map::HashMap

pub struct HashMap<K, V, S = DefaultHashBuilder> { /* fields omitted */ }

A lockfree concurrent hash map implemented with open addressing and linear probing.

The default hashing algorithm is aHash, a hashing algorithm that is accelerated by the AES-NI instruction set on x86 proessors. aHash provides some resistance to DoS attacks, but will not provide the same level of resistance as something like RandomState.

The hashing algorithm to be used can be chosen on a per-HashMap basis using the with_hasher and with_capacity_and_hasher methods.

Key types must implement Hash and Eq. Any operations that return a key or value require the return types to implement Clone, as elements may be in use by other threads and as such cannot be moved from.

HashMap is inspired by Jeff Phreshing's hash tables implemented in Junction, described in this blog post. In short, HashMap supports fully concurrent lookups, insertions, removals, and updates.

Methods

impl<K, V> HashMap<K, V, DefaultHashBuilder>[src]

pub fn new() -> HashMap<K, V, DefaultHashBuilder>[src]

Creates an empty HashMap.

The hash map is created with a capacity of 0 and will not allocate any space for elements until the first insertion.

pub fn with_capacity(capacity: usize) -> HashMap<K, V, DefaultHashBuilder>[src]

Creates an empty HashMap with space for at least capacity elements without reallocating.

If capacity == 0, no allocations will occur.

impl<K, V, S> HashMap<K, V, S>[src]

pub fn with_hasher(build_hasher: S) -> HashMap<K, V, S>[src]

Creates an empty HashMap that will use build_hasher to hash keys.

The created map will have a capacity of 0 and as such will not have any space for elements allocated until the first insertion.

pub fn with_capacity_and_hasher(
    capacity: usize,
    build_hasher: S
) -> HashMap<K, V, S>
[src]

Creates an empty HashMap that will hold at least capacity elements without reallocating and that uses build_hasher to hash keys.

If capacity == 0, no allocations will occur.

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

Returns the number of elements that are confirmed to have been inserted into this map.

Because HashMap can be updated concurrently, this function reflects the number of insert operations that have returned to the user. In-progress insertions are not counted.

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

Returns true if this HashMap contains no confirmed inserted elements.

In-progress insertions into this HashMap are not considered.

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

Returns the number of elements this HashMap can hold without reallocating a table.

Note that all mutating operations, with the exception of removing elements, incur at least one allocation for the associated bucket.

If there are insertion operations in flight, it is possible that a new, larger table has already been allocated.

impl<K: Hash + Eq, V, S: BuildHasher> HashMap<K, V, S>[src]

pub fn get<Q: Hash + Eq + ?Sized>(&self, key: &Q) -> Option<V> where
    K: Borrow<Q>,
    V: Clone
[src]

Returns a copy of the value corresponding to key.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K. V must implement Clone, as the value may be deleted at any moment; the best we can do is to clone them while we know they exist.

pub fn get_key_value<Q: Hash + Eq + ?Sized>(&self, key: &Q) -> Option<(K, V)> where
    K: Borrow<Q> + Clone,
    V: Clone
[src]

Returns a copy of the key and value corresponding to key.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K. K and V must implement Clone, as the bucket may be concurrently removed at any time; the best we can do is to clone them while we know they exist.

pub fn get_and<Q: Hash + Eq + ?Sized, F: FnOnce(&V) -> T, T>(
    &self,
    key: &Q,
    with_value: F
) -> Option<T> where
    K: Borrow<Q>, 
[src]

Invokes with_value with a reference to the value corresponding to key.

with_value will only be invoked if there is a value associated with key contained within this hash map.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K.

pub fn get_key_value_and<Q: Hash + Eq + ?Sized, F: FnOnce(&K, &V) -> T, T>(
    &self,
    key: &Q,
    with_entry: F
) -> Option<T> where
    K: Borrow<Q>, 
[src]

Invokes with_entry with a reference to the key and value corresponding to key.

with_entry will only be invoked if there is a value associated with key contained within this hash map.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K.

pub fn insert(&self, key: K, value: V) -> Option<V> where
    V: Clone
[src]

Inserts a key-value pair, then returns a copy of the value previously associated with key.

If the key was not previously present in this hash map, None is returned.

V must implement Clone, as other threads may hold references to the associated value.

pub fn insert_entry(&self, key: K, value: V) -> Option<(K, V)> where
    K: Clone,
    V: Clone
[src]

Inserts a key-value pair, then returns a copy of the previous entry.

If the key was not previously present in this hash map, None is returned.

K and V must implement Clone, as other threads may hold references to the entry.

pub fn insert_and<F: FnOnce(&V) -> T, T>(
    &self,
    key: K,
    value: V,
    with_previous_value: F
) -> Option<T>
[src]

Inserts a key-value pair, then invokes with_previous_value with the value previously associated with key.

If the key was not previously present in this hash map, None is returned and with_previous_value is not invoked.

pub fn insert_entry_and<F: FnOnce(&K, &V) -> T, T>(
    &self,
    key: K,
    value: V,
    with_previous_entry: F
) -> Option<T>
[src]

Inserts a key-value pair, then invokes with_previous_entry with the previous entry.

If the key was not previously present in this hash map, None is returned and with_previous_entry is not invoked.

pub fn remove<Q: Hash + Eq + ?Sized>(&self, key: &Q) -> Option<V> where
    K: Borrow<Q>,
    V: Clone
[src]

If there is a value associated with key, remove and return a copy of it.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K. V must implement Clone, as other threads may hold references to the associated value.

pub fn remove_entry<Q: Hash + Eq + ?Sized>(&self, key: &Q) -> Option<(K, V)> where
    K: Borrow<Q> + Clone,
    V: Clone
[src]

If there is a value associated with key, remove it and return a copy of the previous entity.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K. K and V must implement Clone, as other threads may hold references to the entry.

pub fn remove_and<Q: Hash + Eq + ?Sized, F: FnOnce(&V) -> T, T>(
    &self,
    key: &Q,
    with_previous_value: F
) -> Option<T> where
    K: Borrow<Q>, 
[src]

If there is a value associated with key, remove it and return the result of invoking with_previous_value with that value.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K.

pub fn remove_entry_and<Q: Hash + Eq + ?Sized, F: FnOnce(&K, &V) -> T, T>(
    &self,
    key: &Q,
    with_previous_entry: F
) -> Option<T> where
    K: Borrow<Q>, 
[src]

If there is a value associated with key, remove it and return the result of invoking with_previous_entry with that entry.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K.

pub fn remove_if<Q: Hash + Eq + ?Sized, F: FnMut(&K, &V) -> bool>(
    &self,
    key: &Q,
    condition: F
) -> Option<V> where
    K: Borrow<Q>,
    V: Clone
[src]

If there is a value associated with key and condition returns true when invoked with the current entry, remove and return a copy of its value.

condition may be invoked one or more times, even if no entry was removed.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K. K and V must implement Clone, as other threads may hold references to the entry.

pub fn remove_entry_if<Q: Hash + Eq + ?Sized, F: FnMut(&K, &V) -> bool>(
    &self,
    key: &Q,
    condition: F
) -> Option<(K, V)> where
    K: Clone + Borrow<Q>,
    V: Clone
[src]

If there is a value associated with key and condition returns true when invoked with the current entry, remove and return a copy of it.

condition may be invoked one or more times, even if no entry was removed.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K. K and V must implement Clone, as other threads may hold references to the entry.

pub fn remove_if_and<Q: Hash + Eq + ?Sized, F: FnMut(&K, &V) -> bool, G: FnOnce(&V) -> T, T>(
    &self,
    key: &Q,
    condition: F,
    with_previous_value: G
) -> Option<T> where
    K: Borrow<Q>, 
[src]

If there is a value associated with key and condition returns true when invoked with the current entry, remove it and return the result of invoking with_previous_value with its value.

condition may be invoked one or more times, even if no entry was removed. If condition failed or there was no value associated with key, with_previous_entry is not invoked and None is returned.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K.

pub fn remove_entry_if_and<Q: Hash + Eq + ?Sized, F: FnMut(&K, &V) -> bool, G: FnOnce(&K, &V) -> T, T>(
    &self,
    key: &Q,
    condition: F,
    with_previous_entry: G
) -> Option<T> where
    K: Borrow<Q>, 
[src]

If there is a value associated with key and condition returns true when invoked with the current entry, remove it and return the result of invoking with_previous_entry with it.

condition may be invoked one or more times, even if no entry was removed. If condition failed or there was no value associated with key, with_previous_entry is not invoked and None is returned.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K.

pub fn insert_or_modify<F: FnMut(&K, &V) -> V>(
    &self,
    key: K,
    value: V,
    on_modify: F
) -> Option<V> where
    V: Clone
[src]

Insert a value if none is associated with key. Otherwise, replace the value with the result of on_modify with the current entry as arguments. Finally, return a copy of the previously associated value.

If there is no value associated with key, None will be returned. on_modify may be invoked multiple times, even if None is returned.

V must implement Clone, as other threads may hold references to the associated value.

pub fn insert_or_modify_entry<F: FnMut(&K, &V) -> V>(
    &self,
    key: K,
    value: V,
    on_modify: F
) -> Option<(K, V)> where
    K: Clone,
    V: Clone
[src]

Insert a value if none is associated with key. Otherwise, replace the value with the result of on_modify with the current entry as arguments. Finally, return a copy of the previous entry.

If there is no value associated with key, None will be returned. on_modify may be invoked multiple times, even if None is returned.

K and V must implement Clone, as other threads may hold references to the entry.

pub fn insert_with_or_modify<F: FnOnce() -> V, G: FnMut(&K, &V) -> V>(
    &self,
    key: K,
    on_insert: F,
    on_modify: G
) -> Option<V> where
    V: Clone
[src]

Insert the result of on_insert if no value is associated with key. Otherwise, replace the value with the result of on_modify with the current entry as arguments. Finally, return a copy of the previously associated value.

If there is no value associated with key, on_insert will be invoked and None will be returned. on_modify may be invoked multiple times, even if None is returned. Similarly, on_insert may be invoked if Some is returned.

V must implement Clone, as other threads may hold references to the associated value.

pub fn insert_with_or_modify_entry<F: FnOnce() -> V, G: FnMut(&K, &V) -> V>(
    &self,
    key: K,
    on_insert: F,
    on_modify: G
) -> Option<(K, V)> where
    K: Clone,
    V: Clone
[src]

Insert the result of on_insert if no value is associated with key. Otherwise, replace the value with the result of on_modify with the current entry as arguments. Finally, return a copy of the previous entry.

If there is no value associated with key, on_insert will be invoked and None will be returned. on_modify may be invoked multiple times, even if None is returned. Similarly, on_insert may be invoked if Some is returned.

K and V must implement Clone, as other threads may hold references to the entry.

pub fn insert_or_modify_and<F: FnMut(&K, &V) -> V, G: FnOnce(&V) -> T, T>(
    &self,
    key: K,
    value: V,
    on_modify: F,
    with_old_value: G
) -> Option<T>
[src]

Insert a value if none is associated with key. Otherwise, replace the value with the result of on_modify with the current entry as arguments. Finally, return the result of invoking with_old_value with the previously associated value.

If there is no value associated with key, with_old_value will not be invoked and None will be returned. on_modify may be invoked multiple times, even if None is returned.

pub fn insert_or_modify_entry_and<F: FnMut(&K, &V) -> V, G: FnOnce(&K, &V) -> T, T>(
    &self,
    key: K,
    value: V,
    on_modify: F,
    with_old_entry: G
) -> Option<T>
[src]

Insert a value if none is associated with key. Otherwise, replace the value with the result of on_modify with the current entry as arguments. Finally, return the result of invoking with_old_entry with the previous entry.

If there is no value associated with key, with_old_value will not be invoked and None will be returned. on_modify may be invoked multiple times, even if None is returned.

pub fn insert_with_or_modify_and<F: FnOnce() -> V, G: FnMut(&K, &V) -> V, H: FnOnce(&V) -> T, T>(
    &self,
    key: K,
    on_insert: F,
    on_modify: G,
    with_old_value: H
) -> Option<T>
[src]

Insert the result of on_insert if no value is associated with key. Otherwise, replace the value with the result of on_modify with the current entry as arguments. Finally, return the result of invoking with_old_value with the previously associated value.

If there is no value associated with key, on_insert will be invoked, with_old_value will not be invoked, and None will be returned. on_modify may be invoked multiple times, even if None is returned. Similarly, on_insert may be invoked if Some is returned.

pub fn insert_with_or_modify_entry_and<F: FnOnce() -> V, G: FnMut(&K, &V) -> V, H: FnOnce(&K, &V) -> T, T>(
    &self,
    key: K,
    on_insert: F,
    on_modify: G,
    with_old_entry: H
) -> Option<T>
[src]

Insert the result of on_insert if no value is associated with key. Otherwise, replace the value with the result of on_modify with the current entry as arguments. Finally, return the result of invoking with_old_entry with the previous entry.

If there is no value associated with key, on_insert will be invoked, with_old_value will not be invoked, and None will be returned. on_modify may be invoked multiple times, even if None is returned. Similarly, on_insert may be invoked if Some is returned.

pub fn modify<F: FnMut(&K, &V) -> V>(&self, key: K, on_modify: F) -> Option<V> where
    V: Clone
[src]

If there is a value associated with key, replace it with the result of invoking on_modify using the current key and value, then return a copy of the previously associated value.

If there is no value associated with key, None will be returned. on_modify may be invoked multiple times, even if None is returned.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K. V must implement Clone, as other threads may hold references to the associated value.

pub fn modify_entry<F: FnMut(&K, &V) -> V>(
    &self,
    key: K,
    on_modify: F
) -> Option<(K, V)> where
    K: Clone,
    V: Clone
[src]

If there is a value associated with key, replace it with the result of invoking on_modify using the current key and value, then return a copy of the previously entry.

If there is no value associated with key, None will be returned. on_modify may be invoked multiple times, even if None is returned.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K. K and V must implement Clone, as other threads may hold references to the entry.

pub fn modify_and<F: FnMut(&K, &V) -> V, G: FnOnce(&V) -> T, T>(
    &self,
    key: K,
    on_modify: F,
    with_old_value: G
) -> Option<T>
[src]

If there is a value associated with key, replace it with the result of invoking on_modify using the current key and value, then return the result of invoking with_old_value with the previously associated value.

If there is no value associated with key, with_old_value will not be invoked and None will be returned. on_modify may be invoked multiple times, even if None is returned.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K.

pub fn modify_entry_and<F: FnMut(&K, &V) -> V, G: FnOnce(&K, &V) -> T, T>(
    &self,
    key: K,
    on_modify: F,
    with_old_entry: G
) -> Option<T>
[src]

If there is a value associated with key, replace it with the result of invoking on_modify using the current key and value, then return the result of invoking with_old_value with the previous entry.

If there is no value associated with key, with_old_value will not be invoked and None will be returned. on_modify may be invoked multiple times, even if None is returned.

Q can be any borrowed form of K, but Hash and Eq on Q must match that of K.

Trait Implementations

impl<K: Default, V: Default, S: Default> Default for HashMap<K, V, S>[src]

impl<K, V, S> Drop for HashMap<K, V, S>[src]

Auto Trait Implementations

impl<K, V, S> RefUnwindSafe for HashMap<K, V, S> where
    K: RefUnwindSafe,
    S: RefUnwindSafe,
    V: RefUnwindSafe

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

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

impl<K, V, S> Unpin for HashMap<K, V, S> where
    S: Unpin

impl<K, V, S> UnwindSafe for HashMap<K, V, S> where
    K: RefUnwindSafe,
    S: UnwindSafe,
    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, 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.