text
stringlengths
0
99.6k
out the prefix 6 and make "c" the new prefix.
At this point our string table looks like this:
string code prefix+extension
------ ---- ----------------
a 1
b 2
c 3
ab 4 1+2
ba 5 2+1
aba 6 4+1
abac 7 6+1
Or if you prefer trees:
a=1 - b=4 - a=6 - c=7
/
root - b=2 - a=5
\
c=3
This goes on until the string table is full. If there
is enough repetition in the input file, long sequences of
characters can be replaced by short 9-12 bit codes and
significant savings can be achieved.
ARC VERSION 2.20 PAGE - 37
ARC starts out by initializing its string table to 256
entries; the byte values 0 to 255. Since the first 256 codes
generated will take on values between 256 and 511, we only
need nine bits for the first 256 codes. The next 512 codes
will be between 512 and 1023, so we only need 10 bits for
the next 512 codes. The size of the code keeps growing like
this until it reaches 12 bits and the string table is full.
This significantly improves the compression ratio when
crunching small files.
Once the string table is full, if a character is
encountered for the first time, it will have to be sent to
the output file as a 12 bit code; a 50% loss! We have found
that the string table usually fills up at about 60-70 CBM
disk blocks for text, and at about 40 for machine language.
You may notice that ML programs of 40 blocks or less usually
crunch, wheras longer ML programs tend to be squashed. If
you are crunching text files, the compression ratio is
usually about 2.00. Once the string table has become full,
the compression ratio will start to diminish because of
this.
ARC reserves two codes when it crunches a file. Code
256 is reserved to indicate the end of file. This is
necessary since ARC doesn't know a files length until after
it has been archived using the single pass crunch option.
Code 257 is reserved for future versions of ARC, which will
use it as a signal to tell the decompressor to reset the
string table once the compression ratio starts to fall off
on large files.
Another amazing thing about crunching is the fact that
it is not very efficient! No attempt is made to find the
most often occuring character sequences in the file. The LZW
approach simply takes things as they come. A long and very
infrequently occuring character sequence could be taking up
valuable space in the string table, when other frequently
occurring sequences have to be coded as individual codes
once the table is full. When a file is very long, the string
table may have given a good compression ratio near the
beginning of the file but the string table may no longer
reflect the files characteristics near the end of the file.
Despite the fact that crunching gives quite good
compression ratios, there is lots of room for improvement.
We could be more selective about the strings we allow in the
table, we could purge the table periodically for
infrequently used codes, or we could simply use a larger
string table.
ARC VERSION 2.20 PAGE - 38
Archive File Format
Each archive entry consists of a short header followed
by the compressed file. If the file is squeezed or squashed,
the Huffman encoding table appears immediately following the
header and before the file data. The archive header consists
of the following bytes: