Maven module :un.api : api-encoding :
Class : un.impl.io.lzss.LZSSOutputStream
Extends/Implements : un.api.io.WrapOutputStream
Subclasses : -

This compression algorithm is based on the ideas of Lempel and Ziv,
with the modifications suggested by Storer and Szymanski. The algorithm
is based on the use of a ring buffer, which initially contains zeros.
We read several characters from the file into the buffer, and then
search the buffer for the longest string that matches the characters
just read, and output the length and position of the match in the buffer.

With a buffer size of 4096 bytes, the position can be encoded in 12
bits. If we represent the match length in four bits, the length> pair is two bytes long. If the longest match is no more than
two characters, then we send just one character without encoding, and
restart the process with the next letter. We must send one extra bit
each time to tell the decoder whether we are sending a length> pair or an unencoded character, and these flags are stored as
an eight bit mask every eight items.

This implementation uses binary trees to speed up the search for the
longest match.

Original code by Haruhiko Okumura, 4/6/1989.
12-2-404 Green Heights, 580 Nagasawa, Yokosuka 239, Japan.

Modified for use in the Allegro filesystem by Shawn Hargreaves.

Use, distribute, and modify this code freely.


References :
http://en.wikipedia.org/wiki/Lempel-Ziv-Storer-Szymanski

Source available in public domain :
http://home.worldonline.cz/~cz210552/lzss.html
http://en.pudn.com/downloads121/sourcecode/java/detail516351_en.html (web cache of the above link)


@author Haruhiko Okumura
@author Shawn Hargreaves
@author Johann Sorel (Adapted to Unlicense-lib)


Variables : state, i, len, r, s, c, last_match_length, code_buf_ptr, mask, code_buf, match_position, match_length, lson, rson, dad, text_buf
Functions : LZSSOutputStream, write, write, flush, close



/* stuff for doing LZ compression */
int state


/* where have we got to in the pack? */
int i


/* where have we got to in the pack? */
int len


/* where have we got to in the pack? */
int r


/* where have we got to in the pack? */
int s

byte c

int last_match_length

int code_buf_ptr

byte mask

byte code_buf

int match_position

int match_length

int lson


/* left children, */
int rson


/* right children, */
int dad


/* and parents, = binary search trees */
byte text_buf



/* ring buffer, with F-1 extra bytes
for string comparison */
void LZSSOutputStream (ByteOutputStream out)

public void write (byte zz, int ofs, int sz)

public void write (byte b)

public void flush ()

public void close ()