1 /* lzo1b_sm.ch -- implementation of the LZO1B compression algorithm
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer
6 Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer
7 Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer
8 Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
9 Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
10 Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
11 Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
12 Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
13 Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
14 Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
15 Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
16 Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
17 Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
18 Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
19 Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
20 Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
23 The LZO library is free software; you can redistribute it and/or
24 modify it under the terms of the GNU General Public License as
25 published by the Free Software Foundation; either version 2 of
26 the License, or (at your option) any later version.
28 The LZO library is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with the LZO library; see the file COPYING.
35 If not, write to the Free Software Foundation, Inc.,
36 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
38 Markus F.X.J. Oberhumer
39 <markus@oberhumer.com>
40 http://www.oberhumer.com/opensource/lzo/
44 /* WARNING: this file should *not* be used by applications. It is
45 part of the implementation of the library and is subject
51 /***********************************************************************
53 ************************************************************************/
57 /* search ip in the dictionary */
59 GINDEX(m_pos,m_off,dict,dindex,in);
60 if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M3_MAX_OFFSET))
63 if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
67 GINDEX(m_pos,m_off,dict,dindex,in);
68 if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M3_MAX_OFFSET))
70 if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
75 #else /* (DD_BITS == 0) */
79 /* search ip in the deepened dictionary */
81 lzo_dict_p d = &dict [ DINDEX(dv,ip) ];
82 const lzo_bytep ip_sav;
85 LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, x_off, 0);
93 const lzo_bytep z_pos = NULL;
95 #if (LZO_DICT_USE_PTR)
97 assert((z_pos = m_pos) == *d);
98 #if (LZO_DETERMINISTIC)
99 assert(m_pos == NULL || m_pos >= in);
100 assert(m_pos == NULL || m_pos < ip);
105 assert(ip == ip_sav);
107 if (LZO_CHECK_MPOS(m_pos,x_off,in,ip,MAX_OFFSET))
113 else if (m_pos[m_len] != ip[m_len])
115 else if (*m_pos++ == *ip++ && *m_pos++ == *ip++ && *m_pos++ == *ip++)
117 #if !(LZO_DICT_USE_PTR)
118 assert((z_pos = ip - 3 - x_off) == (m_pos - 3));
123 x_len = pd((ip - 1), ip_sav);
128 assert((m_pos_sav = z_pos) != NULL);
131 /* try to find a closer match */
132 else if (x_len == m_len && x_off < m_off)
135 assert((m_pos_sav = z_pos) != NULL);
141 assert((ip - ip_sav) == M2_MAX_LEN + 1);
143 #if defined(MATCH_IP_END)
147 while (ip < end && *m_pos == *ip)
149 assert(ip <= in_end);
150 x_len = pd(ip, ip_sav);
156 assert((m_pos_sav = z_pos) != NULL);
157 if (ip >= MATCH_IP_END)
161 /* not needed - we are at the end */
163 assert(d == &dict [ DINDEX(dv,ip) ]);
164 UPDATE_P(d,drun,ip,in);
169 else if (x_len == m_len && x_off < m_off)
172 assert((m_pos_sav = z_pos) != NULL);
175 /* try to find a closer match */
176 if (m_len < M2_MAX_LEN + 1 || x_off < m_off)
178 m_len = M2_MAX_LEN + 1;
180 assert((m_pos_sav = z_pos) != NULL);
184 /* don't search for a longer/closer match */
185 m_len = M2_MAX_LEN + 1;
187 assert((m_pos_sav = z_pos) != NULL);
190 assert(d == &dict [ DINDEX(dv,ip) ]);
191 UPDATE_P(d,drun,ip,in);
201 assert(ip == ip_sav);
204 assert(d == &dict [ DINDEX(dv,ip) ]);
205 UPDATE_P(d,drun,ip,in);
208 #endif /* (DD_BITS == 0) */