Java Reference
In-Depth Information
the main routine
The main routine is shown in the online code. If invoked with the -c argument,
it compresses; with the -u argument it uncompresses. Figure 12.25 illustrates
the wrapping of streams for compression and uncompression. Compression
adds a “.huf” to the filename; uncompression adds a “.uc” to the filename, to
avoid clobbering original files.
improving the program
The program, as written, serves its main purpose of illustrating the basics of
the Huffman coding algorithm. It achieves some compression, even on mod-
erately sized files. For instance, it obtains roughly 40 percent compression
when run on its own source file, Hzip.java . However, the program could be
improved in several ways.
1.
The error checking is limited. A production program should rigor-
ously ensure that the file being decompressed is actually a com-
pressed file. (One way to have it do so is to write extra information in
the encoding table.) The internal routines should have more checks.
2.
Little effort has been made to minimize the size of the encoding table.
For large files this lack is of little consequence, but for smaller files a
large encoding table can be unacceptable because the encoding table
takes up space itself.
3.
A robust program checks the size of the resulting compressed file and
aborts if the size is larger than the original.
4.
In many places we made little attempt to optimize for speed.
Memoization could be used to avoid repeated searching of the tree for
codes.
Further improvements to the program are left for you to do as Exer-
cises 12.14-12.16.
 
Search WWH ::




Custom Search