ConcurrentElasticMap

Struct ConcurrentElasticMap 

Source
pub struct ConcurrentElasticMap<K, V> { /* private fields */ }
Expand description

A thread-safe hash table with adaptive probing strategy.

This implementation uses atomic operations to ensure thread safety without traditional locks, allowing for high concurrency with minimal contention. The adaptive probing strategy dynamically adjusts step sizes based on occupancy patterns.

Implementations§

Source§

impl<K, V> ConcurrentElasticMap<K, V>
where K: Eq + Hash + Clone, V: Clone,

Source

pub fn new() -> Self

Creates a new ConcurrentElasticMap with the default initial capacity and parameters

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new ConcurrentElasticMap with the specified initial capacity

Source

pub fn get_index<Q: ?Sized + Hash>(&self, key: &Q) -> usize

Computes the index in the buckets array for a given key

§Panics

This function will panic if unable to acquire the read lock on the buckets.

Source

pub fn get<Q>(&self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Retrieve a value for a given key

Source

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

Removes a key-value pair from the hash table

Source

pub fn len(&self) -> usize

Returns the number of elements in the hash table

Source

pub fn is_empty(&self) -> bool

Returns true if the hash table is empty

Source

pub fn set_occupancy_threshold(&self, threshold: usize)

Provide a way to configure the occupancy threshold

Source

pub fn set_load_factor_threshold(&self, threshold: f64)

Provide a way to configure the load factor threshold

Source

pub fn iter(&self) -> Iter<'_, K, V>

Returns an iterator over the key-value pairs

§Panics

This function will panic if unable to acquire the read lock on buckets.

Source

pub fn capacity(&self) -> usize

Returns the capacity (number of buckets) in the map

§Panics

This function will panic if unable to acquire the read lock on buckets.

Source

pub fn load_factor(&self) -> f64

Returns the current load factor of the map

§Panics

This function will panic if unable to acquire the read lock on buckets.

Source

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

Inserts a key-value pair into the map

Returns the old value if the key was already present

§Panics

This function may panic if unable to acquire locks on the buckets.

Trait Implementations§

Source§

impl<K: Debug, V: Debug> Debug for ConcurrentElasticMap<K, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V> Default for ConcurrentElasticMap<K, V>
where K: Eq + Hash + Clone, V: Clone,

Source§

fn default() -> Self

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

impl<K, V> HashMapExtensions<K, V> for ConcurrentElasticMap<K, V>
where K: Eq + Hash + Clone, V: Clone,

Source§

fn keys(&self) -> Vec<K>

Returns the keys of the hash map as a Vec
Source§

fn values(&self) -> Vec<V>

Returns the values of the hash map as a Vec
Source§

fn contains_key<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns true if the hash map contains the given key
Source§

impl<'a, K, V> IntoIterator for &'a ConcurrentElasticMap<K, V>
where K: Clone + Eq + Hash, V: Clone,

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<K, V> !Freeze for ConcurrentElasticMap<K, V>

§

impl<K, V> RefUnwindSafe for ConcurrentElasticMap<K, V>

§

impl<K, V> Send for ConcurrentElasticMap<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for ConcurrentElasticMap<K, V>
where K: Send, V: Send,

§

impl<K, V> Unpin for ConcurrentElasticMap<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for ConcurrentElasticMap<K, V>

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.