pub struct HashMap<K, V, H = RandomState> where
K: 'static + Eq + Hash + Sync,
V: 'static + Sync,
H: BuildHasher, { /* private fields */ }
Expand description
Implementations
sourceimpl<K, V, H> HashMap<K, V, H> where
K: 'static + Eq + Hash + Sync,
V: 'static + Sync,
H: BuildHasher,
impl<K, V, H> HashMap<K, V, H> where
K: 'static + Eq + Hash + Sync,
V: 'static + Sync,
H: BuildHasher,
sourcepub fn new(capacity: usize, build_hasher: H) -> HashMap<K, V, H>
pub fn new(capacity: usize, build_hasher: H) -> HashMap<K, V, H>
Creates an empty HashMap
with the given capacity and BuildHasher
.
The actual capacity is equal to or greater than the given capacity.
Panics
Panics if memory allocation fails.
Examples
use scc::awaitable::HashMap;
use std::collections::hash_map::RandomState;
let hashmap: HashMap<u64, u32, RandomState> = HashMap::new(1000, RandomState::new());
let result = hashmap.capacity();
assert_eq!(result, 1024);
sourcepub async fn read<Q, R, F: FnMut(&K, &V) -> R>(
&self,
key_ref: &Q,
reader: F
) -> Option<R> where
K: Borrow<Q>,
Q: Eq + Hash + ?Sized,
pub async fn read<Q, R, F: FnMut(&K, &V) -> R>(
&self,
key_ref: &Q,
reader: F
) -> Option<R> where
K: Borrow<Q>,
Q: Eq + Hash + ?Sized,
Reads a key-value pair.
It returns None
if the key does not exist.
Examples
use scc::awaitable::HashMap;
let hashmap: HashMap<u64, u32> = HashMap::default();
let future_insert = hashmap.insert(11, 17);
let future_read = hashmap.read(&11, |_, v| *v);
sourcepub async fn remove<Q>(&self, key_ref: &Q) -> Option<(K, V)> where
K: Borrow<Q>,
Q: Eq + Hash + ?Sized,
pub async fn remove<Q>(&self, key_ref: &Q) -> Option<(K, V)> where
K: Borrow<Q>,
Q: Eq + Hash + ?Sized,
Removes a key-value pair if the key exists.
Examples
use scc::awaitable::HashMap;
let hashmap: HashMap<u64, u32> = HashMap::default();
let future_insert = hashmap.insert(11, 17);
let future_remove = hashmap.remove(&11);
sourcepub async fn remove_if<Q, F: FnMut(&V) -> bool>(
&self,
key_ref: &Q,
condition: F
) -> Option<(K, V)> where
K: Borrow<Q>,
Q: Eq + Hash + ?Sized,
pub async fn remove_if<Q, F: FnMut(&V) -> bool>(
&self,
key_ref: &Q,
condition: F
) -> Option<(K, V)> where
K: Borrow<Q>,
Q: Eq + Hash + ?Sized,
Removes a key-value pair if the key exists and the given condition is met.
Examples
use scc::awaitable::HashMap;
let hashmap: HashMap<u64, u32> = HashMap::default();
let future_insert = hashmap.insert(11, 17);
let future_remove = hashmap.remove_if(&11, |_| true);
sourcepub async fn retain<F: FnMut(&K, &mut V) -> bool>(
&self,
filter: F
) -> (usize, usize)
pub async fn retain<F: FnMut(&K, &mut V) -> bool>(
&self,
filter: F
) -> (usize, usize)
Retains key-value pairs that satisfy the given predicate.
It returns the number of entries remaining and removed.
Examples
use scc::awaitable::HashMap;
let hashmap: HashMap<u64, u32> = HashMap::default();
let future_insert = hashmap.insert(1, 0);
let future_retain = hashmap.retain(|k, v| *k == 1);
sourcepub async fn clear(&self) -> usize
pub async fn clear(&self) -> usize
Clears all the key-value pairs.
Examples
use scc::awaitable::HashMap;
let hashmap: HashMap<u64, u32> = HashMap::default();
let future_insert = hashmap.insert(1, 0);
let future_clear = hashmap.clear();
Trait Implementations
Auto Trait Implementations
impl<K, V, H> RefUnwindSafe for HashMap<K, V, H> where
H: RefUnwindSafe,
impl<K, V, H> Send for HashMap<K, V, H> where
H: Send,
impl<K, V, H> Sync for HashMap<K, V, H> where
H: Sync,
impl<K, V, H> Unpin for HashMap<K, V, H> where
H: Unpin,
impl<K, V, H = RandomState> !UnwindSafe for HashMap<K, V, H>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more