pub struct MassMap<K, V, R: MassMapReader> {
pub meta: MassMapMeta,
pub meta_offset: u64,
pub meta_length: u64,
/* private fields */
}Expand description
Immutable hash map backed by a serialized massmap file.
A MassMap is created from a MassMapReader (typically a file) and
provides low-latency lookups without loading the whole dataset into memory.
Keys and values are deserialized on demand using serde and MessagePack.
§Type Parameters
K: key type stored in the map; must implementserde::Deserialize.V: value type stored in the map; must implementserde::DeserializeandClone.R: reader that satisfiesMassMapReader.
Fields§
§meta: MassMapMetaMetadata describing the layout and hashing strategy of the backing file.
meta_offset: u64Absolute offset within the reader at which the serialized metadata begins.
meta_length: u64Length in bytes of the serialized metadata blob.
Implementations§
Source§impl<K, V, R: MassMapReader> MassMap<K, V, R>
impl<K, V, R: MassMapReader> MassMap<K, V, R>
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.
§Errors
Returns an error when the magic number is invalid, the metadata cannot be read in full, or the MessagePack payload fails to deserialize.
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: &[&Q]) -> Result<Vec<Option<V>>>
pub fn batch_get<Q>(&self, keys: &[&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.