Code Monkey home page Code Monkey logo

lzw_compression's Introduction

LZW_Compression

An implementation of LZW compression algorithm in Java.

Overview

LZW is a compression algorithm that was created in 1984 by Abraham Lempel, Jacob Ziv, and Terry Welch.In its most basic form, it will output a compressed file as a series of fixed-length codewords.Variable-width codewords can be used to increase the size of codewords output as the dictionary fills up.Further, once the dictionary fills up, the algorithm can either stop adding patterns and continue compression with only the patterns already discovered, or the algorithm can reset the codebook to find new patterns.

This project is a modification of the LZW compression algorithm to use variable-width codewords, and to optionally reset the codebook under certain conditions. With these changes in hand, I have compared the performance of modified LZW code with the LZW code in course textbook, and further with the performance of a widely used compression application.

How to run

Compile the program by running javac MyLZW.java.

There are 3 modes to run this project:

  1. Do Nothing mode Do nothing and continue to use the full codebook (this is already implemented by LZW.java).
  2. Reset mode Reset the dictionary back to its initial state so that new codewords can be added. Be careful to reset at the appropriate place for both compression and expansion, so that the algorithms remain in sync. This is very tricky and may require alot of planning in order to get it working correctly.
  3. Monitor mode Initially do nothing (keep using the full codebook) but begin monitoring the compression ratio whenever you fill the codebook.

Which mode should be used should be chosen by the program during compression. Whichever mode is used to compress a file should also be used to expand the file. The user is not required to state the mode to use for expansion. The mode used to compress a file will be stored at the beginning of the output file, so that it can be automatically retrieved during expansion. To establish the mode to be used during compression, the program will accept 3 command line arguments:
* "n" for Do Nothing mode
* "r" for Reset mode
* "m" for Monitor mode
Note that the provided LZW code already accepts a command line argument to determine whether compression or expansion should be performed ("-" and "+", respectively), and that input/output files are provided via standard I/O redirection ("<" to indicate an input file and ">" to indicate an output file). To compress the file foo.txt to generate foo.lzw using Reset mode, you should be able to run:
java MyLZW - r < foo.txt > foo.lzw Similarly to expand foo.lzw into foo2.txt, you should run:
java MyLZW + < foo.lzw > foo2.txt

lzw_compression's People

Contributors

fatemaquaid987 avatar

Watchers

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.