RedLZ78 lz78 compression/decompression


see http://oldwww.rasip.fer.hr/research/compress/algorithms/fund/lz/lz78.html


a dictionary look-up compressor that performs best with sets of large repetitive data.

works with Integer, Float and Symbol.  can also take a String instead of an Array.


see also: RedBase64 RedHuffman RedLZ77 RedLZSS RedLZW RedRLE


*compress(string)

returns an array

*decompress(array)

returns an array



//--

a= "AABCBBABC".ascii;

b= RedLZ78.compress(a);

c= RedLZ78.decompress(b);

a==c



a= "abracadabra"; //string instead of array

b= RedLZ78.compress(a);

c= RedLZ78.decompress(b);

a==c.join



a= "JOEYNJOEYNJOEYJOEYNJOEYNJOEYJOEYNJOEYNJOEYJOEYNJOEYNJOEY".ascii;

b= RedLZ78.compress(a);

b.size/a.size; //compressed to 75%

c= RedLZ78.decompress(b);

a==c



a= "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.".ascii;

b= RedLZ78.compress(a);

b.size/a.size; //compressed to 94%

c= RedLZ78.decompress(b);

c.collect{|x| x.asAscii}.join;

a==c



a= {[0, 0, 0, 0.1].choose}.dup(5000);

b= RedLZ78.compress(a);

b.size/a.size; //compressed to 22%

c= RedLZ78.decompress(b);

c.size

a==c