The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LZSSCompress::Private Class Reference
+ Collaboration diagram for LZSSCompress::Private:

Public Member Functions

void DeleteNode (short int Node)
 
void InitTree ()
 
void InsertNode (short int Pos)
 

Static Public Attributes

static short int m_dad [N+1]
 
static short int m_lson [N+1]
 
static short int m_match_length
 
static short int m_match_position
 
static unsigned char m_ring_buffer [N+F-1]
 
static short int m_rson [N+257]
 

Detailed Description

Definition at line 61 of file lzsscomprs.cpp.

Member Function Documentation

void LZSSCompress::Private::DeleteNode ( short int  Node)

Definition at line 308 of file lzsscomprs.cpp.

309 {
310  short int q;
311 
312 /*
313  ASSERT(Node >= 0);
314  ASSERT(Node < (N+1));
315 */
316 
317  if (m_dad[Node] == NOT_USED) { // not in tree, nothing to do
318  return;
319  }
320 
321  if (m_rson[Node] == NOT_USED) {
322  q = m_lson[Node];
323  }
324  else if (m_lson[Node] == NOT_USED) {
325  q = m_rson[Node];
326  }
327  else {
328  q = m_lson[Node];
329  if (m_rson[q] != NOT_USED) {
330  do {
331  q = m_rson[q];
332  } while (m_rson[q] != NOT_USED);
333 
334  m_rson[ m_dad[q] ] = m_lson[q];
335  m_dad[ m_lson[q] ] = m_dad[q];
336  m_lson[q] = m_lson[Node];
337  m_dad[ m_lson[Node] ] = q;
338  }
339 
340  m_rson[q] = m_rson[Node];
341  m_dad[ m_rson[Node] ] = q;
342  }
343 
344  m_dad[q] = m_dad[Node];
345 
346  if (m_rson[ m_dad[Node] ] == Node) {
347  m_rson[ m_dad[Node] ] = q;
348  }
349  else {
350  m_lson[ m_dad[Node] ] = q;
351  }
352 
353  m_dad[Node] = NOT_USED;
354 }
#define NOT_USED
Definition: lzsscomprs.cpp:56
static short int m_lson[N+1]
Definition: lzsscomprs.cpp:66
static short int m_rson[N+257]
Definition: lzsscomprs.cpp:67
static short int m_dad[N+1]
Definition: lzsscomprs.cpp:68
void LZSSCompress::Private::InitTree ( void  )

Definition at line 151 of file lzsscomprs.cpp.

151  {
152  int i;
153 
154  // For i = 0 to N - 1, m_rson[i] and m_lson[i] will be the right
155  // and left children of node i. These nodes need not be
156  // initialized. However, for debugging purposes, it is nice to
157  // have them initialized. Since this is only used for compression
158  // (not decompression), I don't mind spending the time to do it.
159  //
160  // For the same range of i, m_dad[i] is the parent of node i.
161  // These are initialized to a known value that can represent
162  // a "not used" state.
163 
164  for (i = 0; i < N; i++) {
165  m_lson[i] = NOT_USED;
166  m_rson[i] = NOT_USED;
167  m_dad[i] = NOT_USED;
168  }
169 
170  // For i = 0 to 255, m_rson[N + i + 1] is the root of the tree
171  // for strings that begin with the character i. This is why
172  // the right child array is larger than the left child array.
173  // These are also initialzied to a "not used" state.
174  //
175  // Note that there are 256 of these, one for each of the possible
176  // 256 characters.
177 
178  for (i = N + 1; i <= (N + 256); i++) {
179  m_rson[i] = NOT_USED;
180  }
181 }
#define NOT_USED
Definition: lzsscomprs.cpp:56
static short int m_lson[N+1]
Definition: lzsscomprs.cpp:66
static short int m_rson[N+257]
Definition: lzsscomprs.cpp:67
static short int m_dad[N+1]
Definition: lzsscomprs.cpp:68
#define N
Definition: lzsscomprs.cpp:53
void LZSSCompress::Private::InsertNode ( short int  Pos)

