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]

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]

[src]

Creates a new LockFreeHashMap.

Examples

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

[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);

[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);

[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);

[src]

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

[src]

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));

[src]

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));

[src]

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`.

[src]

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));

[src]

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

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

[src]

Executes the destructor for this type. Read more

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

[src]

Formats the value using the given formatter. Read more

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> Sync for LockFreeHashMap<'v, K, V, S> where
    K: Send + Sync,
    S: Send + Sync,
    V: Send + Sync