static int swd_init (lzo1x_999_swd_t * s, const lzo_byte * dict, lzo_uint dict_len) { s->n = SWD_N; s->f = SWD_F; s->threshold = SWD_THRESHOLD; s->max_chain = SWD_MAX_CHAIN; s->nice_length = SWD_F; s->use_best_off = 0; s->lazy_insert = 0; s->b_size = s->n + s->f; if (2 * s->f >= s->n || s->b_size + s->f >= NIL2) return LZO_E_ERROR; s->b_wrap = s->b + s->b_size; s->node_count = s->n; memset (s->llen3, 0, sizeof (s->llen3[0]) * SWD_HSIZE); memset (s->head2, 0xff, sizeof (s->head2[0]) * 65536L); s->ip = 0; swd_initdict (s, dict, dict_len); s->bp = s->ip; s->first_rp = s->ip; s->look = (lzo_uint) (s->c->in_end - s->c->ip); if (s->look > 0) { if (s->look > s->f) s->look = s->f; memcpy (&s->b[s->ip], s->c->ip, s->look); s->c->ip += s->look; s->ip += s->look; } if (s->ip == s->b_size) s->ip = 0; if (s->look >= 2 && s->dict_len > 0) swd_insertdict (s, 0, s->dict_len); s->rp = s->first_rp; if (s->rp >= s->node_count) s->rp -= s->node_count; else s->rp += s->b_size - s->node_count; return LZO_E_OK; }
static __inline int swd_init(ucl_swd_t *s, LPBYTE dict, DWORD dict_len) { s->b = NULL; s->head3 = NULL; s->succ3 = NULL; s->best3 = NULL; s->llen3 = NULL; s->head2 = NULL; s->b = (LPBYTE) Mem::alloc(s->n + SWD_F + SWD_F); s->head3 = (LPDWORD)Mem::alloc(SWD_HSIZE * sizeof(*s->head3)); s->succ3 = (LPDWORD)Mem::alloc((s->n + SWD_F) * sizeof(*s->succ3)); s->best3 = (LPDWORD)Mem::alloc((s->n + SWD_F) * sizeof(*s->best3)); s->llen3 = (LPDWORD)Mem::alloc(SWD_HSIZE * sizeof(*s->llen3)); s->head2 = (LPDWORD)Mem::alloc(65536 * sizeof(*s->head2)); if(!s->b || !s->head3 || !s->succ3 || !s->best3 || !s->llen3 || !s->head2)return UCL::E_OUT_OF_MEMORY; /* defaults */ s->max_chain = 2048; s->nice_length = SWD_F; s->b_size = s->n + SWD_F; if(s->b_size + SWD_F >= MAXDWORD)return UCL::E_ERROR; s->b_wrap = s->b + s->b_size; s->node_count = s->n; Mem::_zero(s->llen3, sizeof(s->llen3[0]) * SWD_HSIZE); Mem::_set(s->head2, (char)0xFF, sizeof(s->head2[0]) * 65536); s->ip = 0; swd_initdict(s, dict, dict_len); s->bp = s->ip; s->first_rp = s->ip; s->look = (DWORD)(s->c->in_end - s->c->ip); if(s->look > 0) { if(s->look > SWD_F)s->look = SWD_F; Mem::_copy(&s->b[s->ip],s->c->ip,s->look); s->c->ip += s->look; s->ip += s->look; } if (s->ip == s->b_size)s->ip = 0; if (s->look >= 2 && s->dict_len > 0)swd_insertdict(s, 0, s->dict_len); s->rp = s->first_rp; if(s->rp >= s->node_count)s->rp -= s->node_count; else s->rp += s->b_size - s->node_count; return UCL::E_SUCCESSED; }
static int swd_init(struct ucl_swd *s, const uint8_t *dict, unsigned int dict_len) { unsigned int i = 0; if (s->n == 0) s->n = N; if (s->f == 0) s->f = F; s->threshold = THRESHOLD; if (s->n > N || s->f > F) return UCL_E_INVALID_ARGUMENT; /* defaults */ s->max_chain = SWD_MAX_CHAIN; s->nice_length = s->f; s->use_best_off = 0; s->lazy_insert = 0; s->b_size = s->n + s->f; if (s->b_size + s->f >= UINT_MAX) return UCL_E_ERROR; s->b_wrap = s->b + s->b_size; s->node_count = s->n; memset(s->llen3, 0, sizeof(s->llen3[0]) * SWD_HSIZE); for (i = 0; i < 65536U; i++) s->head2[i] = NIL2; s->ip = 0; swd_initdict(s,dict,dict_len); s->bp = s->ip; s->first_rp = s->ip; assert(s->ip + s->f <= s->b_size); s->look = (unsigned int) (s->c->in_end - s->c->ip); if (s->look > 0) { if (s->look > s->f) s->look = s->f; memcpy(&s->b[s->ip],s->c->ip,s->look); s->c->ip += s->look; s->ip += s->look; } if (s->ip == s->b_size) s->ip = 0; if (s->look >= 2 && s->dict_len > 0) swd_insertdict(s,0,s->dict_len); s->rp = s->first_rp; if (s->rp >= s->node_count) s->rp -= s->node_count; else s->rp += s->b_size - s->node_count; /* unused i */ /* unused c */ return UCL_E_OK; }
static int swd_init(ucl_swd_t * s, const ucl_byte * dict, ucl_uint dict_len) { ucl_uint i = 0; int c = 0; if (s->n == 0) s->n = SWD_N; if (s->f == 0) s->f = SWD_F; s->threshold = SWD_THRESHOLD; if (s->n > SWD_N || s->f > SWD_F) return UCL_E_INVALID_ARGUMENT; #if defined(SWD_USE_MALLOC) s->b = (unsigned char *) ucl_alloc(s->n + s->f + s->f, 1); s->head3 = (swd_uint *) ucl_alloc(SWD_HSIZE, sizeof(*s->head3)); s->succ3 = (swd_uint *) ucl_alloc(s->n + s->f, sizeof(*s->succ3)); s->best3 = (swd_uint *) ucl_alloc(s->n + s->f, sizeof(*s->best3)); s->llen3 = (swd_uint *) ucl_alloc(SWD_HSIZE, sizeof(*s->llen3)); if (!s->b || !s->head3 || !s->succ3 || !s->best3 || !s->llen3) return UCL_E_OUT_OF_MEMORY; #ifdef HEAD2 s->head2 = (swd_uint *) ucl_alloc(UCL_UINT32_C(65536), sizeof(*s->head2)); if (!s->head2) return UCL_E_OUT_OF_MEMORY; #endif #endif /* defaults */ s->max_chain = SWD_MAX_CHAIN; s->nice_length = s->f; s->use_best_off = 0; s->lazy_insert = 0; s->b_size = s->n + s->f; if (s->b_size + s->f >= SWD_UINT_MAX) return UCL_E_ERROR; s->b_wrap = s->b + s->b_size; s->node_count = s->n; ucl_memset(s->llen3, 0, sizeof(s->llen3[0]) * SWD_HSIZE); #ifdef HEAD2 #if 1 ucl_memset(s->head2, 0xff, sizeof(s->head2[0]) * UCL_UINT32_C(65536)); assert(s->head2[0] == NIL2); #else for (i = 0; i < UCL_UINT32_C(65536); i++) s->head2[i] = NIL2; #endif #endif s->ip = 0; swd_initdict(s, dict, dict_len); s->bp = s->ip; s->first_rp = s->ip; assert(s->ip + s->f <= s->b_size); #if 1 s->look = (ucl_uint) (s->c->in_end - s->c->ip); if (s->look > 0) { if (s->look > s->f) s->look = s->f; ucl_memcpy(&s->b[s->ip], s->c->ip, s->look); s->c->ip += s->look; s->ip += s->look; } #else s->look = 0; while (s->look < s->f) { if ((c = getbyte(*(s->c))) < 0) break; s->b[s->ip] = UCL_BYTE(c); s->ip++; s->look++; } #endif if (s->ip == s->b_size) s->ip = 0; if (s->look >= 2 && s->dict_len > 0) swd_insertdict(s, 0, s->dict_len); s->rp = s->first_rp; if (s->rp >= s->node_count) s->rp -= s->node_count; else s->rp += s->b_size - s->node_count; #if defined(__UCL_CHECKER) /* initialize memory for the first few HEAD3 (if s->ip is not far * enough ahead to do this job for us). The value doesn't matter. */ if (s->look < 3) ucl_memset(&s->b[s->bp + s->look], 0, 3); #endif UCL_UNUSED(i); UCL_UNUSED(c); return UCL_E_OK; }