pub struct HashIndex { /* private fields */ }Expand description
Hash-based index for fast O(1) exact-match lookups.
This index uses a hash map for constant-time key lookups, making it ideal for:
- Primary key lookups
- Session/token lookups
- Any scenario where you only need exact matches
§Performance
- Insert: O(1) average
- Lookup: O(1) average
- Delete: O(1) average
§Limitations
- Does not support range queries (use BTreeIndex for that)
- Does not maintain order
§Example
use rustlite_core::index::{HashIndex, Index};
let mut index = HashIndex::new();
index.insert(b"session:abc123", 42).unwrap();
index.insert(b"session:def456", 43).unwrap();
// Fast O(1) lookup
assert_eq!(index.find(b"session:abc123").unwrap(), vec![42]);
assert!(index.find(b"nonexistent").unwrap().is_empty());Implementations§
Source§impl HashIndex
impl HashIndex
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new Hash index with the specified capacity.
Sourcepub fn contains_key(&self, key: &[u8]) -> bool
pub fn contains_key(&self, key: &[u8]) -> bool
Check if the index contains a key.
Trait Implementations§
Source§impl Index for HashIndex
impl Index for HashIndex
Source§fn insert(&mut self, key: &[u8], value: u64) -> Result<()>
fn insert(&mut self, key: &[u8], value: u64) -> Result<()>
Insert a key-value pair into the index.
The value is typically a pointer/offset to the actual data.
Source§fn remove(&mut self, key: &[u8]) -> Result<bool>
fn remove(&mut self, key: &[u8]) -> Result<bool>
Remove all entries for a key from the index.
Returns true if any entries were removed.
Source§fn index_type(&self) -> IndexType
fn index_type(&self) -> IndexType
Returns the index type.
Auto Trait Implementations§
impl Freeze for HashIndex
impl RefUnwindSafe for HashIndex
impl Send for HashIndex
impl Sync for HashIndex
impl Unpin for HashIndex
impl UnwindSafe for HashIndex
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