Struct deepmesa_encoding::prefix::golomb::GolombEncoder [−][src]
pub struct GolombEncoder { /* fields omitted */ }
Expand description
Encodes unsigned values using Golomb Encoding.
Each value is encoded in two parts using a tunable parameter - a quotient in unary a remainder in truncated binary.
The golomb 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::GolombEncoder; let param = 6; let mut ge = GolombEncoder::new(param); // encode 9 ge.encode(9); assert_eq!(ge.elements(), 1); assert_eq!(ge.encoded_len(), 5); assert_eq!(ge.comp_ratio(), 5.0); // Get the underlying BitVector. let encoded = ge.encoded(); assert_eq!(encoded.read_u8(0), (0b10100, 5));
Encoded bits can be decoded using the GolombDecoder
.
Implementations
Creates a new GolombDecoder
with a tunable parameter
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 GolombEncoder
impl Send for GolombEncoder
impl Sync for GolombEncoder
impl Unpin for GolombEncoder
impl UnwindSafe for GolombEncoder