|
kusano |
7d535a |
/* lzo_dict.h -- dictionary definitions for the the LZO library
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
This file is part of the LZO real-time data compression library.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
|
|
kusano |
7d535a |
All Rights Reserved.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The LZO library is free software; you can redistribute it and/or
|
|
kusano |
7d535a |
modify it under the terms of the GNU General Public License as
|
|
kusano |
7d535a |
published by the Free Software Foundation; either version 2 of
|
|
kusano |
7d535a |
the License, or (at your option) any later version.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
The LZO library is distributed in the hope that it will be useful,
|
|
kusano |
7d535a |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
kusano |
7d535a |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
kusano |
7d535a |
GNU General Public License for more details.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
You should have received a copy of the GNU General Public License
|
|
kusano |
7d535a |
along with the LZO library; see the file COPYING.
|
|
kusano |
7d535a |
If not, write to the Free Software Foundation, Inc.,
|
|
kusano |
7d535a |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Markus F.X.J. Oberhumer
|
|
kusano |
7d535a |
<markus@oberhumer.com></markus@oberhumer.com>
|
|
kusano |
7d535a |
http://www.oberhumer.com/opensource/lzo/
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* WARNING: this file should *not* be used by applications. It is
|
|
kusano |
7d535a |
part of the implementation of the library and is subject
|
|
kusano |
7d535a |
to change.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifndef __LZO_DICT_H
|
|
kusano |
7d535a |
#define __LZO_DICT_H
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifdef __cplusplus
|
|
kusano |
7d535a |
extern "C" {
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/***********************************************************************
|
|
kusano |
7d535a |
// dictionary size
|
|
kusano |
7d535a |
************************************************************************/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* dictionary needed for compression */
|
|
kusano |
7d535a |
#if !defined(D_BITS) && defined(DBITS)
|
|
kusano |
7d535a |
# define D_BITS DBITS
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#if !defined(D_BITS)
|
|
kusano |
7d535a |
# error "D_BITS is not defined"
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#if (D_BITS < 16)
|
|
kusano |
7d535a |
# define D_SIZE LZO_SIZE(D_BITS)
|
|
kusano |
7d535a |
# define D_MASK LZO_MASK(D_BITS)
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
# define D_SIZE LZO_USIZE(D_BITS)
|
|
kusano |
7d535a |
# define D_MASK LZO_UMASK(D_BITS)
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#define D_HIGH ((D_MASK >> 1) + 1)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* dictionary depth */
|
|
kusano |
7d535a |
#if !defined(DD_BITS)
|
|
kusano |
7d535a |
# define DD_BITS 0
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#define DD_SIZE LZO_SIZE(DD_BITS)
|
|
kusano |
7d535a |
#define DD_MASK LZO_MASK(DD_BITS)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* dictionary length */
|
|
kusano |
7d535a |
#if !defined(DL_BITS)
|
|
kusano |
7d535a |
# define DL_BITS (D_BITS - DD_BITS)
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#if (DL_BITS < 16)
|
|
kusano |
7d535a |
# define DL_SIZE LZO_SIZE(DL_BITS)
|
|
kusano |
7d535a |
# define DL_MASK LZO_MASK(DL_BITS)
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
# define DL_SIZE LZO_USIZE(DL_BITS)
|
|
kusano |
7d535a |
# define DL_MASK LZO_UMASK(DL_BITS)
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if (D_BITS != DL_BITS + DD_BITS)
|
|
kusano |
7d535a |
# error "D_BITS does not match"
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#if (D_BITS < 8 || D_BITS > 18)
|
|
kusano |
7d535a |
# error "invalid D_BITS"
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#if (DL_BITS < 8 || DL_BITS > 20)
|
|
kusano |
7d535a |
# error "invalid DL_BITS"
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#if (DD_BITS < 0 || DD_BITS > 6)
|
|
kusano |
7d535a |
# error "invalid DD_BITS"
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if !defined(DL_MIN_LEN)
|
|
kusano |
7d535a |
# define DL_MIN_LEN 3
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#if !defined(DL_SHIFT)
|
|
kusano |
7d535a |
# define DL_SHIFT ((DL_BITS + (DL_MIN_LEN - 1)) / DL_MIN_LEN)
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/***********************************************************************
|
|
kusano |
7d535a |
// dictionary access
|
|
kusano |
7d535a |
************************************************************************/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#define LZO_HASH_GZIP 1
|
|
kusano |
7d535a |
#define LZO_HASH_GZIP_INCREMENTAL 2
|
|
kusano |
7d535a |
#define LZO_HASH_LZO_INCREMENTAL_A 3
|
|
kusano |
7d535a |
#define LZO_HASH_LZO_INCREMENTAL_B 4
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if !defined(LZO_HASH)
|
|
kusano |
7d535a |
# error "choose a hashing strategy"
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#undef DM
|
|
kusano |
7d535a |
#undef DX
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if (DL_MIN_LEN == 3)
|
|
kusano |
7d535a |
# define _DV2_A(p,shift1,shift2) \
|
|
kusano |
7d535a |
(((( (lzo_xint)((p)[0]) << shift1) ^ (p)[1]) << shift2) ^ (p)[2])
|
|
kusano |
7d535a |
# define _DV2_B(p,shift1,shift2) \
|
|
kusano |
7d535a |
(((( (lzo_xint)((p)[2]) << shift1) ^ (p)[1]) << shift2) ^ (p)[0])
|
|
kusano |
7d535a |
# define _DV3_B(p,shift1,shift2,shift3) \
|
|
kusano |
7d535a |
((_DV2_B((p)+1,shift1,shift2) << (shift3)) ^ (p)[0])
|
|
kusano |
7d535a |
#elif (DL_MIN_LEN == 2)
|
|
kusano |
7d535a |
# define _DV2_A(p,shift1,shift2) \
|
|
kusano |
7d535a |
(( (lzo_xint)(p[0]) << shift1) ^ p[1])
|
|
kusano |
7d535a |
# define _DV2_B(p,shift1,shift2) \
|
|
kusano |
7d535a |
(( (lzo_xint)(p[1]) << shift1) ^ p[2])
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
# error "invalid DL_MIN_LEN"
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#define _DV_A(p,shift) _DV2_A(p,shift,shift)
|
|
kusano |
7d535a |
#define _DV_B(p,shift) _DV2_B(p,shift,shift)
|
|
kusano |
7d535a |
#define DA2(p,s1,s2) \
|
|
kusano |
7d535a |
(((((lzo_xint)((p)[2]) << (s2)) + (p)[1]) << (s1)) + (p)[0])
|
|
kusano |
7d535a |
#define DS2(p,s1,s2) \
|
|
kusano |
7d535a |
(((((lzo_xint)((p)[2]) << (s2)) - (p)[1]) << (s1)) - (p)[0])
|
|
kusano |
7d535a |
#define DX2(p,s1,s2) \
|
|
kusano |
7d535a |
(((((lzo_xint)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0])
|
|
kusano |
7d535a |
#define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0])
|
|
kusano |
7d535a |
#define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0])
|
|
kusano |
7d535a |
#define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0])
|
|
kusano |
7d535a |
#define DMS(v,s) ((lzo_uint) (((v) & (D_MASK >> (s))) << (s)))
|
|
kusano |
7d535a |
#define DM(v) DMS(v,0)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if (LZO_HASH == LZO_HASH_GZIP)
|
|
kusano |
7d535a |
/* hash function like in gzip/zlib (deflate) */
|
|
kusano |
7d535a |
# define _DINDEX(dv,p) (_DV_A((p),DL_SHIFT))
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#elif (LZO_HASH == LZO_HASH_GZIP_INCREMENTAL)
|
|
kusano |
7d535a |
/* incremental hash like in gzip/zlib (deflate) */
|
|
kusano |
7d535a |
# define __LZO_HASH_INCREMENTAL
|
|
kusano |
7d535a |
# define DVAL_FIRST(dv,p) dv = _DV_A((p),DL_SHIFT)
|
|
kusano |
7d535a |
# define DVAL_NEXT(dv,p) dv = (((dv) << DL_SHIFT) ^ p[2])
|
|
kusano |
7d535a |
# define _DINDEX(dv,p) (dv)
|
|
kusano |
7d535a |
# define DVAL_LOOKAHEAD DL_MIN_LEN
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_A)
|
|
kusano |
7d535a |
/* incremental LZO hash version A */
|
|
kusano |
7d535a |
# define __LZO_HASH_INCREMENTAL
|
|
kusano |
7d535a |
# define DVAL_FIRST(dv,p) dv = _DV_A((p),5)
|
|
kusano |
7d535a |
# define DVAL_NEXT(dv,p) \
|
|
kusano |
7d535a |
dv ^= (lzo_xint)(p[-1]) << (2*5); dv = (((dv) << 5) ^ p[2])
|
|
kusano |
7d535a |
# define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5)
|
|
kusano |
7d535a |
# define DVAL_LOOKAHEAD DL_MIN_LEN
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_B)
|
|
kusano |
7d535a |
/* incremental LZO hash version B */
|
|
kusano |
7d535a |
# define __LZO_HASH_INCREMENTAL
|
|
kusano |
7d535a |
# define DVAL_FIRST(dv,p) dv = _DV_B((p),5)
|
|
kusano |
7d535a |
# define DVAL_NEXT(dv,p) \
|
|
kusano |
7d535a |
dv ^= p[-1]; dv = (((dv) >> 5) ^ ((lzo_xint)(p[2]) << (2*5)))
|
|
kusano |
7d535a |
# define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5)
|
|
kusano |
7d535a |
# define DVAL_LOOKAHEAD DL_MIN_LEN
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
# error "choose a hashing strategy"
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifndef DINDEX
|
|
kusano |
7d535a |
#define DINDEX(dv,p) ((lzo_uint)((_DINDEX(dv,p)) & DL_MASK) << DD_BITS)
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#if !defined(DINDEX1) && defined(D_INDEX1)
|
|
kusano |
7d535a |
#define DINDEX1 D_INDEX1
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#if !defined(DINDEX2) && defined(D_INDEX2)
|
|
kusano |
7d535a |
#define DINDEX2 D_INDEX2
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if !defined(__LZO_HASH_INCREMENTAL)
|
|
kusano |
7d535a |
# define DVAL_FIRST(dv,p) ((void) 0)
|
|
kusano |
7d535a |
# define DVAL_NEXT(dv,p) ((void) 0)
|
|
kusano |
7d535a |
# define DVAL_LOOKAHEAD 0
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if !defined(DVAL_ASSERT)
|
|
kusano |
7d535a |
#if defined(__LZO_HASH_INCREMENTAL) && !defined(NDEBUG)
|
|
kusano |
7d535a |
static void DVAL_ASSERT(lzo_xint dv, const lzo_bytep p)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
lzo_xint df;
|
|
kusano |
7d535a |
DVAL_FIRST(df,(p));
|
|
kusano |
7d535a |
assert(DINDEX(dv,p) == DINDEX(df,p));
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
# define DVAL_ASSERT(dv,p) ((void) 0)
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/***********************************************************************
|
|
kusano |
7d535a |
// dictionary updating
|
|
kusano |
7d535a |
************************************************************************/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if defined(LZO_DICT_USE_PTR)
|
|
kusano |
7d535a |
# define DENTRY(p,in) (p)
|
|
kusano |
7d535a |
# define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex]
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
# define DENTRY(p,in) ((lzo_uint) ((p)-(in)))
|
|
kusano |
7d535a |
# define GINDEX(m_pos,m_off,dict,dindex,in) m_off = dict[dindex]
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if (DD_BITS == 0)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
# define UPDATE_D(dict,drun,dv,p,in) dict[ DINDEX(dv,p) ] = DENTRY(p,in)
|
|
kusano |
7d535a |
# define UPDATE_I(dict,drun,index,p,in) dict[index] = DENTRY(p,in)
|
|
kusano |
7d535a |
# define UPDATE_P(ptr,drun,p,in) (ptr)[0] = DENTRY(p,in)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
# define UPDATE_D(dict,drun,dv,p,in) \
|
|
kusano |
7d535a |
dict[ DINDEX(dv,p) + drun++ ] = DENTRY(p,in); drun &= DD_MASK
|
|
kusano |
7d535a |
# define UPDATE_I(dict,drun,index,p,in) \
|
|
kusano |
7d535a |
dict[ (index) + drun++ ] = DENTRY(p,in); drun &= DD_MASK
|
|
kusano |
7d535a |
# define UPDATE_P(ptr,drun,p,in) \
|
|
kusano |
7d535a |
(ptr) [ drun++ ] = DENTRY(p,in); drun &= DD_MASK
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/***********************************************************************
|
|
kusano |
7d535a |
// test for a match
|
|
kusano |
7d535a |
************************************************************************/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if defined(LZO_DICT_USE_PTR)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* m_pos is either NULL or a valid pointer */
|
|
kusano |
7d535a |
#define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
|
|
kusano |
7d535a |
(m_pos == NULL || (m_off = pd(ip, m_pos)) > max_offset)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* m_pos may point anywhere... */
|
|
kusano |
7d535a |
#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
|
|
kusano |
7d535a |
(BOUNDS_CHECKING_OFF_IN_EXPR(( \
|
|
kusano |
7d535a |
m_pos = ip - (lzo_uint) PTR_DIFF(ip,m_pos), \
|
|
kusano |
7d535a |
PTR_LT(m_pos,in) || \
|
|
kusano |
7d535a |
(m_off = (lzo_uint) PTR_DIFF(ip,m_pos)) <= 0 || \
|
|
kusano |
7d535a |
m_off > max_offset )))
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
|
|
kusano |
7d535a |
(m_off == 0 || \
|
|
kusano |
7d535a |
((m_off = pd(ip, in) - m_off) > max_offset) || \
|
|
kusano |
7d535a |
(m_pos = (ip) - (m_off), 0) )
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
|
|
kusano |
7d535a |
(pd(ip, in) <= m_off || \
|
|
kusano |
7d535a |
((m_off = pd(ip, in) - m_off) > max_offset) || \
|
|
kusano |
7d535a |
(m_pos = (ip) - (m_off), 0) )
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if defined(LZO_DETERMINISTIC)
|
|
kusano |
7d535a |
# define LZO_CHECK_MPOS LZO_CHECK_MPOS_DET
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
# define LZO_CHECK_MPOS LZO_CHECK_MPOS_NON_DET
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifdef __cplusplus
|
|
kusano |
7d535a |
} /* extern "C" */
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#endif /* already included */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
vi:ts=4:et
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|