[−][src]Struct lockfreehashmap::LockFreeHashMap
Fields
inner: AtomicBox<MapInner<'v, K, V, S>>
Points to the newest map (after it's been fully resized). Always non-null.
Methods
impl<'guard, 'v: 'guard, K, V, S> LockFreeHashMap<'v, K, V, S> where
K: 'guard + Hash + Eq,
V: PartialEq,
S: 'guard + BuildHasher + Clone,
[src]
impl<'guard, 'v: 'guard, K, V, S> LockFreeHashMap<'v, K, V, S> where
K: 'guard + Hash + Eq,
V: PartialEq,
S: 'guard + BuildHasher + Clone,
pub const DEFAULT_CAPACITY: usize
[src]
The default size of a new LockFreeHashMap
when created by LockFreeHashMap::new()
.
pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> Self
[src]
pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> Self
Creates an empty LockFreeHashMap
with the specified capacity, using hasher
to hash the
keys.
The hash map will be able to hold at least capacity
elements without
reallocating. If capacity
is 0, the hash map will use the next power of 2 (i.e. 1).
Examples
use lockfreehashmap::LockFreeHashMap; use std::collections::hash_map::RandomState; let s = RandomState::new(); let mut map = LockFreeHashMap::with_capacity_and_hasher(10, s); let guard = lockfreehashmap::pin(); map.insert(1, 2, &guard);
pub(crate) fn load_inner<'s: 'guard>(
&'s self,
guard: &'guard Guard
) -> &'guard MapInner<'v, K, V, S>
[src]
pub(crate) fn load_inner<'s: 'guard>(
&'s self,
guard: &'guard Guard
) -> &'guard MapInner<'v, K, V, S>
Private helper method to load the inner
field as a &[MapInner].
pub fn capacity(&self) -> usize
[src]
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);
pub fn len(&self) -> usize
[src]
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);
pub fn clear(&self)
[src]
pub fn clear(&self)
Clears the entire map.
This has the same effects as if calling LockFreeHashMap::with_capacity()
, but its effects
are visible to all threads. Because of this, new memory is always allocated before the old
map's memory is dropped.
Examples
let map = LockFreeHashMap::<u32, String>::with_capacity(8); let guard = lockfreehashmap::pin(); map.insert(5, String::from("five"), &guard); assert_eq!(map.capacity(), 8); assert_eq!(map.len(), 1); map.clear(); assert_eq!(map.capacity(), 8); assert_eq!(map.len(), 0);
pub fn clear_with_capacity(&self, capacity: usize)
[src]
pub fn clear_with_capacity(&self, capacity: usize)
Clears the entire map.
This has the same effects as if calling LockFreeHashMap::with_capacity()
, but its effects
are visible to all threads. Because of this, new memory is always allocated before the old
map's memory is dropped.
Examples
let map = LockFreeHashMap::<u32, String>::with_capacity(8); let guard = lockfreehashmap::pin(); map.insert(5, String::from("five"), &guard); assert_eq!(map.capacity(), 8); assert_eq!(map.len(), 1); map.clear_with_capacity(15); assert_eq!(map.capacity(), 16); assert_eq!(map.len(), 0);
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
[src]
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
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));
pub fn get<'s: 'guard, Q: ?Sized>(
&'s self,
key: &Q,
guard: &'guard Guard
) -> Option<&'guard V> where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
[src]
pub fn get<'s: 'guard, Q: ?Sized>(
&'s self,
key: &Q,
guard: &'guard Guard
) -> Option<&'guard V> where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
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));
pub fn insert<'s: 'guard>(
&'s self,
key: K,
value: V,
guard: &'guard Guard
) -> Option<&'guard V>
[src]
pub fn insert<'s: 'guard>(
&'s 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`.
pub fn replace<'s: 'guard, Q: ?Sized>(
&'s self,
key: &Q,
value: V,
guard: &'guard Guard
) -> Option<&'guard V> where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
[src]
pub fn replace<'s: 'guard, Q: ?Sized>(
&'s self,
key: &Q,
value: V,
guard: &'guard Guard
) -> Option<&'guard V> where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
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));
pub fn remove<'s: 'guard, Q: ?Sized>(
&'s self,
key: &Q,
guard: &'guard Guard
) -> Option<&'guard V> where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
[src]
pub fn remove<'s: 'guard, Q: ?Sized>(
&'s self,
key: &Q,
guard: &'guard Guard
) -> Option<&'guard V> where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
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));
ⓘImportant traits for Keys<'guard, 'v, K, V, S>pub fn keys(&self, guard: &'guard Guard) -> Keys<'guard, 'v, K, V, S>
[src]
pub fn keys(&self, guard: &'guard Guard) -> Keys<'guard, 'v, K, V, S>
Returns an iterator over the keys in the map at one point in time. Any keys inserted or removed after this point in time may or may not be returned by this iterator.
Examples
let map = LockFreeHashMap::<i32, String>::new(); let guard = lockfreehashmap::pin(); map.insert(4, "Four".to_string(), &guard); map.insert(8, "Eight".to_string(), &guard); map.insert(15, "Fifteen".to_string(), &guard); map.insert(16, "Sixteen".to_string(), &guard); map.insert(23, "TwentyThree".to_string(), &guard); map.insert(42, "FortyTwo".to_string(), &guard); let mut keys = map.keys(&guard).cloned().collect::<Vec<_>>(); keys.sort(); assert_eq!(vec![4, 8, 15, 16, 23, 42], keys); map.remove(&16, &guard); let mut keys = map.keys(&guard).cloned().collect::<Vec<_>>(); keys.sort(); assert_eq!(vec![4, 8, 15, 23, 42], keys);
impl<'guard, 'v: 'guard, K: Hash + Eq + 'guard, V: PartialEq> LockFreeHashMap<'v, K, V>
[src]
impl<'guard, 'v: 'guard, K: Hash + Eq + 'guard, V: PartialEq> LockFreeHashMap<'v, K, V>
pub fn new() -> Self
[src]
pub fn new() -> Self
pub fn with_capacity(size: usize) -> Self
[src]
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);
Trait Implementations
impl<'v, K, V, S> Drop for LockFreeHashMap<'v, K, V, S>
[src]
impl<'v, K, V, S> Drop for LockFreeHashMap<'v, K, V, S>
impl<'guard, 'v: 'guard, K: Hash + Eq + Debug, V: Debug + PartialEq> Debug for LockFreeHashMap<'v, K, V>
[src]
impl<'guard, 'v: 'guard, K: Hash + Eq + Debug, V: Debug + PartialEq> Debug for LockFreeHashMap<'v, K, V>
Auto Trait Implementations
impl<'v, K, V, S> Send for LockFreeHashMap<'v, K, V, S> where
K: Send + Sync,
S: Send + Sync,
V: Send + Sync,
impl<'v, K, V, S> Send for LockFreeHashMap<'v, K, V, S> where
K: Send + Sync,
S: Send + Sync,
V: Send + Sync,
impl<'v, K, V, S> Sync for LockFreeHashMap<'v, K, V, S> where
K: Send + Sync,
S: Send + Sync,
V: Send + Sync,
impl<'v, K, V, S> Sync for LockFreeHashMap<'v, K, V, S> where
K: Send + Sync,
S: Send + Sync,
V: Send + Sync,
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more