195#define PGLZ_MAX_HISTORY_LISTS 8192
196#define PGLZ_HISTORY_SIZE 4096
197#define PGLZ_MAX_MATCH 273
262#define INVALID_ENTRY 0
263#define INVALID_ENTRY_PTR (&hist_entries[INVALID_ENTRY])
277#define pglz_hist_idx(_s,_e, _mask) ( \
278 ((((_e) - (_s)) < 4) ? (int) (_s)[0] : \
279 (((_s)[0] << 6) ^ ((_s)[1] << 4) ^ \
280 ((_s)[2] << 2) ^ (_s)[3])) & (_mask) \
296#define pglz_hist_add(_hs,_he,_hn,_recycle,_s,_e, _mask) \
298 int __hindex = pglz_hist_idx((_s),(_e), (_mask)); \
299 int16 *__myhsp = &(_hs)[__hindex]; \
300 PGLZ_HistEntry *__myhe = &(_he)[_hn]; \
302 if (__myhe->prev == NULL) \
303 (_hs)[__myhe->hindex] = __myhe->next - (_he); \
305 __myhe->prev->next = __myhe->next; \
306 if (__myhe->next != NULL) \
307 __myhe->next->prev = __myhe->prev; \
309 __myhe->next = &(_he)[*__myhsp]; \
310 __myhe->prev = NULL; \
311 __myhe->hindex = __hindex; \
312 __myhe->pos = (_s); \
321 (_he)[(*__myhsp)].prev = __myhe; \
323 if (++(_hn) >= PGLZ_HISTORY_SIZE + 1) { \
336#define pglz_out_ctrl(__ctrlp,__ctrlb,__ctrl,__buf) \
338 if ((__ctrl & 0xff) == 0) \
340 *(__ctrlp) = __ctrlb; \
341 __ctrlp = (__buf)++; \
355#define pglz_out_literal(_ctrlp,_ctrlb,_ctrl,_buf,_byte) \
357 pglz_out_ctrl(_ctrlp,_ctrlb,_ctrl,_buf); \
358 *(_buf)++ = (unsigned char)(_byte); \
371#define pglz_out_tag(_ctrlp,_ctrlb,_ctrl,_buf,_len,_off) \
373 pglz_out_ctrl(_ctrlp,_ctrlb,_ctrl,_buf); \
378 (_buf)[0] = (unsigned char)((((_off) & 0xf00) >> 4) | 0x0f); \
379 (_buf)[1] = (unsigned char)(((_off) & 0xff)); \
380 (_buf)[2] = (unsigned char)((_len) - 18); \
383 (_buf)[0] = (unsigned char)((((_off) & 0xf00) >> 4) | ((_len) - 3)); \
384 (_buf)[1] = (unsigned char)((_off) & 0xff); \
512 unsigned char *
bp = (
unsigned char *) dest;
520 unsigned char ctrlb = 0;
521 unsigned char ctrl = 0;
536 if (strategy ==
NULL)
594 else if (
slen < 1024)
695 const unsigned char *
sp;
696 const unsigned char *
srcend;
700 sp = (
const unsigned char *)
source;
702 dp = (
unsigned char *) dest;
711 unsigned char ctrl = *
sp++;
730 len = (
sp[0] & 0x0f) + 3;
731 off = ((
sp[0] & 0xf0) << 4) |
sp[1];
746 off > (
dp - (
unsigned char *) dest)))
827 return (
char *)
dp - dest;
const PGLZ_Strategy *const PGLZ_strategy_always
static int16 hist_start[PGLZ_MAX_HISTORY_LISTS]
const PGLZ_Strategy *const PGLZ_strategy_default
static int pglz_find_match(int16 *hstart, const char *input, const char *end, int *lenp, int *offp, int good_match, int good_drop, int mask)
#define INVALID_ENTRY_PTR
#define pglz_hist_idx(_s, _e, _mask)
static const PGLZ_Strategy strategy_default_data
static PGLZ_HistEntry hist_entries[PGLZ_HISTORY_SIZE+1]
static const PGLZ_Strategy strategy_always_data
#define pglz_out_tag(_ctrlp, _ctrlb, _ctrl, _buf, _len, _off)
#define PGLZ_MAX_HISTORY_LISTS
#define pglz_out_literal(_ctrlp, _ctrlb, _ctrl, _buf, _byte)
int32 pglz_decompress(const char *source, int32 slen, char *dest, int32 rawsize, bool check_complete)
#define PGLZ_HISTORY_SIZE
int32 pglz_compress(const char *source, int32 slen, char *dest, const PGLZ_Strategy *strategy)
#define pglz_hist_add(_hs, _he, _hn, _recycle, _s, _e, _mask)
int32 pglz_maximum_compressed_size(int32 rawsize, int32 total_compressed_size)
static rewind_source * source
struct PGLZ_HistEntry * next
struct PGLZ_HistEntry * prev