Giter Site home page Giter Site logo

huffman's Introduction

Huffman

Code Climate Build Status Gem Version

The Huffman gem

This gem allow you to encode and decode a text using the Huffman encoding compression algorithm. It can also generate and visualize the huffman tree as a png file.

Setup

-Add this line to your application's Gemfile:

gem 'huffman'

-And then execute:

$ bundle

-Or install it yourself as:

$ gem install huffman

-Install graphviz if you want to be able to visualize trees.

Usage

Encode a text :

Huffman.encode_text(txt) # return text_encoded, dictionnary
Huffman.encode_text(txt) # return text_encoded, dictionnary

Decode a text :

Huffman.decode_text(encoded_txt, dictionnary) # return decoded_text

Encode a text file

Huffman.encode_file(file_name) # write a file_name.huffman-encoded file and a file_name.huffman-dictionnary
Huffman.encode_file(file_name) # write a file_name.huffman-encoded file and a file_name.huffman-dictionnary

Decode a text file :

Huffman.decode_file(huffman_encoded_file_path,huffman-dictionnary_path) # write a huffman-encoded-back-to-original file

Generate a Huffman tree

Huffman tree

This gem give you the ability to generate and visualize the huffman tree. You have to install graphviz before.

All you need to do is to optionally add some options to the encode_file and decode_file method :

Huffman.encode_text(txt, tree_picture: true, tree_path: "my_trees/the_tree")     # or
Huffman.encode_file(file_name, tree_picture: true, tree_path: "my_trees/the_tree") 

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

huffman's People

Contributors

supertinou avatar bj0rge avatar fgosew avatar

Forkers

chillerdragon

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.