Struct deepmesa_encoding::prefix::unary::UnaryEncoder [−][src]
pub struct UnaryEncoder { /* fields omitted */ }
Expand description
Encodes unsigned values using Unary Encoding.
Each value is encoded as a sequence of 1
bits followed by a
0
bit.
Examples
decimal 2 = 0000_0010
encoding for decimal 2 = 110
decimal 12 = 0000_0101
encoding for decimal 12 = 1111_1111_1111_0
The unary 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::UnaryEncoder; let mut vbe = UnaryEncoder::new(); // encode 2 vbe.encode(2); assert_eq!(vbe.elements(), 1); assert_eq!(vbe.encoded_len(), 3); assert_eq!(vbe.comp_ratio(), 3.0); // Get the underlying BitVector. let encoded = vbe.encoded(); assert_eq!(encoded.read_u8(0), (0b110, 3)); // encode 12 vbe.encode(12); assert_eq!(vbe.elements(), 2); assert_eq!(vbe.encoded_len(), 16); assert_eq!(vbe.comp_ratio(), 8.0); let encoded = vbe.encoded(); assert_eq!(encoded.read_u16(3), (0b1111_1111_1111_0, 13));
Encoded bits can be decoded using the UnaryDecoder
.
Implementations
Creates a new UnaryEncoder
with the underlying BitVector
initialized with
a capacity of 1024 bits. .
Creates a new UnaryEncoder
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 UnaryEncoder
impl Send for UnaryEncoder
impl Sync for UnaryEncoder
impl Unpin for UnaryEncoder
impl UnwindSafe for UnaryEncoder