Struct scc::HashIndex [−][src]
A scalable concurrent hash index implementation.
scc::HashIndex is a concurrent hash index data structure that is optimized for read operations.
Implementations
impl<K, V, H> HashIndex<K, V, H> where
K: Clone + Eq + Hash + Sync,
V: Clone + Sync,
H: BuildHasher,
[src]
K: Clone + Eq + Hash + Sync,
V: Clone + Sync,
H: BuildHasher,
pub fn new(capacity: usize, build_hasher: H) -> HashIndex<K, V, H>
[src]
Creates an empty HashIndex instance with the given capacity and build hasher.
The actual capacity is equal to or greater than the given capacity. It is recommended to give a capacity value that is larger than 16 * the number of threads to access the HashMap.
Panics
Panics if memory allocation fails.
Examples
use scc::HashIndex; use std::collections::hash_map::RandomState; let hashindex: HashIndex<u64, u32, RandomState> = HashIndex::new(0, RandomState::new());
pub fn insert(&self, key: K, value: V) -> Result<(), (K, V)>
[src]
Inserts a key-value pair into the HashIndex.
Returns an error with the given key-value pair attached if the key exists.
Panics
Panics if memory allocation fails, or the number of entries in the target cell reaches u32::MAX.
Examples
use scc::HashIndex; let hashindex: HashIndex<u64, u32, _> = Default::default(); let result = hashindex.insert(1, 0); assert!(result.is_ok()); let result = hashindex.insert(1, 1); if let Err((key, value)) = result { assert_eq!(key, 1); assert_eq!(value, 1); } else { assert!(false); }
pub fn remove(&self, key: &K) -> bool
[src]
Removes a key-value pair.
Returns false if the key does not exist.
Examples
use scc::HashIndex; let hashindex: HashIndex<u64, u32, _> = Default::default(); let result = hashindex.insert(1, 0); assert!(result.is_ok()); let result = hashindex.remove(&1); assert!(result);
pub fn read<R, F: FnOnce(&K, &V) -> R>(&self, key: &K, f: F) -> Option<R>
[src]
Reads a key-value pair.
Errors
Returns None if the key does not exist.
Examples
use scc::HashIndex; let hashindex: HashIndex<u64, u32, _> = Default::default(); let result = hashindex.insert(1, 0); assert!(result.is_ok()); let result = hashindex.read(&1, |_, &value| value); if let Some(result) = result { assert_eq!(result, 0); } else { assert!(false); }
pub fn clear(&self)
[src]
Clears all the key-value pairs.
Examples
use scc::HashIndex; let hashindex: HashIndex<u64, u32, _> = Default::default(); let result = hashindex.insert(1, 0); assert!(result.is_ok()); let result = hashindex.len(|capacity| capacity); assert_eq!(result, 1); hashindex.clear(); let result = hashindex.len(|capacity| capacity); assert_eq!(result, 0);
pub fn len<F: FnOnce(usize) -> usize>(&self, f: F) -> usize
[src]
Returns an estimated size of the HashIndex.
The given function determines the sampling size. A function returning a fixed number larger than u16::MAX yields around 99% accuracy.
Examples
use scc::HashIndex; let hashindex: HashIndex<u64, u32, _> = Default::default(); let result = hashindex.insert(1, 0); assert!(result.is_ok()); let result = hashindex.len(|capacity| capacity); assert_eq!(result, 1); let result = hashindex.len(|capacity| capacity / 2); assert!(result == 0 || result == 2);
pub fn capacity(&self) -> usize
[src]
Returns the capacity of the HashIndex.
Examples
use scc::HashIndex; use std::collections::hash_map::RandomState; let hashindex: HashIndex<u64, u32, RandomState> = HashIndex::new(1000000, RandomState::new()); let result = hashindex.capacity(); assert_eq!(result, 1048576);
pub fn hasher(&self) -> &H
[src]
Returns a reference to its build hasher.
Examples
use scc::HashIndex; use std::collections::hash_map::RandomState; let hashindex: HashIndex<u64, u32, _> = Default::default(); let result: &RandomState = hashindex.hasher();
pub fn iter(&self) -> Visitor<'_, K, V, H>
[src]
Returns a Visitor.
It is guaranteed to go through all the key-value pairs pertaining in the HashIndex at the moment, however the same key-value pair can be visited more than once if the HashIndex is being resized.
Examples
use scc::HashIndex; let hashindex: HashIndex<u64, u32, _> = Default::default(); let result = hashindex.insert(1, 0); assert!(result.is_ok()); let mut iter = hashindex.iter(); assert_eq!(iter.next(), Some((&1, &0))); assert_eq!(iter.next(), None); for iter in hashindex.iter() { assert_eq!(iter, (&1, &0)); }
Trait Implementations
impl<K, V> Default for HashIndex<K, V, RandomState> where
K: Clone + Eq + Hash + Sync,
V: Clone + Sync,
[src]
K: Clone + Eq + Hash + Sync,
V: Clone + Sync,
fn default() -> Self
[src]
Creates a HashIndex instance with the default parameters.
The default hash builder is RandomState, and the default capacity is 256.
Panics
Panics if memory allocation fails.
use scc::HashIndex; let hashindex: HashIndex<u64, u32, _> = Default::default();
impl<K, V, H> Drop for HashIndex<K, V, H> where
K: Clone + Eq + Hash + Sync,
V: Clone + Sync,
H: BuildHasher,
[src]
K: Clone + Eq + Hash + Sync,
V: Clone + Sync,
H: BuildHasher,
Auto Trait Implementations
impl<K, V, H> !RefUnwindSafe for HashIndex<K, V, H>
impl<K, V, H> Send for HashIndex<K, V, H> where
H: Send,
K: Send,
V: Send,
H: Send,
K: Send,
V: Send,
impl<K, V, H> Sync for HashIndex<K, V, H> where
H: Sync,
K: Send,
V: Send,
H: Sync,
K: Send,
V: Send,
impl<K, V, H> Unpin for HashIndex<K, V, H> where
H: Unpin,
H: Unpin,
impl<K, V, H> !UnwindSafe for HashIndex<K, V, H>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
[src]
pub const ALIGN: usize
[src]
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
[src]
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
[src]
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
[src]
pub unsafe fn drop(ptr: usize)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,