MassMapBuilder

Struct MassMapBuilder 

Source
pub struct MassMapBuilder<H: MassMapHashLoader = MassMapDefaultHashLoader> { /* private fields */ }
Expand description

Builder type for emitting massmap files from key-value iterators.

The builder owns configuration such as the hash seed, bucket sizing, IO buffering, field-name emission, and optional bucket size guards. Use build to stream MessagePack-encoded buckets to a MassMapWriter sink (typically a file implementing FileExt).

The loader type parameter H allows swapping in custom MassMapHashLoader implementations. Each builder instance is consumed by a single call to build.

Implementations§

Source§

impl MassMapBuilder

Source

pub fn default() -> Self

Creates a new default massmap builder with default hash loader.

Source§

impl<H: MassMapHashLoader> MassMapBuilder<H>

Source

pub fn with_hash_config(self, config: MassMapHashConfig) -> Self

Replaces the entire hash configuration used to distribute keys across buckets.

This method allows advanced users to specify a custom MassMapHashConfig with arbitrary parameters. For most use cases, with_hash_seed is sufficient to override just the hash seed parameter.

§Parameters
  • config: The hash configuration to use for this builder.
Source

pub fn with_hash_seed(self, seed: u64) -> Self

Overrides the hash seed used to distribute keys across buckets.

Source

pub fn with_bucket_count(self, count: u64) -> Self

Sets the number of buckets to allocate prior to serialization.

A larger bucket count reduces collisions at the cost of additional metadata and potentially sparser files.

Source

pub fn with_writer_buffer_size(self, size: usize) -> Self

Adjusts the capacity of the buffered writer used while streaming data.

Source

pub fn with_field_names(self, value: bool) -> Self

Controls whether serialized MessagePack maps include field names.

Enabling this makes the serialized buckets human readable at the cost of slightly larger files and additional encoding work.

Source

pub fn with_bucket_size_limit(self, limit: u32) -> Self

Sets a hard cap on the number of bytes allowed per bucket payload.

Buckets that exceed this limit cause build to abort with ErrorKind::InvalidData, which can be useful when targeting systems with strict per-request IO ceilings.

Source

pub fn build<W, K, V>( self, writer: &W, entries: impl Iterator<Item = impl Borrow<(K, V)>>, ) -> Result<MassMapInfo>
where W: MassMapWriter, K: Serialize + Clone + Hash + Eq, V: Serialize + Clone,

Consumes the builder and writes a massmap to writer from entries.

The iterator is hashed according to the configured parameters, buckets are serialized via rmp-serde, and a MassMapInfo summary is returned on success. Input ordering does not matter; keys are automatically distributed across buckets.

§Errors

Returns an error if serialization fails, if any bucket exceeds the configured limit, or if the underlying writer reports an IO failure.

§Examples
use massmap::MassMapBuilder;

let data = [("it", 1u32), ("works", 2u32)];
let file = std::fs::File::create("examples/example.massmap")?;
let info = MassMapBuilder::default().build(&file, data.iter())?;
assert_eq!(info.meta.entry_count, 2);

Trait Implementations§

Source§

impl<H: Debug + MassMapHashLoader> Debug for MassMapBuilder<H>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<H: MassMapHashLoader> Default for MassMapBuilder<H>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<H> Freeze for MassMapBuilder<H>

§

impl<H> RefUnwindSafe for MassMapBuilder<H>
where H: RefUnwindSafe,

§

impl<H> Send for MassMapBuilder<H>
where H: Send,

§

impl<H> Sync for MassMapBuilder<H>
where H: Sync,

§

impl<H> Unpin for MassMapBuilder<H>
where H: Unpin,

§

impl<H> UnwindSafe for MassMapBuilder<H>
where H: 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.