					
				Huffman.java
				~~~~~~~~~~~~

	A dirty but free implementation of a huffman encoder/decoder in Java.


1) What it is
~~~~~~~~~~~~~

As said above, this is just a dirty implementation of a huffman 
coder/decoder written in Java. You can use it if you want to build your own 
compressor oder decompressor with Java or if you want to study how a huffman
coder works. It is far away from being optimized. I used to write it for another
project of mine, on which you can look take a look at:

			 http://www.javaradio.de  

Feel free to do what you want with it - according to the GNU GLPL (see 5).


2.) How to install it
~~~~~~~~~~~~~~~~~~~~~

I suggest compiling it first using one of your standard Java development tools,
like guavac or jikes. If you are using a Unix-like system, such as GNU/Linux
you may have a look at the "makefile".
Any version of Java equivalent to Sun's JDK >=1.00 should work.
Once built the class file, you can test the class on the command line with a
command like:

java Huffman "Mississippi"

or 

java Huffman "Mississippi" -d 

if you want to see more information.

(However this string won't compress very well)


3.) How to include the class in your own programs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you want an example implementation of the class, look at the class's 
main method, which you invoked above.

There are three important methods:

public int compress(byte[] datain, byte[] dataout, int[] treeout) 
public int treesize(int treein[])

public void uncompress(byte[] datain, byte dataout[], int[] treein)

which do the main jobs.

You should first instantiate a new class with a call like:
Huffman h = new Huffman();

Then you can call h.compress() which will then compress datain[], and write
the result to dataout[] and the resulting huffman tree to treeout[]. 
Both dataout[] and treeout[] must be initialized with enough memory, I suggest
dataout.length=datain.length and treeout.length=size of your alphabet, which is
stored in Huffman.ALPHABETSIZE. Be aware, that the result can even get bigger
than datain[].
The compress method returns the real amount of bytes of the compressed string as
integer value. 
To get the real size of the huffman tree in treeout[] call treesize().

To decompress call decompress with the compressed array in datain[] and your 
tree in treein[] and you get the result written to dataout[].


4.) Additional information
~~~~~~~~~~~~~~~~~~~~~~~~~~

This program is useful if, and only if, you find it useful.
The code is far away from being optimized and I am not liable
for any bugs or whatever might happen to you. If you find this piece
of code is not good, delete it, or even better, write a better one and
send it to me.


5.) Copyright
~~~~~~~~~~~~~

This project is copyrighted under the terms of the 
GNU Library Public License version 2.00 (GLPL).

To contact the author write to:
fractor@germanymail.com
        
Or visit my homepage at:
http://www.inf.fu-berlin.de/~fland
 
Trademarks etc... are trademarks of their owners and are not specially marked
as such.
