Struct HashMap

Source
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>

Source

pub fn new() -> Self

new returns an instance with N shards. N gets rounded to nearest power of two.

Source

pub fn new_arc() -> Arc<Self>

new_arc returns a new instance contained in an arc pointer.

Source

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.

Source

pub fn get_shard(&'a self, key: K) -> (&'a Arc<RwLock<Shard<K, V>>>, u64)
where K: Hash + Eq + IKey<K>, V: Clone,

get_shard returns the shard lock along with its hash.

Source

pub fn get_owned(&'a self, key: K) -> Option<V>
where K: Hash + Eq + IKey<K>, V: Clone,

get_owned returns the cloned value associated with the given key.

Source

pub fn insert(&self, key: K, value: V)
where K: Hash + Eq + IKey<K>,

insert inserts the given key, value pair into a shard based on the hash value of key.

Source

pub fn remove(&self, key: K) -> Option<V>
where K: Hash + Eq + IKey<K>,

remove removes the entry associated with key from the corresponding shard.

Source

pub fn contains(&self, key: K) -> bool
where K: Hash + Eq + IKey<K>,

contains returns whether any entry is associated with the given key.

Source

pub fn len(&self) -> usize

len returns the sum of total number of all entries stored in each shard table.

Source

pub fn into_iter(&self) -> IntoIter<K, V>

into_iter creates an iterator for shards.

Trait Implementations§

Source§

impl<K: Clone + Send + Sync, V: Clone + Send + Sync, const N: usize> Default for HashMap<K, V, N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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>
where K: Send + Sync, V: Send + Sync,

§

impl<K, V, const N: usize> Sync for HashMap<K, V, N>
where K: Send + Sync, V: Send + Sync,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.