MassMapBuilder

Struct MassMapBuilder 

Source
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

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 output human readable at the cost of slightly larger files.

Source

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

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

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.

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

Trait Implementations§

Source§

impl Default for MassMapBuilder

Source§

fn default() -> Self

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

Auto Trait Implementations§

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.