Definition at line 210 of file lzsscomprs.cpp.

211 {
212  short int i;
213  short int p;
214  int cmp;
215  unsigned char * key;
216 
217 /*
218  ASSERT(Pos >= 0);
219  ASSERT(Pos < N);
220 */
221 
222  cmp = 1;
223  key = &(m_ring_buffer[Pos]);
224 
225  // The last 256 entries in m_rson contain the root nodes for
226  // strings that begin with a letter. Get an index for the
227  // first letter in this string.
228 
229  p = (short int) (N + 1 + key[0]);
230 
231  // Set the left and right tree nodes for this position to "not
232  // used."
233 
234  m_lson[Pos] = NOT_USED;
235  m_rson[Pos] = NOT_USED;
236 
237  // Haven't matched anything yet.
238 
239  m_match_length = 0;
240 
241  for ( ; ; ) {
242  if (cmp >= 0) {
243  if (m_rson[p] != NOT_USED) {
244  p = m_rson[p];
245  }
246  else {
247  m_rson[p] = Pos;
248  m_dad[Pos] = p;
249  return;
250  }
251  }
252  else {
253  if (m_lson[p] != NOT_USED) {
254  p = m_lson[p];
255  }
256  else {
257  m_lson[p] = Pos;
258  m_dad[Pos] = p;
259  return;
260  }
261  }
262 
263  // Should we go to the right or the left to look for the
264  // next match?
265 
266  for (i = 1; i < F; i++) {
267  cmp = key[i] - m_ring_buffer[p + i];
268  if (cmp != 0)
269  break;
270  }
271 
272  if (i > m_match_length) {
274  m_match_length = i;
275 
276  if (i >= F)
277  break;
278  }
279  }
280 
281  m_dad[Pos] = m_dad[p];
282  m_lson[Pos] = m_lson[p];
283  m_rson[Pos] = m_rson[p];
284 
285  m_dad[ m_lson[p] ] = Pos;
286  m_dad[ m_rson[p] ] = Pos;
287 
288  if (m_rson[ m_dad[p] ] == p) {
289  m_rson[ m_dad[p] ] = Pos;
290  }
291  else {
292  m_lson[ m_dad[p] ] = Pos;
293  }
294 
295  // Remove "p"
296 
297  m_dad[p] = NOT_USED;
298 }
#define NOT_USED
Definition: lzsscomprs.cpp:56
static short int m_lson[N+1]
Definition: lzsscomprs.cpp:66
static short int m_rson[N+257]
Definition: lzsscomprs.cpp:67
Private * p
Definition: lzsscomprs.h:35
static short int m_match_length
Definition: lzsscomprs.cpp:65
static unsigned char m_ring_buffer[N+F-1]
Definition: lzsscomprs.cpp:63
#define F
Definition: lzsscomprs.cpp:54
static short int m_match_position
Definition: lzsscomprs.cpp:64
static short int m_dad[N+1]
Definition: lzsscomprs.cpp:68
#define N
Definition: lzsscomprs.cpp:53

Member Data Documentation

short int LZSSCompress::Private::m_dad
static

Definition at line 68 of file lzsscomprs.cpp.

short int LZSSCompress::Private::m_lson
static

Definition at line 66 of file lzsscomprs.cpp.

short int LZSSCompress::Private::m_match_length
static

Definition at line 65 of file lzsscomprs.cpp.

short int LZSSCompress::Private::m_match_position
static

Definition at line 64 of file lzsscomprs.cpp.

unsigned char LZSSCompress::Private::m_ring_buffer
static

Definition at line 63 of file lzsscomprs.cpp.

short int LZSSCompress::Private::m_rson
static

Definition at line 67 of file lzsscomprs.cpp.


The documentation for this class was generated from the following file: