Skip to main content

AsyncShardedHashMap

Struct AsyncShardedHashMap 

Source
pub struct AsyncShardedHashMap<K, V, S = FxBuildHasher>
where K: Eq + Hash + Clone + Send + Sync, V: Clone + Send + Sync, S: BuildHasher + Clone + Send + Sync,
{ /* private fields */ }
Available on crate feature async only.
Expand description

Asynchronous sharded concurrent HashMap (Tokio RwLock).

Implementations§

Source§

impl<K, V> AsyncShardedHashMap<K, V, FxBuildHasher>
where K: Eq + Hash + Clone + Send + Sync, V: Clone + Send + Sync,

Source

pub fn new(shard_count: usize) -> Self

Create with default hasher.

§Arguments
  • shard_count: number of shards (0 defaults to DEFAULT_SHARDS).
§Returns
  • Self: new async sharded hash map.
Source§

impl<K, V, S> AsyncShardedHashMap<K, V, S>
where K: Eq + Hash + Clone + Send + Sync, V: Clone + Send + Sync, S: BuildHasher + Clone + Send + Sync,

Source

pub fn with_shards_and_hasher(shard_count: usize, hasher: S) -> Self

Create with custom hasher.

§Arguments
  • shard_count: number of shards (0 defaults to `DEFAULT_SHARDS
  • hasher: user-supplied hasher instance.
§Returns
  • Self: new async sharded hash map.
Source

pub fn shard_count(&self) -> usize

Configured shard capacity.

§Returns
  • usize: number of shard slots.
Source

pub async fn initialized_shards(&self) -> usize

Number of initialized shards.

§Returns
  • usize: count of allocated shards.
Source

pub async fn insert(&self, key: K, value: V) -> Option<V>

Insert key/value asynchronously.

§Arguments
  • key: key to insert.
  • value: value to associate with the key.
§Returns
  • Option<V>: previous value if the key was already present.
Source

pub async fn get(&self, key: &K) -> Option<V>

Get cloned value; uses try_read first (fast path, reduces scheduler churn).

§Arguments
  • key: key to look up.
§Returns
  • Option<V>: cloned value if the key exists.
Source

pub async fn contains(&self, key: &K) -> bool

Check if a key exists; uses try_read first (fast path, reduces scheduler churn).

§Arguments
  • key: key to check.
§Returns
  • bool: true if the key exists in the map, false otherwise.
Source

pub async fn remove(&self, key: &K) -> Option<V>

Remove key.

§Arguments
  • key: key to remove.
§Returns
  • Option<V>: previous value if the key existed.
Source

pub async fn len(&self) -> usize

Length (atomic).

§Returns
  • usize: total number of key/value pairs in the map.
Source

pub async fn is_empty(&self) -> bool

Empty check.

§Returns
  • bool: true if the map contains no entries.
Source

pub async fn clear(&self)

Clear (retains allocated shards).

§Notes
  • Resets length counter to zero.
Source

pub async fn iter(&self) -> Vec<(K, V)>

Snapshot iteration (async).

Steps:

  1. Snapshot Arc list of initialized shards under read lock of the shard vector.
  2. For each shard: try try_read; fallback to await read.
  3. Clone inner HashMaps (short critical sections).
  4. If rayon enabled, parallel flatten of snapshots.

Returns a materialized Vec.

Source§

impl<K, V> AsyncShardedHashMap<K, V>
where K: Eq + Hash + Clone + Send + Sync + Serialize, V: Clone + Send + Sync + Serialize,

Source

pub async fn async_snapshot_serializable( &self, ) -> AsyncShardedHashMapSnapshot<K, V>

Available on crate feature serde only.

Obtain a serializable snapshot wrapper (for serde).

Trait Implementations§

Source§

impl<K, V, S> Clone for AsyncShardedHashMap<K, V, S>
where K: Eq + Hash + Clone + Send + Sync + Clone, V: Clone + Send + Sync + Clone, S: BuildHasher + Clone + Send + Sync + Clone,

Source§

fn clone(&self) -> AsyncShardedHashMap<K, V, S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<K, V, S> Freeze for AsyncShardedHashMap<K, V, S>
where S: Freeze,

§

impl<K, V, S = FxBuildHasher> !RefUnwindSafe for AsyncShardedHashMap<K, V, S>

§

impl<K, V, S> Send for AsyncShardedHashMap<K, V, S>

§

impl<K, V, S> Sync for AsyncShardedHashMap<K, V, S>

§

impl<K, V, S> Unpin for AsyncShardedHashMap<K, V, S>
where S: Unpin,

§

impl<K, V, S = FxBuildHasher> !UnwindSafe for AsyncShardedHashMap<K, V, S>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.