Code Monkey home page Code Monkey logo

huffmancompression's Introduction

HuffmanBinaryTree

This program compresses files by reducing the necessary number of bits per character by using a Huffman coding scheme that is generated from a Huffman Tree structure. Using a priority queue our program constructs a tree that always has nodes with the lowest frequencies farthest down the tree, and nodes with high frequencies up near the root of the tree. Left subtree paths have a “0” value, and right subtrees have a “1” value. The unique structure that is created is exactly what is needed to make path codes, which exhibit the prefix property. Our program is able to output our tree, in standard order, to a given code file. It is also able to take encoded files and decode them back into their original 8-bit character format using the code file.

Public Methods

post: constructs the initial Huffman structure with the given frequency counts of ASCII characters. An extra node is added to account for our special pseudo-eof character

public HuffmanBinaryTree(int[] count)

pre : Scanner contains a tree stored in standard format post: constructs a Huffman structure from the given code file. Uses each binary value in the Huffman code to reconstruct a pathway from the top of the tree to each character node. A binary value of 0 means we shall progress left down the tree, and a value of 1 means we progress downward to the right. A dummy(empty) root will be instantiated.

public HuffmanBinaryTree(Scanner input)

post: writes the tree to the given output file in standard format which consists of line pairs that describe the ASCII value code for each character in the structure. Codes will appear in traversal order.

public void write(PrintStream output)

post: returns the current sum of letter counts in the LetterInventory instance

public void write(PrintStream output)

pre : input stream contains a legal encoding of characters for this tree’s Huffman code post: reads individual bits from the input stream and writes corresponding characters to the given output file. This method stops reading if it encounters our pseudo-eof character.

public void decode(BitInputStream input, PrintStream output, int eof)

huffmancompression's People

Contributors

chrisg220 avatar

Watchers

 avatar James Cloos avatar  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.