Struct deepmesa_encoding::prefix::gamma::GammaEncoder [−][src]
pub struct GammaEncoder { /* fields omitted */ }
Expand description
Encodes unsigned values using Gamma Encoding.
Each value is encoded in two parts - a length and an
offset. The length is encoded in unary and the offset is the
binary representation with the leading 1
removed.
Examples
decimal 2 = 0000_0010
encoding for decimal 2 = 10_0
decimal 13 = 0000_1101
encoding for decimal 13 = 1110_101
The gamma 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::GammaEncoder; let mut ge = GammaEncoder::new(); // encode 2 ge.encode(2); assert_eq!(ge.elements(), 1); assert_eq!(ge.encoded_len(), 3); assert_eq!(ge.comp_ratio(), 3.0); // Get the underlying BitVector. let encoded = ge.encoded(); assert_eq!(encoded.read_u8(0), (0b100, 3)); // encode 13 ge.encode(13); assert_eq!(ge.elements(), 2); assert_eq!(ge.encoded_len(), 10); assert_eq!(ge.comp_ratio(), 5.0); let encoded = ge.encoded(); assert_eq!(encoded.read_u16(3), (0b1110_101, 7));
Encoded bits can be decoded using the GammaDecoder
.
Implementations
Creates a new GammaEncoder
with the underlying BitVector
initialized with
a capacity of 1024 bits. .
Creates a new GammaEncoder
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 GammaEncoder
impl Send for GammaEncoder
impl Sync for GammaEncoder
impl Unpin for GammaEncoder
impl UnwindSafe for GammaEncoder