pub struct HashMap<K, V, const N: usize> { /* private fields */ }
Expand description
HashMap is a sharded hashmap which uses N
buckets,
each protected with an Read/Write lock. N
gets
rounded to nearest power of two.
Implementations§
Source§impl<'a, K: Clone + Send + Sync, V: Clone + Send + Sync, const N: usize> HashMap<K, V, N>
impl<'a, K: Clone + Send + Sync, V: Clone + Send + Sync, const N: usize> HashMap<K, V, N>
Sourcepub fn new() -> Self
pub fn new() -> Self
new returns an instance with N
shards.
N
gets rounded to nearest power of two.
Sourcepub fn with_shard(shards_size: usize) -> Self
pub fn with_shard(shards_size: usize) -> Self
with_shard returns a new instance with N
shards.
N
gets rounded to nearest power of two.
Sourcepub fn get_shard(&'a self, key: K) -> (&'a Arc<RwLock<Shard<K, V>>>, u64)
pub fn get_shard(&'a self, key: K) -> (&'a Arc<RwLock<Shard<K, V>>>, u64)
get_shard returns the shard lock along with its hash.
Sourcepub fn get_owned(&'a self, key: K) -> Option<V>
pub fn get_owned(&'a self, key: K) -> Option<V>
get_owned returns the cloned value associated
with the given key
.
Sourcepub fn insert(&self, key: K, value: V)
pub fn insert(&self, key: K, value: V)
insert inserts the given key
, value
pair into a shard based on the hash value
of key
.
Sourcepub fn remove(&self, key: K) -> Option<V>
pub fn remove(&self, key: K) -> Option<V>
remove removes the entry associated with key
from the corresponding shard.
Sourcepub fn contains(&self, key: K) -> bool
pub fn contains(&self, key: K) -> bool
contains returns whether any entry is
associated with the given key
.
Trait Implementations§
Auto Trait Implementations§
impl<K, V, const N: usize> Freeze for HashMap<K, V, N>
impl<K, V, const N: usize> !RefUnwindSafe for HashMap<K, V, N>
impl<K, V, const N: usize> Send for HashMap<K, V, N>
impl<K, V, const N: usize> Sync for HashMap<K, V, N>
impl<K, V, const N: usize> Unpin for HashMap<K, V, N>
impl<K, V, const N: usize> !UnwindSafe for HashMap<K, V, N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more