1 /* lzo_mchw.ch -- matching functions using a window
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer
8 The LZO library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 The LZO library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the LZO library; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
25 http://www.oberhumer.com/opensource/lzo/
29 /***********************************************************************
31 ************************************************************************/
37 lzo_uint look; /* bytes in lookahead buffer */
48 const lzo_bytep in_end;
53 lzo_uint textsize; /* text size counter */
54 lzo_uint codesize; /* code size counter */
55 lzo_uint printcount; /* counter for reporting progress every 1K bytes */
58 unsigned long lit_bytes;
59 unsigned long match_bytes;
60 unsigned long rep_bytes;
67 unsigned long r1_r, m3_r, m2_m, m3_m;
75 unsigned long r1_r, m3_r, m2_m, m3_m;
83 unsigned long r1_r, m2_m, m3_m;
86 #if defined(LZO1X) || defined(LZO1Y) || defined(LZO1Z)
91 unsigned long m1a_m, m1b_m, m2_m, m3_m, m4_m;
92 unsigned long lit1_r, lit2_r, lit3_r;
97 unsigned long m1, m2, m3, m4;
103 #define getbyte(c) ((c).ip < (c).in_end ? *((c).ip)++ : (-1))
105 #include "lzo_swd.ch"
108 /***********************************************************************
110 ************************************************************************/
113 init_match ( LZO_COMPRESS_T *c, lzo_swd_p s,
114 const lzo_bytep dict, lzo_uint dict_len,
124 c->last_m_len = c->last_m_off = 0;
126 c->textsize = c->codesize = c->printcount = 0;
127 c->lit_bytes = c->match_bytes = c->rep_bytes = 0;
130 r = swd_init(s,dict,dict_len);
137 s->use_best_off = (flags & 1) ? 1 : 0;
142 /***********************************************************************
144 ************************************************************************/
147 find_match ( LZO_COMPRESS_T *c, lzo_swd_p s,
148 lzo_uint this_len, lzo_uint skip )
154 assert(this_len >= skip);
155 swd_accept(s, this_len - skip);
156 c->textsize += this_len - skip + 1;
160 assert(this_len <= 1);
161 c->textsize += this_len - skip;
164 s->m_len = SWD_THRESHOLD;
168 lzo_memset(s->best_pos,0,sizeof(s->best_pos));
184 c->look = s->look + 1;
186 c->bp = c->ip - c->look;
189 /* brute force match search */
190 if (c->m_len > SWD_THRESHOLD && c->m_len + 1 <= c->look)
192 const lzo_bytep ip = c->bp;
193 const lzo_bytep m = c->bp - c->m_off;
194 const lzo_bytep in = c->in;
196 if (ip - in > s->swd_n)
205 if (lzo_memcmp(in,ip,c->m_len+1) == 0)
206 printf("%p %p %p %5d\n",in,ip,m,c->m_len);
212 if (c->cb && c->cb->nprogress && c->textsize > c->printcount)
214 (*c->cb->nprogress)(c->cb, c->textsize, c->codesize, 0);
215 c->printcount += 1024;