#ifndef INSERT_STRING_H_
#define INSERT_STRING_H_
#include "zmemory.h"
#ifndef HASH_CALC_OFFSET
# define HASH_CALC_OFFSET 0
#endif
#ifndef HASH_CALC_MASK
# define HASH_CALC_MASK HASH_MASK
#endif
#ifndef HASH_CALC_READ
# if BYTE_ORDER == LITTLE_ENDIAN
# define HASH_CALC_READ \
val = zng_memread_4(strstart);
# else
# define HASH_CALC_READ \
val = ZSWAP32(zng_memread_4(strstart));
# endif
#endif
Z_INTERNAL uint32_t UPDATE_HASH(uint32_t h, uint32_t val) {
HASH_CALC(h, val);
return h & HASH_CALC_MASK;
}
Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) {
uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
uint32_t val, hm;
Pos head;
HASH_CALC_VAR_INIT;
HASH_CALC_READ;
HASH_CALC(HASH_CALC_VAR, val);
HASH_CALC_VAR &= HASH_CALC_MASK;
hm = HASH_CALC_VAR;
head = s->head[hm];
if (LIKELY(head != str)) {
s->prev[str & s->w_mask] = head;
s->head[hm] = (Pos)str;
}
return head;
}
Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) {
uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
uint8_t *strend = strstart + count;
Pos *headp = s->head;
Pos *prevp = s->prev;
const unsigned int w_mask = s->w_mask;
for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) {
uint32_t val, hm;
HASH_CALC_VAR_INIT;
HASH_CALC_READ;
HASH_CALC(HASH_CALC_VAR, val);
HASH_CALC_VAR &= HASH_CALC_MASK;
hm = HASH_CALC_VAR;
Pos head = headp[hm];
if (LIKELY(head != idx)) {
prevp[idx & w_mask] = head;
headp[hm] = idx;
}
}
}
#endif