00001 /****************************************************************************** 00002 * lzsscomprs.h - definition of Class SWCompress used for data compression 00003 * 00004 * $Id: lzsscomprs_8h-source.html,v 1.9 2002/10/31 11:30:15 joachim 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 SWORD_NAMESPACE_START 00030 00031 // The following are constant sizes used by the compression algorithm. 00032 // 00033 // N - This is the size of the ring buffer. It is set 00034 // to 4K. It is important to note that a position 00035 // within the ring buffer requires 12 bits. 00036 // 00037 // F - This is the maximum length of a character sequence 00038 // that can be taken from the ring buffer. It is set 00039 // to 18. Note that a length must be 3 before it is 00040 // worthwhile to store a position/length pair, so the 00041 // length can be encoded in only 4 bits. Or, put yet 00042 // another way, it is not necessary to encode a length 00043 // of 0-18, it is necessary to encode a length of 00044 // 3-18, which requires 4 bits. 00045 // 00046 // THRESHOLD - It takes 2 bytes to store an offset and 00047 // a length. If a character sequence only 00048 // requires 1 or 2 characters to store 00049 // uncompressed, then it is better to store 00050 // it uncompressed than as an offset into 00051 // the ring buffer. 00052 // 00053 // Note that the 12 bits used to store the position and the 4 bits 00054 // used to store the length equal a total of 16 bits, or 2 bytes. 00055 00056 #define N 4096 00057 #define F 18 00058 #define THRESHOLD 3 00059 #define NOT_USED N 00060 00061 00062 00063 class SWDLLEXPORT LZSSCompress:public SWCompress 00064 { 00065 static unsigned char m_ring_buffer[N + F - 1]; 00066 static short int m_match_position; 00067 static short int m_match_length; 00068 static short int m_lson[N + 1]; 00069 static short int m_rson[N + 257]; 00070 static short int m_dad[N + 1]; 00071 void InitTree (); 00072 void InsertNode (short int Pos); 00073 void DeleteNode (short int Node); 00074 public: 00075 LZSSCompress (); 00076 virtual ~ LZSSCompress (); 00077 virtual void Encode (void); 00078 virtual void Decode (void); 00079 }; 00080 00081 SWORD_NAMESPACE_END 00082 #endif