Struct concurrent_hashmap::ConcHashMap [] [src]

pub struct ConcHashMap<K, V, H = RandomState> where K: Send + Sync, V: Send + Sync { /* fields omitted */ }

A concurrent hashmap using sharding and reader-writer locking.

Methods

impl<K, V, H> ConcHashMap<K, V, H> where K: Hash + Eq + Send + Sync, V: Send + Sync, H: BuildHasher
[src]

Creates a new hashmap using default options

Creates a new hashmap with custom options

Searches for a key, returning an accessor to the mapped values (or None if no mapping exists).

Note that as long as the Accessor lives, a lock is held.

Examples

Printing a value if it exists:

map.insert(100, 1);
if let Some(val) = map.find(&100) {
    println!("100 => {}", val.get());
}

Searches for a key, returning a mutable accessor to the mapped value (or None if no mapping exists).

Note that as long as the MutAccessor lives, a lock is held.

Examples

Adding 2 to a value if it exists:

map.insert(100, 1);
if let Some(mut val) = map.find_mut(&100) {
    *val.get() += 2;
}

Inserts a new mapping from key to value. If a previous mapping existed for key, it is returned.

Performs on "upsert" operation: Updates the value currently mapped to key using updater, or maps key to value if no previous mapping existed.

Examples

let word_counts = ConcHashMap::<String, u32>::new();
let words = ["a", "car", "is", "a", "thing"];
for word in words.iter().map(|s| s.to_string()) {
    word_counts.upsert(word, 1, &|count| *count += 1);
}
// Map is now "a"=>2, "car"=>1, "thing"=>1

Removes any mapping associated with key.

If a mapping was removed, the mapped values is returned.

impl<K, V, H> ConcHashMap<K, V, H> where K: Send + Sync, V: Send + Sync
[src]

Iterates over all mappings.

This method does not provide a consistent snapshot of the map. All mappings returned must have been in the map at some point, but updates performed during the iteration may or may not be reflected.

Iterating may block writers.

Removes all mappings.

In the absence of external synchronization, the map can not be guaranteed to have been empty at any point during or after the .clear() call.

Trait Implementations

impl<K, V, H> Clone for ConcHashMap<K, V, H> where K: Hash + Eq + Send + Sync + Clone, V: Send + Sync + Clone, H: BuildHasher + Clone
[src]

Clones the hashmap, returning a new map with the same mappings and hasher.

If a consistent snapshot is desired, external synchronization is required. In the absence of external synchronization, this method has the same consistency guarantees as .iter().

Performs copy-assignment from source. Read more

impl<K, V, H> FromIterator<(K, V)> for ConcHashMap<K, V, H> where K: Eq + Hash + Send + Sync, V: Send + Sync, H: BuildHasher + Default
[src]

Creates a value from an iterator. Read more

impl<K, V, H> Default for ConcHashMap<K, V, H> where K: Hash + Eq + Send + Sync, V: Send + Sync, H: BuildHasher + Default
[src]

Equivalent to ConcHashMap::new().