Current Forum: Homework 4 - Huffman Trees (Part 1) |
Date: Wed Oct 10 2001 1:01 am |
Author: Cipriani, Jason A. <jac4@andrew.cmu.edu> |
Subject: Re: general clarification on FileBitReader/Writer classes |
|
|
we all know by now that you can use readBits(8). the big difference between readByte() and readBits(8) isn't so much the return type as the implementation of it. readByte() calls FileInputStream.read(), while readBits does that little loop. readByte() is approximately 12% faster than readBits(8) on my own machine.
the big advantage to readBits(8) (besides the unsigned return type) is that the stuff doesn't necessarily need to be byte aligned to read it correctly.
the return type "byte" IS a bad choice. because of the fact that it is unsigned, it is a bad choice. "char" is far more appropriate from reading characters from a file. not only can it hold values in the range 0 to 255, but is two bytes long and thus has support (even though we don't need it for this assignment) for wider character sets. |
|