MassMap

Struct MassMap 

Source
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>
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.

Source

pub fn len(&self) -> u64

Returns the number of entries written into this map.

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no entries.

Source

pub fn bucket_count(&self) -> usize

Returns the number of buckets in the underlying massmap.

This is mainly intended for testing and diagnostics.

Source

pub fn info(&self) -> MassMapInfo

Returns information about the map’s structure and contents.

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: impl IntoIterator<Item = impl Borrow<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.

Source

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);
Source

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.

Auto Trait Implementations§

§

impl<K, V, R, H> Freeze for MassMap<K, V, R, H>

§

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

§

impl<K, V, R, H> Send for MassMap<K, V, R, H>
where <H as MassMapHashLoader>::BuildHasher: Send, R: Send, K: Send, V: Send,

§

impl<K, V, R, H> Sync for MassMap<K, V, R, H>
where <H as MassMapHashLoader>::BuildHasher: Sync, R: Sync, K: Sync, V: Sync,

§

impl<K, V, R, H> Unpin for MassMap<K, V, R, H>
where <H as MassMapHashLoader>::BuildHasher: Unpin, R: Unpin, K: Unpin, V: Unpin,

§

impl<K, V, R, H> UnwindSafe for MassMap<K, V, R, H>

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.