Struct lockfreehashmap::LockFreeHashMap
[−]
[src]
pub struct LockFreeHashMap<'v, K, V: 'v, S = RandomState> { /* fields omitted */ }
Methods
impl<'v, K, V, S> LockFreeHashMap<'v, K, V, S>
[src]
pub const DEFAULT_CAPACITY: usize
DEFAULT_CAPACITY: usize = 8
The default size of a new LockFreeHashMap
when created by LockFreeHashMap::new()
.
impl<'guard, 'v: 'guard, K: Hash + Eq + 'guard, V: PartialEq> LockFreeHashMap<'v, K, V>
[src]
pub fn new() -> Self
[src]
pub fn with_capacity(size: usize) -> Self
[src]
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);
pub fn capacity(&self) -> usize
[src]
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]
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]
Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
[src]
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<Q: ?Sized>(&self, key: &Q, guard: &'guard Guard) -> Option<&'guard V> where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
[src]
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(
&self,
key: K,
value: V,
guard: &'guard Guard
) -> Option<&'guard V>
[src]
&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<Q: ?Sized>(
&self,
key: &Q,
value: V,
guard: &'guard Guard
) -> Option<&'guard V> where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
[src]
&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<Q: ?Sized>(
&self,
key: &Q,
guard: &'guard Guard
) -> Option<&'guard V> where
K: Borrow<Q>,
Q: Hash + Eq + PartialEq<K>,
[src]
&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));