All Projects → kelreel → huffman-javascript

kelreel / huffman-javascript

Licence: other
Huffman encode/decode text

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to huffman-javascript

Huffman-Coding
A C++ compression program based on Huffman's lossless compression algorithm and decoder.
Stars: ✭ 81 (+305%)
Mutual labels:  huffman-coding, huffman-algorithm, huffman-tree, huffman-compression-algorithm
huffman
Huffman coding implementation in Go (Huffman tree, Symbol table, Huffman Reader + Writer).
Stars: ✭ 25 (+25%)
Mutual labels:  huffman-coding, huffman-tree
gpuhd
Massively Parallel Huffman Decoding on GPUs
Stars: ✭ 30 (+50%)
Mutual labels:  huffman-coding
huffman-coding
A C++ compression and decompression program based on Huffman Coding.
Stars: ✭ 31 (+55%)
Mutual labels:  huffman-coding
rust-huffman-compress
A Rust library for Huffman compression given a propability distribution over arbitrary symbols
Stars: ✭ 18 (-10%)
Mutual labels:  huffman-coding
huffman
Using huffman coding to compress-decompress real-world files
Stars: ✭ 27 (+35%)
Mutual labels:  huffman-algorithm
LittleBit
LittleBit is a pure Huffman coding compression algorithm with the option of random access reading while offering competitive compression ratios.
Stars: ✭ 13 (-35%)
Mutual labels:  huffman-tree


Huffman coding JS (TypeScript)

DEMO

Huffman code is a particular type of optimal prefix code that is commonly used for lossless data compression. This is the implementation of the algorithm on TypeScript.

Installation

Clone this repository and install modules:

git clone https://github.com/kanitelk/huffman-javascript.git
cd huffman-javascript
npm install
npm run dev(or build)

Usage

The algorithm implementation is in the file /src/index.ts

Let's encode and decode plain text!

import { getCodesFromText, encode, decode } from './huffman';

/** ENCODING */
let text: string = 'abracadabra'; 
let encodedText: string = '';

let codes: Map<string, string> = getCodesFromText(text); // Symbols codes
let encodedArray: Array<any> = encode(text, codes); // Get array of encoded symbols

encodedText = encodedArray.join(''); // Encoded array to string. Equals 0101100...

/** DECODING */
text = decode(encodedArray, codes); // Equals 'abracadabra'

APIs

Encode text

encode(text: string, codes: Map<string, string>): Array<string>

Decode text

decode(text: Array<string>, codes: Map<string, string>):string

Get symbols codes from text

getCodesFromText(text: string): Map<string, string>

Get symbols frequency

getFrequency(text: string): Array<any>

Get Huffman Tree from frequency array

getTree(arr: Array<any>)

Get relative frequency array

getRelativeFrequency(arr: Array<any>): Array<any>

Get text entropy

getEntropyOfText(text: string): number
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].