pub struct HashMap<K, V, H = RandomState> where
    K: 'static + Eq + Hash + Sync,
    V: 'static + Sync,
    H: BuildHasher
{ /* private fields */ }
Expand description

Scalable concurrent hash map data structure for asynchronous code.

The data structure is almost identical to HashMap except that most methods return future thereby allowing the data structures to be used in asynchronous code without blocking execution.

Implementations

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);

Inserts a key-value pair into the HashMap.

Errors

Returns an error along with the supplied key-value pair.

Examples
use scc::awaitable::HashMap;

let hashmap: HashMap<u64, u32> = HashMap::default();
let future_insert = hashmap.insert(11, 17);

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);

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);

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);

Iterates over all the entries in the HashMap.

Examples
use scc::awaitable::HashMap;

let hashmap: HashMap<u64, u32> = HashMap::default();

let future_insert = hashmap.insert(1, 0);
let future_for_each = hashmap.for_each(|k, v| println!("{} {}", k, v));

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);

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();

Returns the number of entries in the HashMap.

It scans the entire array to calculate the number of valid entries, making its time complexity O(N).

Examples
use scc::awaitable::HashMap;

let hashmap: HashMap<u64, u32> = HashMap::default();

assert_eq!(hashmap.len(), 0);

Returns true if the HashMap is empty.

It scans the entire array to calculate the number of valid entries, making its time complexity O(N).

Examples
use scc::awaitable::HashMap;

let hashmap: HashMap<u64, u32> = HashMap::default();

assert!(hashmap.is_empty());

Returns the capacity of the HashMap.

Examples
use scc::awaitable::HashMap;
use std::collections::hash_map::RandomState;

let hashmap: HashMap<u64, u32, RandomState> = HashMap::new(1000000, RandomState::new());
assert_eq!(hashmap.capacity(), 1048576);

Trait Implementations

Creates a HashMap with the default parameters.

The default hash builder is RandomState, and the default capacity is 64.

Panics

Panics if memory allocation fails.

Examples
use scc::awaitable::HashMap;

let hashmap: HashMap<u64, u32> = HashMap::default();

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.