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<H: MassMapHashLoader> MassMapBuilder<H>
impl<H: MassMapHashLoader> MassMapBuilder<H>
Sourcepub fn with_hash_config(self, config: MassMapHashConfig) -> Self
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.
Sourcepub fn with_hash_seed(self, seed: u64) -> Self
pub fn with_hash_seed(self, seed: u64) -> Self
Overrides the hash seed used to distribute keys across buckets.
Sourcepub fn with_bucket_count(self, count: u64) -> Self
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.
Sourcepub fn with_writer_buffer_size(self, size: usize) -> Self
pub fn with_writer_buffer_size(self, size: usize) -> Self
Adjusts the capacity of the buffered writer used while streaming data.
Sourcepub fn with_field_names(self, value: bool) -> Self
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.
Sourcepub fn with_bucket_size_limit(self, limit: u32) -> Self
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.
Sourcepub fn build<W, K, V>(
self,
writer: &W,
entries: impl Iterator<Item = impl Borrow<(K, V)>>,
) -> Result<MassMapInfo>
pub fn build<W, K, V>( self, writer: &W, entries: impl Iterator<Item = impl Borrow<(K, V)>>, ) -> Result<MassMapInfo>
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);