Averest


Encodings Module

Types

Type Description

BinCodeTree

Prefix codes are represented as binary trees whose leafs are the symbols that were encoded. The codes correspond with the paths from the root to the character where left/right branchings correspond with bits 0 and 1, respectively.

Functions and values

Function or value Description

ArithCode probList wordToEncode

Full Usage: ArithCode probList wordToEncode

Parameters:
    probList : (char * float) list
    wordToEncode : string

Returns: Map<char, (float * float)> * (float * float)[]

Arithmetic encoding yields the minimal number of bits due to Shannon's source coding theorem. Given list of characters c with probabilities and a word to encode, the function computes a mapping from characters to the corresponding intervals in [0.0,1.0], and an array of intervals that are associated with the prefixes of the given word to encode.

probList : (char * float) list
wordToEncode : string
Returns: Map<char, (float * float)> * (float * float)[]

AverageSize probList codeTree

Full Usage: AverageSize probList codeTree

Parameters:
    probList : (char * float) list
    codeTree : BinCodeTree

Returns: float

Determine the average number of bits per character of the prefix code given by the code tree.

probList : (char * float) list
codeTree : BinCodeTree
Returns: float

BinCodeTree2Dot probList codeTree ostr

Full Usage: BinCodeTree2Dot probList codeTree ostr

Parameters:

Write a code tree in dot file format to output stream ostr; arguments are the list of characters with their probabilities, the code tree, and the output stream.

probList : (char * float) list
codeTree : BinCodeTree
ostr : TextWriter

BinCodeTree2Encoding codeTree

Full Usage: BinCodeTree2Encoding codeTree

Parameters:
Returns: Map<char, string>

BinCodeTree2Encoding determines from a binary code tree (whose leafs are chars) the corresponding encoding of the characters by bitvectors.

codeTree : BinCodeTree
Returns: Map<char, string>

CyclicReduncdancyCheck codeWord crcWord

Full Usage: CyclicReduncdancyCheck codeWord crcWord

Parameters:
    codeWord : string
    crcWord : string

Returns: string

This function computes a polynomial division as used by cyclic redundancy checks, i.e., it divides bitvector codeWord by bitvector crcWord, where subtraction is done by bitwise exclusive-or operations. The resulting remainder must be zero to indicate no errors. The checksum of a given code can be obtained by adding (String.length crcWord)-1 zeros to the right before computing the polynom division.

codeWord : string
crcWord : string
Returns: string

CyclicRedundancyCheckTool qscoll

Full Usage: CyclicRedundancyCheckTool qscoll

Parameters:

CyclicRedundancyCheckTool is the function to be called from the web page; it expects bitvector arguments codeWord and crcWord.

qscoll : NameValueCollection

DecodeWord codeTree s

Full Usage: DecodeWord codeTree s

Parameters:
Returns: string

Decode a given string s consisting only of 0 and 1 with a prefix code given by the code tree; trailing bits that do not form another full code word are ignored.

codeTree : BinCodeTree
s : string
Returns: string

EncodeWord codeTree s

Full Usage: EncodeWord codeTree s

Parameters:
Returns: string

Encode a given word s with a prefix code given by the code tree.

codeTree : BinCodeTree
s : string
Returns: string

Entropy probList

Full Usage: Entropy probList

Parameters:
    probList : (char * float) list

Returns: float

Compute the entropy of a given character probability list.

probList : (char * float) list
Returns: float

EntropyEncodingTool qscoll

Full Usage: EntropyEncodingTool qscoll

Parameters:

EntropyEncodingTool is the function to be called from the web page; it expects the following key/value pairs:

  • probList: symbols with probabilities like (A,0.18);(B,0.16);(C,0.12);(D,0.11);(E,0.10);(F,0.09); (G,0.08);(H,0.07);(I,0.05);(J,0.04)
  • wordToEncode: a word like "CAGE"
  • wordToDecode: a word like "0011001010"

qscoll : NameValueCollection

FibonacciCode n

Full Usage: FibonacciCode n

Parameters:
    n : int

Returns: int[] * int[][] * string[]

Fibonacci encoding according to Zeckendorf's theorem: Every natural number can be written as a sum of Fibonacci numbers that does not include two successor Fibonacci numbers. This function computes a triple (fSeq,zeck,codes) such that fSeq is a prefix of the Fibonacci sequence that ends with the first Fibonacci number which is greater than n; zeck is an array such that zeck[k] is an array of indices of those Fibonacci numbers whose sum yields k, and codes is an array that maps k to its code word codes[k]. The code words codes[k] start with "11" and have no occurrences of "11" other than this prefix (hence, it forms a prefix code).

n : int
Returns: int[] * int[][] * string[]

FibonacciEncode probList codes wordToEncode

Full Usage: FibonacciEncode probList codes wordToEncode

Parameters:
    probList : (char * float) list
    codes : string[]
    wordToEncode : string

Returns: int[] * string

Encoding a given word with a Fibonacci code as generated by function FibonacciCode.

probList : (char * float) list
codes : string[]
wordToEncode : string
Returns: int[] * string

HuffmanCodeTree probList

Full Usage: HuffmanCodeTree probList

Parameters:
    probList : (char * float) list

Returns: BinCodeTree

HuffmanCodeTree generates a binary code tree according to the Huffman algorithm. In contrast to the Shannon-Fano algorithm, Huffmann encoding is provably optimal for fixed size code words.

probList : (char * float) list
Returns: BinCodeTree

LinearSeparatedCodesTool qscoll

Full Usage: LinearSeparatedCodesTool qscoll

Parameters:
qscoll : NameValueCollection

PrintCodeAsHtmlTable ostr codeTree

Full Usage: PrintCodeAsHtmlTable ostr codeTree

Parameters:

Print the prefix code of a code tree as a html table mapping characters to their code words.

ostr : TextWriter
codeTree : BinCodeTree

ShannonFanoCodeTree probList

Full Usage: ShannonFanoCodeTree probList

Parameters:
    probList : (char * float) list

Returns: BinCodeTree

ShannonFanoCodeTree generates a binary code tree for encoding characters given with probabilities in probList according to the Shannon-Fano algorithm.

probList : (char * float) list
Returns: BinCodeTree