Skip to main content

RcuRawHashMap

Struct RcuRawHashMap 

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

A hash map that uses read-copy-update (RCU) to manage concurrent accesses.

By default, this map uses rapidhash::RapidBuildHasher, which provides high performance. However, if this map holds keys which may be attacker-controlled, consider using std::collections::hash_map::RandomState instead.

Implementations§

Source§

impl<K, V> RcuRawHashMap<K, V, RapidBuildHasher>
where K: Eq + Hash + Clone + Send + Sync + 'static, V: Clone + Send + Sync + 'static,

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new hash map with the given capacity.

Source§

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

Source

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

Creates a new hash map with the given capacity and hasher.

Source

pub fn with_hasher(hash_builder: S) -> Self

Creates a new hash map with the given hasher.

Source

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

Returns a reference to the value corresponding to the key.

Another thread running concurrently might see a different value for the object.

Source

pub fn len(&self) -> usize

Returns the number of entries in the map.

The length can change concurrently with this call.

Source

pub unsafe fn insert( &self, scope: &RcuReadScope, key: K, value: V, ) -> InsertionResult<V>

Inserts a key-value pair into the map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated, and the old value is returned.

Concurrent readers might not see the inserted value until the RCU state machine has made sufficient progress to ensure that no concurrent readers are holding read guards.

§Safety

Requires external synchronization to exclude concurrent writers.

Source

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

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

Concurrent readers might see the removed value until the RCU state machine has made sufficient progress to ensure that no concurrent readers are holding read guards.

§Safety

Requires external synchronization to exclude concurrent writers.

Source

pub fn cursor<'a>( &'a self, scope: &'a RcuReadScope, ) -> RcuRawHashMapCursor<'a, K, V, S>

Returns a cursor that can be used to traverse and modify the map.

The cursor iterates through the map in insertion order.

Source

pub fn keys<'a>( &'a self, scope: &'a RcuReadScope, ) -> impl Iterator<Item = &'a K>

Returns an iterator over the keys in the map.

Trait Implementations§

Source§

impl<K, V, S> Debug for RcuRawHashMap<K, V, S>
where K: Eq + Hash + Clone + Send + Sync + 'static + Debug, V: Clone + Send + Sync + 'static + Debug, S: BuildHasher + Send + Sync + 'static,

Source§

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

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

impl<K, V> Default for RcuRawHashMap<K, V, RapidBuildHasher>
where K: Eq + Hash + Clone + Send + Sync + 'static, V: Clone + Send + Sync + 'static,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<K, V, S = BuildHasherDefault<RapidHasher>> !Freeze for RcuRawHashMap<K, V, S>

§

impl<K, V, S> RefUnwindSafe for RcuRawHashMap<K, V, S>

§

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

§

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

§

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

§

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

§

impl<K, V, S> UnwindSafe for RcuRawHashMap<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> 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.