Defines | Typedefs | Functions

fastlz.c File Reference

#include "fastlz.c"
Include dependency graph for fastlz.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define FASTLZ_SAFE
#define FASTLZ_EXPECT_CONDITIONAL(c)   (c)
#define FASTLZ_UNEXPECT_CONDITIONAL(c)   (c)
#define FASTLZ_INLINE
#define FASTLZ_STRICT_ALIGN
#define MAX_COPY   32
#define MAX_LEN   264
#define MAX_DISTANCE   8192
#define FASTLZ_READU16(p)   ((p)[0] | (p)[1]<<8)
#define HASH_LOG   13
#define HASH_SIZE   (1<< HASH_LOG)
#define HASH_MASK   (HASH_SIZE-1)
#define HASH_FUNCTION(v, p)   { v = FASTLZ_READU16(p); v ^= FASTLZ_READU16(p+1)^(v>>(16-HASH_LOG));v &= HASH_MASK; }
#define FASTLZ_LEVEL   1
#define FASTLZ_COMPRESSOR   fastlz1_compress
#define FASTLZ_DECOMPRESSOR   fastlz1_decompress
#define FASTLZ_LEVEL   2
#define MAX_DISTANCE   8191
#define MAX_FARDISTANCE   (65535+MAX_DISTANCE-1)
#define FASTLZ_COMPRESSOR   fastlz2_compress
#define FASTLZ_DECOMPRESSOR   fastlz2_decompress

Typedefs

typedef unsigned char flzuint8
typedef unsigned short flzuint16
typedef unsigned int flzuint32

Functions

int fastlz_compress (const void *input, int length, void *output)
 Compress a block of data in the input buffer and returns the size of compressed block.
int fastlz_compress_level (int level, const void *input, int length, void *output)
 Compress a block of data in the input buffer and returns the size of compressed block.
int fastlz_decompress (const void *input, int length, void *output, int maxout)
 Decompress a block of compressed data and returns the size of the decompressed block.
static FASTLZ_INLINE int FASTLZ_COMPRESSOR (const void *input, int length, void *output)
static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR (const void *input, int length, void *output, int maxout)

Define Documentation

#define FASTLZ_COMPRESSOR   fastlz1_compress

Definition at line 124 of file fastlz.c.

#define FASTLZ_COMPRESSOR   fastlz2_compress

Definition at line 124 of file fastlz.c.

#define FASTLZ_DECOMPRESSOR   fastlz1_decompress

Definition at line 125 of file fastlz.c.

#define FASTLZ_DECOMPRESSOR   fastlz2_decompress

Definition at line 125 of file fastlz.c.

#define FASTLZ_EXPECT_CONDITIONAL (   c  )     (c)

Definition at line 42 of file fastlz.c.

#define FASTLZ_INLINE

Definition at line 54 of file fastlz.c.

#define FASTLZ_LEVEL   2

Definition at line 116 of file fastlz.c.

#define FASTLZ_LEVEL   1

Definition at line 116 of file fastlz.c.

#define FASTLZ_READU16 (   p  )     ((p)[0] | (p)[1]<<8)

Definition at line 96 of file fastlz.c.

#define FASTLZ_SAFE

Definition at line 33 of file fastlz.c.

#define FASTLZ_STRICT_ALIGN

Definition at line 61 of file fastlz.c.

#define FASTLZ_UNEXPECT_CONDITIONAL (   c  )     (c)

Definition at line 43 of file fastlz.c.

#define HASH_FUNCTION (   v,
  p 
)    { v = FASTLZ_READU16(p); v ^= FASTLZ_READU16(p+1)^(v>>(16-HASH_LOG));v &= HASH_MASK; }

Definition at line 102 of file fastlz.c.

#define HASH_LOG   13

Definition at line 99 of file fastlz.c.

#define HASH_MASK   (HASH_SIZE-1)

Definition at line 101 of file fastlz.c.

#define HASH_SIZE   (1<< HASH_LOG)

Definition at line 100 of file fastlz.c.

#define MAX_COPY   32

Definition at line 89 of file fastlz.c.

#define MAX_DISTANCE   8192

Definition at line 119 of file fastlz.c.

#define MAX_DISTANCE   8191

Definition at line 119 of file fastlz.c.

#define MAX_FARDISTANCE   (65535+MAX_DISTANCE-1)

Definition at line 120 of file fastlz.c.

#define MAX_LEN   264

Definition at line 90 of file fastlz.c.


Typedef Documentation

typedef unsigned short flzuint16

Definition at line 81 of file fastlz.c.

typedef unsigned int flzuint32

Definition at line 82 of file fastlz.c.

typedef unsigned char flzuint8

Definition at line 80 of file fastlz.c.


Function Documentation

int fastlz_compress ( const void *  input,
int  length,
void *  output 
)

Compress a block of data in the input buffer and returns the size of compressed block.

The size of input buffer is specified by length. The minimum input buffer size is 16.

The output buffer must be at least 5% larger than the input buffer and can not be smaller than 66 bytes.

If the input is not compressible, the return value might be larger than length (input buffer size).

The input buffer and the output buffer can not overlap.

Definition at line 130 of file fastlz.c.

Referenced by RamCacheCLFUS::compress_entries().

int fastlz_compress_level ( int  level,
const void *  input,
int  length,
void *  output 
)

Compress a block of data in the input buffer and returns the size of compressed block.

The size of input buffer is specified by length. The minimum input buffer size is 16.

The output buffer must be at least 5% larger than the input buffer and can not be smaller than 66 bytes.

If the input is not compressible, the return value might be larger than length (input buffer size).

The input buffer and the output buffer can not overlap.

Compression level can be specified in parameter level. At the moment, only level 1 and level 2 are supported. Level 1 is the fastest compression and generally useful for short data. Level 2 is slightly slower but it gives better compression ratio.

Note that the compressed data, regardless of the level, can always be decompressed using the function fastlz_decompress above.

Definition at line 154 of file fastlz.c.

static FASTLZ_INLINE int FASTLZ_COMPRESSOR ( const void *  input,
int  length,
void *  output 
) [static]
int fastlz_decompress ( const void *  input,
int  length,
void *  output,
int  maxout 
)

Decompress a block of compressed data and returns the size of the decompressed block.

If error occurs, e.g. the compressed data is corrupted or the output buffer is not large enough, then 0 (zero) will be returned instead.

The input buffer and the output buffer can not overlap.

Decompression is memory safe and guaranteed not to write the output buffer more than what is specified in maxout.

Definition at line 140 of file fastlz.c.

Referenced by RamCacheCLFUS::get().

static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR ( const void *  input,
int  length,
void *  output,
int  maxout 
) [static]