Struct deepmesa_encoding::prefix::delta::DeltaEncoder [−][src]
pub struct DeltaEncoder { /* fields omitted */ }
Expand description
Encodes unsigned values using Delta Encoding.
Each value is encoded in two parts - a length and an
offset. The length is encoded in Gamma and the offset is the
binary representation with the leading 1
removed.
Examples
decimal 2 = 0000_0010
encoding for decimal 2 = 100_0
decimal 13 = 0000_1101
encoding for decimal 13 = 10_1_101
The delta encoder, encodes the data in a BitVector
. The
.encode()
accepts a u128
value and
pushes encoded bits to the BitVector
.
The encoder maintains a count of number of values encoded
(.elements()
), the number of bits used
to encode those elements
(.encoded_len()
) and the compression
ratio (.comp_ratio()
). The compression
ratio is the average number of bits per value needed to encode
all the values.
Examples
use deepmesa::encoding::DeltaEncoder; let mut de = DeltaEncoder::new(); // encode 2 de.encode(2); assert_eq!(de.elements(), 1); assert_eq!(de.encoded_len(), 2); assert_eq!(de.comp_ratio(), 2.0); // Get the underlying BitVector. let encoded = de.encoded(); assert_eq!(encoded.read_u8(0), (0b00, 2)); // encode 13 de.encode(13); assert_eq!(de.elements(), 2); assert_eq!(de.encoded_len(), 8); assert_eq!(de.comp_ratio(), 4.0); let encoded = de.encoded(); assert_eq!(encoded.read_u16(2), (0b101_101, 6));
Encoded bits can be decoded using the DeltaDecoder
.
Implementations
Creates a new DeltaEncoder
with the underlying BitVector
initialized with
a capacity of 1024 bits. .
Creates a new DeltaEncoder
with the underlying BitVector
initialized with
the specified capacity_bits
;
Returns an immutable reference to the underlying
BitVector
containing the encoded bits.
Returns the length in bits of the underlying
BitVector
containing the encoded bits.
Returns the number of elements encoded in the
underlying BitVector
.
Returns the compression ratio of the encoded
elements. This is simply the
.encoded_len()
divided by
the number of .elements()
;
Auto Trait Implementations
impl RefUnwindSafe for DeltaEncoder
impl Send for DeltaEncoder
impl Sync for DeltaEncoder
impl Unpin for DeltaEncoder
impl UnwindSafe for DeltaEncoder