Skip to main content

HopscotchMap

Struct HopscotchMap 

Source
pub struct HopscotchMap<K: 'static, V: 'static, S = FixedState> { /* private fields */ }
Expand description

A concurrent, lock-free hash map based on Hopscotch Hashing.

Implementations§

Source§

impl<K, V> HopscotchMap<K, V, FixedState>
where K: Hash + Eq + Clone + 'static, V: Clone + 'static,

Source

pub fn new() -> Self

Creates a new HopscotchMap with default capacity and hasher.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new HopscotchMap with the specified capacity and default hasher.

Source§

impl<K, V, S> HopscotchMap<K, V, S>
where K: Hash + Eq + Clone + 'static, V: Clone + 'static, S: BuildHasher,

Source

pub fn with_hasher(hasher: S) -> Self

Creates a new HopscotchMap with the specified hasher and default capacity.

Source

pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> Self

Creates a new HopscotchMap with the specified capacity and hasher.

Source

pub fn len(&self) -> usize

Returns the number of elements in the map.

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Source

pub fn capacity(&self) -> usize

Returns the current capacity of the map.

Source

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

Returns the value corresponding to the key.

Source

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

Inserts a key-value pair into the map.

Source

pub fn get_or_insert(&self, key: K, value: V) -> V

Returns the value corresponding to the key, or inserts the given value if the key is not present.

When multiple threads call this concurrently for the same key (without concurrent removes), all callers receive the same value.

Source

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

Insert a key-value pair only if the key does not exist. Returns None if inserted, Some(existing_value) if the key already exists.

Source

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

Remove all nodes matching key, returning the most recent value if the key was present.

remove unlinks only the first matching entry. Insert/remove races can transiently leave more than one entry for the same key (“versions”); after a plain remove() an older version would become visible again. This method keeps removing until a full scan finds no match, so the key is guaranteed absent at the linearization point of the final scan.

Use remove() for single-version removal semantics and force_remove() when the key must be fully evicted.

Note: a concurrent insert of the same key can land after the final scan, as with any removal under contention.

Source

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

Removes a key from the map, returning the value at the key if the key was previously in the map.

Source

pub fn clear(&self)

Clears the map, removing all key-value pairs.

Source

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

Returns an iterator over the map entries.

Source

pub fn keys(&self) -> HopscotchKeys<'_, K, V, S>

Returns an iterator over the map keys.

Source

pub fn values(&self) -> HopscotchValues<'_, K, V, S>

Returns an iterator over the map values (clones V).

Source

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

Returns true if the key is present.

Source

pub fn extend<I: IntoIterator<Item = (K, V)>>(&self, iter: I)

Insert all (K, V) pairs from iter. Takes &self (concurrent map).

Source

pub fn hasher(&self) -> &S

Get the underlying hasher.

Trait Implementations§

Source§

impl<K, V> Default for HopscotchMap<K, V, FixedState>
where K: Hash + Eq + Clone + 'static, V: Clone + 'static,

Available on crate feature std only.
Source§

fn default() -> Self

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

impl<K, V, S> Drop for HopscotchMap<K, V, S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<K, V, S> FromIterator<(K, V)> for HopscotchMap<K, V, S>
where K: Hash + Eq + Clone + Send + 'static, V: Clone + Send + 'static, S: BuildHasher + Default,

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<K, V, S> IntoIterator for HopscotchMap<K, V, S>
where K: 'static, V: 'static,

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = HopscotchIntoIter<K, V>

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

fn into_iter(self) -> HopscotchIntoIter<K, V>

Creates an iterator from a value. Read more
Source§

impl<'a, K, V, S> IntoIterator for &'a HopscotchMap<K, V, S>
where K: Hash + Eq + Clone + 'static, V: Clone + 'static, S: BuildHasher,

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = HopscotchIter<'a, K, V, S>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K: Send, V: Send, S: Send> Send for HopscotchMap<K, V, S>

Source§

impl<K: Send + Sync, V: Send + Sync, S: Send + Sync> Sync for HopscotchMap<K, V, S>

Auto Trait Implementations§

§

impl<K, V, S = FixedState> !Freeze for HopscotchMap<K, V, S>

§

impl<K, V, S = FixedState> !RefUnwindSafe for HopscotchMap<K, V, S>

§

impl<K, V, S = FixedState> !UnwindSafe for HopscotchMap<K, V, S>

§

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

§

impl<K, V, S> UnsafeUnpin for HopscotchMap<K, V, S>
where S: UnsafeUnpin,

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.