MassMap

Struct MassMap 

Source
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 implement serde::Deserialize.
  • V: value type stored in the map; must implement serde::Deserialize and Clone.
  • R: reader that satisfies MassMapReader.

Fields§

§meta: MassMapMeta

Metadata describing the layout and hashing strategy of the backing file.

§meta_offset: u64

Absolute offset within the reader at which the serialized metadata begins.

§meta_length: u64

Length in bytes of the serialized metadata blob.

Implementations§

Source§

impl<K, V, R: MassMapReader> MassMap<K, V, R>
where K: for<'de> Deserialize<'de> + Eq + Hash, V: for<'de> Deserialize<'de> + Clone,

Source

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.

Source

pub fn length(&self) -> u64

Returns the number of entries written into this map.

Source

pub fn get<Q>(&self, k: &Q) -> Result<Option<V>>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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.

Source

pub fn batch_get<Q>(&self, keys: &[&Q]) -> Result<Vec<Option<V>>>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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.

Trait Implementations§

Source§

impl<K: Debug, V: Debug, R: Debug + MassMapReader> Debug for MassMap<K, V, R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V, R> Freeze for MassMap<K, V, R>
where R: Freeze,

§

impl<K, V, R> RefUnwindSafe for MassMap<K, V, R>

§

impl<K, V, R> Send for MassMap<K, V, R>
where R: Send, K: Send, V: Send,

§

impl<K, V, R> Sync for MassMap<K, V, R>
where R: Sync, K: Sync, V: Sync,

§

impl<K, V, R> Unpin for MassMap<K, V, R>
where R: Unpin, K: Unpin, V: Unpin,

§

impl<K, V, R> UnwindSafe for MassMap<K, V, R>
where R: UnwindSafe, K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.