DedupeEncoder

Struct DedupeEncoder 

Source
pub struct DedupeEncoder { /* private fields */ }
Expand description

Stateful encoder that replaces repeated values with compact IDs.

Implementations§

Source§

impl DedupeEncoder

Source

pub fn new() -> Self

Creates a new empty DedupeEncoder.

Source

pub fn with_capacity(initial_capacity: usize, num_types: usize) -> Self

Creates a new DedupeEncoder with the specified capacity.

The encoder will be able to hold at least capacity unique values and num_types categories of types without reallocating.

Source

pub fn clear(&mut self)

Removes all cached entries and resets assigned IDs.

Source

pub const fn len(&self) -> usize

Returns the number of unique values currently stored in the encoder (seen so far).

Source

pub const fn is_empty(&self) -> bool

Returns true if no values have been seen yet.

Source

pub fn encode<T: Hash + Eq + Pack + Clone + Send + Sync + 'static>( &mut self, val: &T, writer: &mut impl Write, ) -> Result<usize>

Encodes a value with deduplication.

If the value has been seen before, only its ID is encoded. Otherwise, the value is encoded in full, preceded by a special ID (0).

§Arguments
  • val - The value to encode. It must implement Hash, Eq, and Pack.
  • writer - The writer to which the encoded data will be written.
§Returns

The number of bytes written to the writer. Encodes val with deduplication support.

When the value is first seen, this writes a special ID 0 followed by the packed value. On subsequent occurrences, only the assigned ID is written.

Trait Implementations§

Source§

impl Default for DedupeEncoder

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> Same for T

Source§

type Output = T

Should always be Self
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.