ShardedHashMap

Struct ShardedHashMap 

Source
pub struct ShardedHashMap<K, V, S = FxBuildHasher>
where K: Eq + Hash + Clone + Send + Sync, V: Clone + Send + Sync, S: BuildHasher + Clone + Send + Sync,
{ /* private fields */ }
Expand description

Sharded concurrent HashMap (synchronous).

Cloning the map is cheap (Arc handles + atomic length).

Implementations§

Source§

impl<K, V> ShardedHashMap<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 (FxBuildHasher).

Source§

impl<K, V, S> ShardedHashMap<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 explicit hasher (non-zero shard count fallback).

Source

pub fn shard_count(&self) -> usize

Current configured shard slots.

Source

pub fn initialized_shards(&self) -> usize

Number of shards actually initialized (allocated).

Source

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

Insert key/value. Returns previous value if existed.

Complexity: O(1) expected.

Source

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

Fetch cloned value.

Source

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

Remove key, returning previous value.

Source

pub fn len(&self) -> usize

Length (cached atomic).

Source

pub fn is_empty(&self) -> bool

Whether empty.

Source

pub fn clear(&self)

Clear all data (retains shard allocations).

Source

pub fn iter(&self) -> impl Iterator<Item = (K, V)>

Snapshot iteration over (K,V) clones.

Semantics:

  • Collects a list of initialized shard Arcs first (short critical section).
  • Each shard is read-locked independently; values cloned.
  • Not a live iterator: modifications after a shard snapshot are not reflected.
  • If rayon enabled, internal flattening per-shard happens in parallel for speed.

Cost:

  • O(N) cloning cost for visited entries.
  • Temporary Vec allocations proportional to initialized shard count (and item copies).

Trait Implementations§

Source§

impl<K, V, S> Clone for ShardedHashMap<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) -> ShardedHashMap<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 ShardedHashMap<K, V, S>
where S: Freeze,

§

impl<K, V, S> RefUnwindSafe for ShardedHashMap<K, V, S>
where S: RefUnwindSafe,

§

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

§

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

§

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

§

impl<K, V, S> UnwindSafe for ShardedHashMap<K, V, S>
where S: UnwindSafe,

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.