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]
fn new() -> ConcHashMap<K, V>
Creates a new hashmap using default options
fn with_options(opts: Options<H>) -> ConcHashMap<K, V, H>
Creates a new hashmap with custom options
fn find<'a, Q: ?Sized>(&'a self, key: &Q) -> Option<Accessor<'a, K, V>> where K: Borrow<Q> + Hash + Eq + Send + Sync, Q: Hash + Eq + Sync
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()); }
fn find_mut<'a, Q: ?Sized>(&'a self, key: &Q) -> Option<MutAccessor<'a, K, V>> where K: Borrow<Q> + Hash + Eq + Send + Sync, Q: Hash + Eq + Sync
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; }
fn insert(&self, key: K, value: V) -> Option<V>
Inserts a new mapping from key
to value
.
If a previous mapping existed for key
, it is returned.
fn upsert<U: Fn(&mut V)>(&self, key: K, value: V, updater: &U)
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
fn remove<'a, Q: ?Sized>(&'a self, key: &Q) -> Option<V> where K: Borrow<Q> + Hash + Eq + Send + Sync, Q: Hash + Eq + Sync
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]
fn iter<'a>(&'a self) -> Entries<'a, K, V, H>
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.
fn clear(&self)
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]
fn clone(&self) -> ConcHashMap<K, V, H>
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().
fn clone_from(&mut self, source: &Self)
1.0.0
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]
fn from_iter<T>(iterator: T) -> Self where T: IntoIterator<Item=(K, V)>
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]
fn default() -> ConcHashMap<K, V, H>
Equivalent to ConcHashMap::new()
.