pub struct MassMap<K, V, R: MassMapReader, H: MassMapHashLoader = MassMapDefaultHashLoader> { /* private fields */ }Expand description
Typed view over a MassMapInner.
This wrapper carries the key/value types at compile time while sharing the underlying storage and hashing configuration with other typed views.
Implementations§
Source§impl<K, V, R: MassMapReader, H: MassMapHashLoader> MassMap<K, V, R, H>
impl<K, V, R: MassMapReader, H: MassMapHashLoader> MassMap<K, V, R, H>
Sourcepub fn load(reader: R) -> Result<Self>
pub fn load(reader: R) -> Result<Self>
Constructs a massmap from a MassMapReader implementation.
The method validates the leading header (magic number, metadata offset and
length) and deserializes MassMapMeta. Any IO or deserialization errors
are forwarded to the caller.
Sourcepub fn bucket_count(&self) -> usize
pub fn bucket_count(&self) -> usize
Returns the number of buckets in the underlying massmap.
This is mainly intended for testing and diagnostics.
Sourcepub fn info(&self) -> MassMapInfo
pub fn info(&self) -> MassMapInfo
Returns information about the map’s structure and contents.
Sourcepub fn get<Q>(&self, k: &Q) -> Result<Option<V>>
pub fn get<Q>(&self, k: &Q) -> Result<Option<V>>
Attempts to deserialize the value associated with k.
Keys are hashed using the stored seed and only the relevant bucket is deserialized, minimizing IO when the entry is missing.
§Errors
Returns an error if the reader fails to provide the bucket or if the
serialized data cannot be deserialized into (K, V) pairs.
Sourcepub fn batch_get<Q>(
&self,
keys: impl IntoIterator<Item = impl Borrow<Q>>,
) -> Result<Vec<Option<V>>>
pub fn batch_get<Q>( &self, keys: impl IntoIterator<Item = impl Borrow<Q>>, ) -> Result<Vec<Option<V>>>
Performs multiple lookups in a single pass.
The reader is asked to fetch each bucket sequentially; implementations
may override MassMapReader::batch_read_at to issue true scatter/gather
reads where available. Results preserve the order of keys.
§Errors
Returns an error under the same conditions as get.
Sourcepub fn iter(&self) -> MassMapIter<'_, K, V, R, H> ⓘ
pub fn iter(&self) -> MassMapIter<'_, K, V, R, H> ⓘ
Creates an iterator that traverses all entries in the map by bucket order.
The iterator reads each bucket sequentially from the backing storage, deserializes all entries in the bucket, and yields them one at a time. Each bucket is fully loaded into memory before any of its entries are yielded. Iteration stops immediately if a bucket fails to deserialize.
§Examples
use massmap::{MassMap, MassMapBuilder};
let entries = [("a", 1), ("b", 2), ("c", 3)];
let file = std::fs::File::create("examples/iter_test.massmap")?;
MassMapBuilder::default().build(&file, entries.iter())?;
let file = std::fs::File::open("examples/iter_test.massmap")?;
let map = MassMap::<String, i32, _>::load(file)?;
let all_entries: Vec<_> = map.iter().collect::<std::io::Result<Vec<_>>>()?;
assert_eq!(all_entries.len(), 3);Sourcepub fn get_bucket(&self, index: usize) -> Result<Vec<(K, V)>>
pub fn get_bucket(&self, index: usize) -> Result<Vec<(K, V)>>
Retrieves all entries in the specified bucket.
This method is primarily intended for testing and debugging.
§Errors
Returns an error if the reader fails to provide the bucket or if the
serialized data cannot be deserialized into (K, V) pairs.