Giter Site home page Giter Site logo

huffman_js's Introduction

Huffman JS

Huffman JS is an implementation of Huffman Algorithm in Javascript. It provides
full compatibility with Huffman algorithm reference.

Basic Usage

Include the JS file with latest version in your site (it will be in dist directory):

<script type="text/javascript" src="huffman-0.9.0.min.js"></script>

Them you can do a lot of things, let get a basic usage by generating a custom tree:

text = "some text to encode with huffman";
huffman = Huffman.treeFromText(text); // first we need to create the tree to make encoding/decoding
encoded = huffman.encode(text); // will return the compressed version of text
decoded = huffman.decode(encoded); // will decode text to original version

The idea to create a tree to use with same text may seem strange at first, but
you probably will want to have a default to your encoding/decodings, otherwise
you will need to send your tree with encoded text in order to decode it in other place.

Encoding / Decoding Trees

You can easily save a Huffman Tree to use it again later (or transmit it will
encoded information to receiver be capable to decode it if you are not using
a default tree).

text = "some text to encode with huffman";
huffman = Huffman.treeFromText(text); // generate the tree
treeEncoded = huffman.encodeTree(); // will return an javascript array with tree representation
treeAgain = Huffman.decodeTree(treeEncoded); // restore the tree based on array representation
treeJSON = JSON.stringify(treeEncoded); // get a JSON string for easy transportation

Authors

Wilker Lúcio da Silva

huffman_js's People

Contributors

wilkerlucio avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.