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 */ }async only.Expand description
Asynchronous sharded concurrent HashMap (Tokio RwLock).
Implementations§
Source§impl<K, V> AsyncShardedHashMap<K, V, FxBuildHasher>
impl<K, V> AsyncShardedHashMap<K, V, FxBuildHasher>
Source§impl<K, V, S> AsyncShardedHashMap<K, V, S>
impl<K, V, S> AsyncShardedHashMap<K, V, S>
Sourcepub fn with_shards_and_hasher(shard_count: usize, hasher: S) -> Self
pub fn with_shards_and_hasher(shard_count: usize, hasher: S) -> Self
Create with custom hasher.
This preserves backward compatibility while enforcing the default
safety cap (MAX_SHARDS) to avoid oversized allocations.
Sourcepub fn with_shards_and_hasher_capped(
shard_count: usize,
hasher: S,
max_shards: usize,
) -> Self
pub fn with_shards_and_hasher_capped( shard_count: usize, hasher: S, max_shards: usize, ) -> Self
Create with custom hasher and a custom cap.
Sourcepub fn try_with_shards_and_hasher(
shard_count: usize,
hasher: S,
) -> Result<Self, ShardCountError>
pub fn try_with_shards_and_hasher( shard_count: usize, hasher: S, ) -> Result<Self, ShardCountError>
Strict constructor with custom hasher.
Returns an error when the requested shard count exceeds MAX_SHARDS.
Sourcepub fn try_with_shards_and_hasher_capped(
shard_count: usize,
hasher: S,
max_shards: usize,
) -> Result<Self, ShardCountError>
pub fn try_with_shards_and_hasher_capped( shard_count: usize, hasher: S, max_shards: usize, ) -> Result<Self, ShardCountError>
Strict constructor with custom hasher and caller-provided cap.
Sourcepub fn shard_count(&self) -> usize
pub fn shard_count(&self) -> usize
Configured shard capacity.
Sourcepub async fn initialized_shards(&self) -> usize
pub async fn initialized_shards(&self) -> usize
Number of initialized shards.
Sourcepub async fn iter(&self) -> Vec<(K, V)>
pub async fn iter(&self) -> Vec<(K, V)>
Snapshot iteration (async).
Steps:
- Snapshot Arc of initialized shards under read lock of the shard vector.
- For each shard: try
try_read; fallback toawaitread. - Clone inner HashMaps (short critical sections).
- If
rayonenabled, parallel flatten of snapshots.
Returns a materialized Vec.
Sourcepub async fn batch_insert<I>(&self, entries: I) -> usizewhere
I: IntoIterator<Item = (K, V)>,
pub async fn batch_insert<I>(&self, entries: I) -> usizewhere
I: IntoIterator<Item = (K, V)>,
Sourcepub async fn batch_remove<I>(&self, keys: I) -> usizewhere
I: IntoIterator<Item = K>,
pub async fn batch_remove<I>(&self, keys: I) -> usizewhere
I: IntoIterator<Item = K>,
Sourcepub async fn compute_if_present<F>(&self, key: &K, f: F) -> Option<V>
pub async fn compute_if_present<F>(&self, key: &K, f: F) -> Option<V>
Sourcepub async fn compute_if_absent<F>(&self, key: K, f: F) -> Vwhere
F: FnOnce() -> V,
pub async fn compute_if_absent<F>(&self, key: K, f: F) -> Vwhere
F: FnOnce() -> V,
Sourcepub async fn retain<F>(&self, predicate: F)
pub async fn retain<F>(&self, predicate: F)
Remove entries where predicate returns false (async).
Locks each shard independently to maximize parallelism.
§Arguments
predicate: function that returns true to keep, false to remove
Sourcepub async fn execute_transaction(
&self,
txn: Transaction<K, V>,
) -> TransactionResult<()>
pub async fn execute_transaction( &self, txn: Transaction<K, V>, ) -> TransactionResult<()>
Sourcepub async fn compare_and_swap(
&self,
key: &K,
expected: &V,
new: V,
) -> CasResult<V>where
V: PartialEq,
pub async fn compare_and_swap(
&self,
key: &K,
expected: &V,
new: V,
) -> CasResult<V>where
V: PartialEq,
Sourcepub async fn cow_snapshot(&self) -> CowSnapshot<K, V>
pub async fn cow_snapshot(&self) -> CowSnapshot<K, V>
Create a copy-on-write snapshot for minimal-locking reads (async).
§Returns
CowSnapshot<K, V>: Immutable snapshot of current state.
Sourcepub async fn versioned_snapshot(&self) -> IsolatedSnapshot<K, V>
pub async fn versioned_snapshot(&self) -> IsolatedSnapshot<K, V>
Create a versioned snapshot for time-travel queries (async).
§Returns
IsolatedSnapshot<K, V>: Snapshot with version information.
Sourcepub async fn snapshot_at_version(
&self,
version: u64,
) -> Option<IsolatedSnapshot<K, V>>
pub async fn snapshot_at_version( &self, version: u64, ) -> Option<IsolatedSnapshot<K, V>>
Sourcepub async fn lock_profiles(&self) -> Vec<LockProfile>
pub async fn lock_profiles(&self) -> Vec<LockProfile>
Get lock profiling data for all shards (async).
§Returns
Vec<LockProfile>: Per-shard lock statistics.
Sourcepub fn enable_profiling(&self, enabled: bool)
pub fn enable_profiling(&self, enabled: bool)
Sourcepub fn with_replication(
shard_count: usize,
replicas: Vec<Arc<dyn Replica<K, V>>>,
quorum_config: QuorumConfig,
) -> Selfwhere
S: Default,
pub fn with_replication(
shard_count: usize,
replicas: Vec<Arc<dyn Replica<K, V>>>,
quorum_config: QuorumConfig,
) -> Selfwhere
S: Default,
Sourcepub async fn insert_replicated(
&self,
key: K,
value: V,
) -> Result<Option<V>, ReplicaError>
pub async fn insert_replicated( &self, key: K, value: V, ) -> Result<Option<V>, ReplicaError>
Sourcepub async fn remove_replicated(
&self,
key: &K,
) -> Result<Option<V>, ReplicaError>
pub async fn remove_replicated( &self, key: &K, ) -> Result<Option<V>, ReplicaError>
Sourcepub async fn shard_stats(&self) -> ShardStats
pub async fn shard_stats(&self) -> ShardStats
Returns statistics about shard distribution and utilization (async).
§Returns
ShardStats: structure containing shard metrics
Sourcepub async fn shard_utilization(&self) -> f64
pub async fn shard_utilization(&self) -> f64
Returns shard utilization as a percentage (0-100, async).
§Returns
f64: percentage of shards that have been initialized
Sourcepub async fn per_shard_load(&self) -> Vec<PerShardLoad>
pub async fn per_shard_load(&self) -> Vec<PerShardLoad>
Returns load statistics for each initialized shard (async).
Sourcepub async fn memory_stats(&self) -> MemoryStats
pub async fn memory_stats(&self) -> MemoryStats
Returns current memory-oriented shard statistics (async).
Sourcepub async fn drain(&self) -> DrainIterator<K, V> ⓘ
pub async fn drain(&self) -> DrainIterator<K, V> ⓘ
Drains all entries from the map and returns them as an iterator (async).
Shard allocations are retained.
Source§impl<K, V> AsyncShardedHashMap<K, V>
impl<K, V> AsyncShardedHashMap<K, V>
Sourcepub async fn async_snapshot_serializable(
&self,
) -> AsyncShardedHashMapSnapshot<K, V>
Available on crate feature serde only.
pub async fn async_snapshot_serializable( &self, ) -> AsyncShardedHashMapSnapshot<K, V>
serde only.Obtain a serializable snapshot wrapper (for serde).
Trait Implementations§
Source§impl<K, V, S> Clone for AsyncShardedHashMap<K, V, S>
impl<K, V, S> Clone for AsyncShardedHashMap<K, V, S>
Source§fn clone(&self) -> AsyncShardedHashMap<K, V, S>
fn clone(&self) -> AsyncShardedHashMap<K, V, S>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto 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> UnsafeUnpin for AsyncShardedHashMap<K, V, S>where
S: UnsafeUnpin,
impl<K, V, S = FxBuildHasher> !UnwindSafe for AsyncShardedHashMap<K, V, S>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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