pub struct HashIndex<K: Hash + Eq, V: Copy> { /* private fields */ }Expand description
A thread-safe hash index for O(1) key lookups.
Backed by FxHashMap with an RwLock - multiple readers, single writer. Best for exact-match queries on unique keys.
§Example
use grafeo_core::index::HashIndex;
use grafeo_common::types::NodeId;
let index: HashIndex<String, NodeId> = HashIndex::new();
index.insert("alice".to_string(), NodeId::new(1));
index.insert("bob".to_string(), NodeId::new(2));
assert_eq!(index.get(&"alice".to_string()), Some(NodeId::new(1)));Implementations§
Source§impl<K: Hash + Eq, V: Copy> HashIndex<K, V>
impl<K: Hash + Eq, V: Copy> HashIndex<K, V>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new hash index with the given capacity.
Sourcepub fn insert(&self, key: K, value: V) -> Option<V>
pub fn insert(&self, key: K, value: V) -> Option<V>
Inserts a key-value pair into the index.
Returns the previous value if the key was already present.
Trait Implementations§
Auto Trait Implementations§
impl<K, V> !Freeze for HashIndex<K, V>
impl<K, V> !RefUnwindSafe for HashIndex<K, V>
impl<K, V> Send for HashIndex<K, V>
impl<K, V> Sync for HashIndex<K, V>
impl<K, V> Unpin for HashIndex<K, V>
impl<K, V> UnwindSafe for HashIndex<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more