pub struct DedupeEncoder { /* private fields */ }Expand description
Stateful encoder that replaces repeated values with compact IDs.
Implementations§
Source§impl DedupeEncoder
impl DedupeEncoder
Sourcepub fn with_capacity(initial_capacity: usize, num_types: usize) -> Self
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.
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of unique values currently stored in the encoder (seen so far).
Sourcepub fn encode<T: Hash + Eq + Pack + Clone + Send + Sync + 'static>(
&mut self,
val: &T,
writer: &mut impl Write,
) -> Result<usize>
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 implementHash,Eq, andPack.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§
Auto Trait Implementations§
impl Freeze for DedupeEncoder
impl !RefUnwindSafe for DedupeEncoder
impl Send for DedupeEncoder
impl Sync for DedupeEncoder
impl Unpin for DedupeEncoder
impl !UnwindSafe for DedupeEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more