+ ctx->match_window_pos = spec->window_pos;
+ ctx->cache_ptr = ctx->cached_matches;
+ memset(&freqs, 0, sizeof(freqs));
+ window_ptr = &ctx->window[spec->window_pos];
+ window_end = window_ptr + spec->block_size;
+
+ spec->chosen_items = &ctx->chosen_items[spec->window_pos];
+ next_chosen_match = spec->chosen_items;
+
+ while (window_ptr != window_end) {
+ lz_match = lzx_get_near_optimal_match(ctx);
+
+ LZX_ASSERT(!(lz_match.len == LZX_MIN_MATCH_LEN &&
+ lz_match.offset == ctx->max_window_size -
+ LZX_MIN_MATCH_LEN));
+ if (lz_match.len >= LZX_MIN_MATCH_LEN) {
+ lzx_item.data = lzx_tally_match(lz_match.len,
+ lz_match.offset,
+ &freqs, &ctx->queue);
+ window_ptr += lz_match.len;
+ } else {
+ lzx_item.data = lzx_tally_literal(*window_ptr, &freqs);
+ window_ptr += 1;
+ }
+ *next_chosen_match++ = lzx_item;
+ }
+ spec->num_chosen_items = next_chosen_match - spec->chosen_items;
+ lzx_make_huffman_codes(&freqs, &spec->codes, ctx->num_main_syms);