bits-0.5.1: 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) Source # 

Methods

encode :: MonadPut m => Unary n -> Coding m () Source #

encodeMany :: (MonadPut m, Foldable t) => t (Unary n) -> Coding m () Source #

decode :: MonadGet m => Coding m (Unary n) Source #

(Coded c, Integral c, Ranked n) => Coded (Elias c n) Source # 

Methods

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

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

decode :: MonadGet m => Coding m (Elias c n) Source #

newtype Unary n Source #

Unary-coded integers

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

Constructors

Unary 

Fields

Instances

Enum n => Enum (Unary n) Source # 

Methods

succ :: Unary n -> Unary n #

pred :: Unary n -> Unary n #

toEnum :: Int -> Unary n #

fromEnum :: Unary n -> Int #

enumFrom :: Unary n -> [Unary n] #

enumFromThen :: Unary n -> Unary n -> [Unary n] #

enumFromTo :: Unary n -> Unary n -> [Unary n] #

enumFromThenTo :: Unary n -> Unary n -> Unary n -> [Unary n] #

Eq n => Eq (Unary n) Source # 

Methods

(==) :: Unary n -> Unary n -> Bool #

(/=) :: Unary n -> Unary n -> Bool #

Integral n => Integral (Unary n) Source # 

Methods

quot :: Unary n -> Unary n -> Unary n #

rem :: Unary n -> Unary n -> Unary n #

div :: Unary n -> Unary n -> Unary n #

mod :: Unary n -> Unary n -> Unary n #

quotRem :: Unary n -> Unary n -> (Unary n, Unary n) #

divMod :: Unary n -> Unary n -> (Unary n, Unary n) #

toInteger :: Unary n -> Integer #

Num n => Num (Unary n) Source # 

Methods

(+) :: Unary n -> Unary n -> Unary n #

(-) :: Unary n -> Unary n -> Unary n #

(*) :: Unary n -> Unary n -> Unary n #

negate :: Unary n -> Unary n #

abs :: Unary n -> Unary n #

signum :: Unary n -> Unary n #

fromInteger :: Integer -> Unary n #

Ord n => Ord (Unary n) Source # 

Methods

compare :: Unary n -> Unary n -> Ordering #

(<) :: Unary n -> Unary n -> Bool #

(<=) :: Unary n -> Unary n -> Bool #

(>) :: Unary n -> Unary n -> Bool #

(>=) :: Unary n -> Unary n -> Bool #

max :: Unary n -> Unary n -> Unary n #

min :: Unary n -> Unary n -> Unary n #

Read n => Read (Unary n) Source # 
Real n => Real (Unary n) Source # 

Methods

toRational :: Unary n -> Rational #

Show n => Show (Unary n) Source # 

Methods

showsPrec :: Int -> Unary n -> ShowS #

show :: Unary n -> String #

showList :: [Unary n] -> ShowS #

Integral n => Coded (Unary n) Source # 

Methods

encode :: MonadPut m => Unary n -> Coding m () Source #

encodeMany :: (MonadPut m, Foldable t) => t (Unary n) -> Coding m () Source #

decode :: MonadGet m => Coding m (Unary n) Source #

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

Instances

Enum n => Enum (Elias c n) Source # 

Methods

succ :: Elias c n -> Elias c n #

pred :: Elias c n -> Elias c n #

toEnum :: Int -> Elias c n #

fromEnum :: Elias c n -> Int #

enumFrom :: Elias c n -> [Elias c n] #

enumFromThen :: Elias c n -> Elias c n -> [Elias c n] #

enumFromTo :: Elias c n -> Elias c n -> [Elias c n] #

enumFromThenTo :: Elias c n -> Elias c n -> Elias c n -> [Elias c n] #

Eq n => Eq (Elias c n) Source # 

Methods

(==) :: Elias c n -> Elias c n -> Bool #

(/=) :: Elias c n -> Elias c n -> Bool #

Integral n => Integral (Elias c n) Source # 

Methods

quot :: Elias c n -> Elias c n -> Elias c n #

rem :: Elias c n -> Elias c n -> Elias c n #

div :: Elias c n -> Elias c n -> Elias c n #

mod :: Elias c n -> Elias c n -> Elias c n #

quotRem :: Elias c n -> Elias c n -> (Elias c n, Elias c n) #

divMod :: Elias c n -> Elias c n -> (Elias c n, Elias c n) #

toInteger :: Elias c n -> Integer #

Num n => Num (Elias c n) Source # 

Methods

(+) :: Elias c n -> Elias c n -> Elias c n #

(-) :: Elias c n -> Elias c n -> Elias c n #

(*) :: Elias c n -> Elias c n -> Elias c n #

negate :: Elias c n -> Elias c n #

abs :: Elias c n -> Elias c n #

signum :: Elias c n -> Elias c n #

fromInteger :: Integer -> Elias c n #

Ord n => Ord (Elias c n) Source # 

Methods

compare :: Elias c n -> Elias c n -> Ordering #

(<) :: Elias c n -> Elias c n -> Bool #

(<=) :: Elias c n -> Elias c n -> Bool #

(>) :: Elias c n -> Elias c n -> Bool #

(>=) :: Elias c n -> Elias c n -> Bool #

max :: Elias c n -> Elias c n -> Elias c n #

min :: Elias c n -> Elias c n -> Elias c n #

Read n => Read (Elias c n) Source # 
Real n => Real (Elias c n) Source # 

Methods

toRational :: Elias c n -> Rational #

Show n => Show (Elias c n) Source # 

Methods

showsPrec :: Int -> Elias c n -> ShowS #

show :: Elias c n -> String #

showList :: [Elias c n] -> ShowS #

(Coded c, Integral c, Ranked n) => Coded (Elias c n) Source # 

Methods

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

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

decode :: MonadGet m => Coding m (Elias c n) Source #

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 #