RedHuffman:
Filter:
Classes (extension) | Red > redTools

RedHuffman : Object
ExtensionExtension

huffman coding

Description

The principle is "to use fewer bits for more frequently occurring character".

See http://www.cs.duke.edu/csed/poop/huff/info/

NOTE: Works with Integer, Float and Symbol. Can also take a String instead of an Array.

Class Methods

RedHuffman.compress(arr)

Compresses an array into a string of binary numbers. Creates a *tree and a *dict as well.

RedHuffman.decompress(str)

Decompresses a binary string into an array. Make sure you use the right *tree and *dict as generated by the compress method.

RedHuffman.binaryStringToBytes(str)

Converts a binary string into 8-bit bytes. Up to 7 zeros might be padded automatically at the end. The number of zeros is stored in *pad. *pad is semi-private and used when converting back to bytes.

RedHuffman.bytesToBinaryString(arr)

Converts an array of 8-bit bytes into a binary string.

RedHuffman.pad

RedHuffman.pad = value

Semi-private counter for number of padded zeros. Set by *binaryStringToBytes and read by *bytesToBinaryString.

RedHuffman.tree

RedHuffman.tree = value

Multi-level array with values as leaves.

RedHuffman.dict

RedHuffman.dict = value

Look-up dictionary with values and binary strings.

Inherited class methods

Instance Methods

Inherited instance methods

Examples