Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

lzsscomprs.h

00001 /******************************************************************************
00002  *  lzsscomprs.h   - definition of Class SWCompress used for data compression
00003  *
00004  * $Id: lzsscomprs_8h-source.html,v 1.7 2002/06/20 20:23:09 mgruner Exp $
00005  *
00006  * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
00007  *      CrossWire Bible Society
00008  *      P. O. Box 2528
00009  *      Tempe, AZ  85280-2528
00010  *
00011  * This program is free software; you can redistribute it and/or modify it
00012  * under the terms of the GNU General Public License as published by the
00013  * Free Software Foundation version 2.
00014  *
00015  * This program is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * General Public License for more details.
00019  *
00020  */
00021 
00022 #ifndef LZSSCOMPRS_H
00023 #define LZSSCOMPRS_H
00024 
00025 #include <swcomprs.h>
00026 
00027 #include <defs.h>
00028 
00029 // The following are constant sizes used by the compression algorithm.
00030 //
00031 //  N         - This is the size of the ring buffer.  It is set
00032 //              to 4K.  It is important to note that a position
00033 //              within the ring buffer requires 12 bits.  
00034 //
00035 //  F         - This is the maximum length of a character sequence
00036 //              that can be taken from the ring buffer.  It is set
00037 //              to 18.  Note that a length must be 3 before it is
00038 //              worthwhile to store a position/length pair, so the
00039 //              length can be encoded in only 4 bits.  Or, put yet
00040 //              another way, it is not necessary to encode a length
00041 //              of 0-18, it is necessary to encode a length of
00042 //              3-18, which requires 4 bits.
00043 //              
00044 //  THRESHOLD - It takes 2 bytes to store an offset and
00045 //              a length.  If a character sequence only
00046 //              requires 1 or 2 characters to store 
00047 //              uncompressed, then it is better to store
00048 //              it uncompressed than as an offset into
00049 //              the ring buffer.
00050 //
00051 // Note that the 12 bits used to store the position and the 4 bits
00052 // used to store the length equal a total of 16 bits, or 2 bytes.
00053 
00054 #define N               4096
00055 #define F               18
00056 #define THRESHOLD       3
00057 #define NOT_USED        N
00058 
00059 
00060 
00061 class SWDLLEXPORT LZSSCompress:public SWCompress
00062 {
00063   static unsigned char m_ring_buffer[N + F - 1];
00064   static short int m_match_position;
00065   static short int m_match_length;
00066   static short int m_lson[N + 1];
00067   static short int m_rson[N + 257];
00068   static short int m_dad[N + 1];
00069   void InitTree ();
00070   void InsertNode (short int Pos);
00071   void DeleteNode (short int Node);
00072 public:
00073     LZSSCompress ();
00074     virtual ~ LZSSCompress ();
00075   virtual void Encode (void);
00076   virtual void Decode (void);
00077 };
00078 
00079 #endif

Generated on Thu Jun 20 22:12:59 2002 for The Sword Project by doxygen1.2.15