variety-0.1.0.2: integer arithmetic codes
Safe HaskellSafe-Inferred
LanguageHaskell2010

Codec.Arithmetic.Variety.Bounded

Description

Since the arithmetic operations of composition might get computationally expensive on very large codes, a similar interface is provided here which produces and consumes bits in chunks whenever spaces are about to grow beyond a certain size given in bytes, at the cost of at most one bit per chunk.

While the Haskell language standard defines Integer as having no upper bound, GHC most commonly uses the GNU Multiple Precision Arithmetic Library (GMP) as a backend for it, which incurs a limit of 16GiB (or a little over 17GB) on the size of Integer values.

Synopsis

Documentation

encode :: Int -> [(Integer, Integer)] -> BitVec Source #

Given a max precision in bytes, encode a series of value-base pairs into a single bit vector. Bases must be at least equal to 1 and the associated values must exist in the range [0..base-1].

codeLen :: Int -> [Integer] -> Int Source #

Return the length of the code of a sequence of values in the given precision and list of bases in bits.

decode :: Int -> [Integer] -> BitVec -> [Integer] Source #

Try to decode a sequence of values at the head of a bit vector given the same precision and list of bases that was used to encode it. If successful, returns the decoded values and the remainder of the BitVec, with the sequence's code removed. Throws an error if the given vector's size doesn't match the given bases.