pub struct MassMapBuilder { /* private fields */ }Expand description
Builder type for emitting massmap files from key-value iterators.
The builder owns configuration such as hash seed, bucket sizing and IO
buffering. Use build to stream MessagePack-encoded buckets to
a MassMapWriter sink (typically a file implementing FileExt).
Cloning is not required; each builder instance is consumed by a single call
to build.
Implementations§
Source§impl MassMapBuilder
impl MassMapBuilder
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 output human readable at the cost of slightly larger files.
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.
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.
§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.entry_count, 2);