Struct LockFreeHashMap

Source
pub struct LockFreeHashMap<'v, K, V: 'v, S = RandomState> { /* private fields */ }

Implementations§

Source§

impl<'v, K, V, S> LockFreeHashMap<'v, K, V, S>

Source

pub const DEFAULT_CAPACITY: usize = 8usize

The default size of a new LockFreeHashMap when created by LockFreeHashMap::new().

Source§

impl<'guard, 'v: 'guard, K: Hash + Eq + 'guard, V: PartialEq> LockFreeHashMap<'v, K, V>

Source

pub fn new() -> Self

Creates a new LockFreeHashMap.

§Examples
let map = LockFreeHashMap::<u32, String>::new();
Source

pub fn with_capacity(size: usize) -> Self

Creates a new LockFreeHashMap of a given size. Uses the next power of two if size is not a power of two.

§Examples
let map = LockFreeHashMap::<u32, String>::with_capacity(12);
assert_eq!(map.capacity(), 12usize.next_power_of_two());
assert_eq!(map.capacity(), 16);
Source

pub fn capacity(&self) -> usize

Returns the number of elements the map can hold without reallocating.

§Examples
let map = LockFreeHashMap::<u32, String>::with_capacity(8);
assert_eq!(map.capacity(), 8);
Source

pub fn len(&self) -> usize

Returns the number of elements in the map.

§Examples
let map = LockFreeHashMap::<u32, String>::with_capacity(8);
assert_eq!(map.capacity(), 8);
assert_eq!(map.len(), 0);
let guard = lockfreehashmap::pin();
map.insert(5, String::from("five"), &guard);
assert_eq!(map.capacity(), 8);
assert_eq!(map.len(), 1);
Source

pub fn clear(&self)

Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.

Source

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

Returns true if the map contains a value for the specified key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

§Examples
let map = LockFreeHashMap::<i32, i32>::new();
assert!(!map.contains_key(&3));
let guard = lockfreehashmap::pin();
map.insert(3, 8934, &guard);
assert!(map.contains_key(&3));
map.remove(&3, &guard);
assert!(!map.contains_key(&3));
Source

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

Returns a reference to the value corresponding to the key. The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

§Examples
let map = LockFreeHashMap::<i32, i32>::new();
let guard = lockfreehashmap::pin();
assert_eq!(map.get(&1, &guard), None);
map.insert(1, 15, &guard);
assert_eq!(map.get(&1, &guard), Some(&15));
Source

pub fn insert( &self, key: K, value: V, guard: &'guard Guard, ) -> Option<&'guard 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. The key is not updated, though; this matters for types that can be == without being identical.

§Examples
let map = LockFreeHashMap::<String, String>::new();
let guard = lockfreehashmap::pin();
let key = "key".to_string();
let equal_key = "key".to_string();
assert_eq!(key, equal_key); // The keys are equal
assert_ne!(&key as *const _, &equal_key as *const _); // But not identical
assert_eq!(map.insert(key, "value".to_string(), &guard), None);
assert_eq!(map.insert(equal_key, "other".to_string(), &guard), Some(&"value".to_string()));
// `map` now contains `key` as its key, rather than `equal_key`.
Source

pub fn replace<Q>( &self, key: &Q, value: V, guard: &'guard Guard, ) -> Option<&'guard V>
where K: Borrow<Q>, Q: Hash + Eq + PartialEq<K> + ?Sized,

Inserts a key-value pair into the map, but only if there is already an existing value that corresponds to the key in 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. The key is not updated, though; this matters for types that can be == without being identical.

§Examples
let map = LockFreeHashMap::<i32, i32>::new();
let guard = lockfreehashmap::pin();
assert_eq!(map.replace(&1, 1, &guard), None);
assert_eq!(map.replace(&1, 1, &guard), None);
assert_eq!(map.insert(1, 1, &guard), None);
assert_eq!(map.replace(&1, 3, &guard), Some(&1));
Source

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

Removes a key from the map, returning the value at the key if the key was previously in the map. The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

§Examples
let map = LockFreeHashMap::<i32, i32>::new();
let guard = lockfreehashmap::pin();
assert_eq!(map.remove(&1, &guard), None);
map.insert(1, 1, &guard);
assert_eq!(map.remove(&1, &guard), Some(&1));

Trait Implementations§

Source§

impl<'guard, 'v: 'guard, K: Hash + Eq + Debug, V: Debug + PartialEq> Debug for LockFreeHashMap<'v, K, V>

Source§

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

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

impl<'v, K, V, S> Drop for LockFreeHashMap<'v, K, V, S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'v, K, V, S = RandomState> !Freeze for LockFreeHashMap<'v, K, V, S>

§

impl<'v, K, V, S> RefUnwindSafe for LockFreeHashMap<'v, K, V, S>

§

impl<'v, K, V, S> Send for LockFreeHashMap<'v, K, V, S>
where S: Send + Sync, K: Send + Sync, V: Send + Sync,

§

impl<'v, K, V, S> Sync for LockFreeHashMap<'v, K, V, S>
where S: Send + Sync, K: Send + Sync, V: Send + Sync,

§

impl<'v, K, V, S> Unpin for LockFreeHashMap<'v, K, V, S>

§

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