bits-0.4: Various bit twiddling and bitwise serialization primitives

LicenseBSD3
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell98

Data.Bits.Coded

Description

 

Synopsis

Documentation

class Coded c where Source

Unaligned codes

Minimal complete definition

encode, decode

Methods

encode :: MonadPut m => c -> Coding m () Source

encodeMany :: (MonadPut m, Foldable t) => t c -> Coding m () Source

decode :: MonadGet m => Coding m c Source

Instances

Integral n => Coded (Unary n) 
(Coded c, Integral c, Ranked n) => Coded (Elias c n) 

newtype Unary n Source

Unary-coded integers

>>> runPutL . runEncode $ encode (Unary 1) >> flush
"\128"
>>> runPutL . runEncode $ encode (Unary 7) >> flush
"\254"

Constructors

Unary 

Fields

unUnary :: n
 

Instances

Enum n => Enum (Unary n) 
Eq n => Eq (Unary n) 
Integral n => Integral (Unary n) 
Num n => Num (Unary n) 
Ord n => Ord (Unary n) 
Read n => Read (Unary n) 
Real n => Real (Unary n) 
Show n => Show (Unary n) 
Integral n => Coded (Unary n) 

newtype Elias c n Source

Representation for Elias Gamma and Delta codes. A positive integer n is encoded by encoding the position of its most significant bit, and then the binary representation of the rest of the number.

Constructors

Elias 

Fields

unElias :: n
 

Instances

Enum n => Enum (Elias c n) 
Eq n => Eq (Elias c n) 
Integral n => Integral (Elias c n) 
Num n => Num (Elias c n) 
Ord n => Ord (Elias c n) 
Read n => Read (Elias c n) 
Real n => Real (Elias c n) 
Show n => Show (Elias c n) 
(Coded c, Integral c, Ranked n) => Coded (Elias c n) 

type Gamma c = Elias (Unary c) Source

Elias Gamma codes the position of the most significant in Unary.

type Delta c n = Elias (Gamma c n) n Source

Elias Delta codes the position of the most significant bit in Elias Gamma.

runEncode :: MonadPut m => Coding m () -> m () Source

runDecode :: MonadGet m => Coding m a -> m a Source