Elias Gamma/Delta Codes
Elias Gamma & Delta Codes
Implement Elias gamma and delta codes for positive integers using MSB-first bit order.
Functions
func EncodeGamma(n uint64) []byte
func DecodeGamma(data []byte) (uint64, bool)
func EncodeDelta(n uint64) []byte
func DecodeDelta(data []byte) (uint64, bool)
Behavior
- Inputs are positive integers (
n >= 1). - Encoders return a byte slice containing a single codeword padded with trailing zeros to the next byte.
- Decoders read exactly one codeword from
dataand ignore any trailing zero padding. - Return
ok=falseif the codeword is invalid or incomplete.
Definitions
Gamma:
- Let
L = floor(log2 n) + 1. - Write
L-1zeros, then theL-bit binary ofn.
Delta:
- Let
L = floor(log2 n) + 1. - Write
gamma(L), then the lowerL-1bits ofn.
Run tests to see results
No issues detected