This can't simply be changed anymore, so there's not much point in having
it. For now window sizes are fixed at 32 bits.
#include "wimlib/types.h"
#include "wimlib/types.h"
-/* Variable type that can represent all possible window positions. */
-#ifndef INPUT_IDX_T_DEFINED
-#define INPUT_IDX_T_DEFINED
-typedef u32 input_idx_t;
-#endif
-
/* Structure to keep track of the current state sending bits and bytes to the
* compressed output buffer. */
struct output_bitstream {
/* Structure to keep track of the current state sending bits and bytes to the
* compressed output buffer. */
struct output_bitstream {
u8 *output;
/* Number of bytes remaining in the @output buffer. */
u8 *output;
/* Number of bytes remaining in the @output buffer. */
- input_idx_t bytes_remaining;
/* Set to true if the buffer has been exhausted. */
bool overrun;
/* Set to true if the buffer has been exhausted. */
bool overrun;
init_output_bitstream(struct output_bitstream *ostream,
void *data, unsigned num_bytes);
init_output_bitstream(struct output_bitstream *ostream,
void *data, unsigned num_bytes);
flush_output_bitstream(struct output_bitstream *ostream);
extern void
flush_output_bitstream(struct output_bitstream *ostream);
extern void
extern void
make_canonical_huffman_code(unsigned num_syms,
unsigned max_codeword_len,
extern void
make_canonical_huffman_code(unsigned num_syms,
unsigned max_codeword_len,
- const input_idx_t freq_tab[restrict],
+ const u32 freq_tab[restrict],
u8 lens[restrict],
u32 codewords[restrict]);
u8 lens[restrict],
u32 codewords[restrict]);
#include "wimlib/endianness.h"
#include "wimlib/types.h"
#include "wimlib/endianness.h"
#include "wimlib/types.h"
-#ifndef INPUT_IDX_T_DEFINED
-#define INPUT_IDX_T_DEFINED
-typedef u32 input_idx_t;
-#endif
-
/* Structure to encapsulate a block of in-memory data that is being interpreted
* as a stream of bits.
*
/* Structure to encapsulate a block of in-memory data that is being interpreted
* as a stream of bits.
*
const u8 *data;
/* Number of bytes of data that are left. */
const u8 *data;
/* Number of bytes of data that are left. */
- input_idx_t data_bytes_left;
};
/* Initializes a bitstream to receive its input from @data. */
static inline void
init_input_bitstream(struct input_bitstream *istream,
};
/* Initializes a bitstream to receive its input from @data. */
static inline void
init_input_bitstream(struct input_bitstream *istream,
- const void *data, input_idx_t num_data_bytes)
+ const void *data, u32 num_data_bytes)
{
istream->bitbuf = 0;
istream->bitsleft = 0;
{
istream->bitbuf = 0;
istream->bitsleft = 0;
* This can alternatively be used to represent a literal byte if @len is less
* than the minimum match length. */
struct lz_match {
* This can alternatively be used to represent a literal byte if @len is less
* than the minimum match length. */
struct lz_match {
- input_idx_t len;
- input_idx_t offset;
};
#endif /* _WIMLIB_LZ_H */
};
#endif /* _WIMLIB_LZ_H */
extern void
lz_analyze_block(const u8 window[restrict],
extern void
lz_analyze_block(const u8 window[restrict],
- input_idx_t window_size,
lz_record_match_t record_match,
lz_record_literal_t record_literal,
void *record_ctx,
const struct lz_params *params,
lz_record_match_t record_match,
lz_record_literal_t record_literal,
void *record_ctx,
const struct lz_params *params,
- input_idx_t prev_tab[restrict]);
+ u32 prev_tab[restrict]);
#endif /* _WIMLIB_LZ_HASH_H */
#endif /* _WIMLIB_LZ_HASH_H */
*
* Returns -1 if the stream has overrun; otherwise returns the total number of
* bytes in the output. */
*
* Returns -1 if the stream has overrun; otherwise returns the total number of
* bytes in the output. */
flush_output_bitstream(struct output_bitstream *ostream)
{
if (unlikely(ostream->overrun))
flush_output_bitstream(struct output_bitstream *ostream)
{
if (unlikely(ostream->overrun))
- return ~(input_idx_t)0;
*(le16*)ostream->bit_output =
cpu_to_le16((u16)((u32)ostream->bitbuf << ostream->free_bits));
*(le16*)ostream->bit_output =
cpu_to_le16((u16)((u32)ostream->bitbuf << ostream->free_bits));
* indicating the end of the hash chain.
*/
static inline unsigned
* indicating the end of the hash chain.
*/
static inline unsigned
-insert_string(input_idx_t hash_tab[], input_idx_t prev_tab[],
+insert_string(u32 hash_tab[], u32 prev_tab[],
const u8 window[], unsigned str_pos,
unsigned hash)
{
const u8 window[], unsigned str_pos,
unsigned hash)
{
*/
static unsigned
longest_match(const u8 window[], unsigned bytes_remaining,
*/
static unsigned
longest_match(const u8 window[], unsigned bytes_remaining,
- unsigned strstart, const input_idx_t prev_tab[],
+ unsigned strstart, const u32 prev_tab[],
unsigned cur_match, unsigned prev_len,
unsigned *match_start_ret,
const struct lz_params *params,
unsigned cur_match, unsigned prev_len,
unsigned *match_start_ret,
const struct lz_params *params,
*/
void
lz_analyze_block(const u8 window[restrict],
*/
void
lz_analyze_block(const u8 window[restrict],
- input_idx_t window_size,
lz_record_match_t record_match,
lz_record_literal_t record_literal,
void *record_ctx,
const struct lz_params *params,
lz_record_match_t record_match,
lz_record_literal_t record_literal,
void *record_ctx,
const struct lz_params *params,
- input_idx_t prev_tab[restrict])
+ u32 prev_tab[restrict])
{
unsigned cur_input_pos = 0;
unsigned hash = 0;
{
unsigned cur_input_pos = 0;
unsigned hash = 0;
unsigned match_len = params->min_match - 1;
unsigned match_start = 0;
bool match_available = false;
unsigned match_len = params->min_match - 1;
unsigned match_start = 0;
bool match_available = false;
- input_idx_t hash_tab[HASH_SIZE];
+ u32 hash_tab[HASH_SIZE];
unsigned min_start_pos = 1;
ZERO_ARRAY(hash_tab);
unsigned min_start_pos = 1;
ZERO_ARRAY(hash_tab);
/* Tables for tallying symbol frequencies in the three LZX alphabets */
struct lzx_freqs {
/* Tables for tallying symbol frequencies in the three LZX alphabets */
struct lzx_freqs {
- input_idx_t main[LZX_MAINCODE_MAX_NUM_SYMBOLS];
- input_idx_t len[LZX_LENCODE_NUM_SYMBOLS];
- input_idx_t aligned[LZX_ALIGNEDCODE_NUM_SYMBOLS];
+ u32 main[LZX_MAINCODE_MAX_NUM_SYMBOLS];
+ u32 len[LZX_LENCODE_NUM_SYMBOLS];
+ u32 aligned[LZX_ALIGNEDCODE_NUM_SYMBOLS];
};
/* LZX intermediate match/literal format */
};
/* LZX intermediate match/literal format */
int block_type;
/* 0-based position in the window at which this block starts. */
int block_type;
/* 0-based position in the window at which this block starts. */
- input_idx_t window_pos;
/* The number of bytes of uncompressed data this block represents. */
/* The number of bytes of uncompressed data this block represents. */
- input_idx_t block_size;
/* The match/literal sequence for this block. */
struct lzx_item *chosen_items;
/* The length of the @chosen_items sequence. */
/* The match/literal sequence for this block. */
struct lzx_item *chosen_items;
/* The length of the @chosen_items sequence. */
- input_idx_t num_chosen_items;
/* Huffman codes for this block. */
struct lzx_codes codes;
/* Huffman codes for this block. */
struct lzx_codes codes;
/* Number of bytes of data to be compressed, which is the number of
* bytes of data in @window that are actually valid. */
/* Number of bytes of data to be compressed, which is the number of
* bytes of data in @window that are actually valid. */
- input_idx_t window_size;
/* Allocated size of the @window. */
/* Allocated size of the @window. */
- input_idx_t max_window_size;
/* Number of symbols in the main alphabet (depends on the
* @max_window_size since it determines the maximum allowed offset). */
/* Number of symbols in the main alphabet (depends on the
* @max_window_size since it determines the maximum allowed offset). */
struct lzx_costs costs;
/* Fast algorithm only: Array of hash table links. */
struct lzx_costs costs;
/* Fast algorithm only: Array of hash table links. */
/* Slow algorithm only: Binary tree match-finder. */
struct lz_bt mf;
/* Position in window of next match to return. */
/* Slow algorithm only: Binary tree match-finder. */
struct lz_bt mf;
/* Position in window of next match to return. */
- input_idx_t match_window_pos;
/* The end-of-block position. We can't allow any matches to span this
* position. */
/* The end-of-block position. We can't allow any matches to span this
* position. */
- input_idx_t match_window_end;
/* Matches found by the match-finder are cached in the following array
* to achieve a slight speedup when the same matches are needed on
/* Matches found by the match-finder are cached in the following array
* to achieve a slight speedup when the same matches are needed on
/* Position of the start of the match or literal that
* was taken to get to this position in the approximate
* minimum-cost parse. */
/* Position of the start of the match or literal that
* was taken to get to this position in the approximate
* minimum-cost parse. */
/* Offset (as in an LZ (length, offset) pair) of the
* match or literal that was taken to get to this
* position in the approximate minimum-cost parse. */
/* Offset (as in an LZ (length, offset) pair) of the
* match or literal that was taken to get to this
* position in the approximate minimum-cost parse. */
- input_idx_t match_offset;
} prev;
struct {
/* Position at which the match or literal starting at
* this position ends in the minimum-cost parse. */
} prev;
struct {
/* Position at which the match or literal starting at
* this position ends in the minimum-cost parse. */
/* Offset (as in an LZ (length, offset) pair) of the
* match or literal starting at this position in the
* approximate minimum-cost parse. */
/* Offset (as in an LZ (length, offset) pair) of the
* match or literal starting at this position in the
* approximate minimum-cost parse. */
- input_idx_t match_offset;
lzx_build_precode(const u8 lens[restrict],
const u8 prev_lens[restrict],
const unsigned num_syms,
lzx_build_precode(const u8 lens[restrict],
const u8 prev_lens[restrict],
const unsigned num_syms,
- input_idx_t precode_freqs[restrict LZX_PRECODE_NUM_SYMBOLS],
+ u32 precode_freqs[restrict LZX_PRECODE_NUM_SYMBOLS],
u8 output_syms[restrict num_syms],
u8 precode_lens[restrict LZX_PRECODE_NUM_SYMBOLS],
u32 precode_codewords[restrict LZX_PRECODE_NUM_SYMBOLS],
u8 output_syms[restrict num_syms],
u8 precode_lens[restrict LZX_PRECODE_NUM_SYMBOLS],
u32 precode_codewords[restrict LZX_PRECODE_NUM_SYMBOLS],
const u8 prev_lens[restrict],
unsigned num_syms)
{
const u8 prev_lens[restrict],
unsigned num_syms)
{
- input_idx_t precode_freqs[LZX_PRECODE_NUM_SYMBOLS];
+ u32 precode_freqs[LZX_PRECODE_NUM_SYMBOLS];
u8 output_syms[num_syms];
u8 precode_lens[LZX_PRECODE_NUM_SYMBOLS];
u32 precode_codewords[LZX_PRECODE_NUM_SYMBOLS];
u8 output_syms[num_syms];
u8 precode_lens[LZX_PRECODE_NUM_SYMBOLS];
u32 precode_codewords[LZX_PRECODE_NUM_SYMBOLS];
LZX_DEBUG("Flushing bitstream...");
compressed_size = flush_output_bitstream(&ostream);
LZX_DEBUG("Flushing bitstream...");
compressed_size = flush_output_bitstream(&ostream);
- if (compressed_size == ~(input_idx_t)0) {
+ if (compressed_size == (u32)~0UL) {
LZX_DEBUG("Data did not compress to %zu bytes or less!",
compressed_size_avail);
return 0;
LZX_DEBUG("Data did not compress to %zu bytes or less!",
compressed_size_avail);
return 0;
#include <string.h>
struct xpress_record_ctx {
#include <string.h>
struct xpress_record_ctx {
- input_idx_t freqs[XPRESS_NUM_SYMBOLS];
+ u32 freqs[XPRESS_NUM_SYMBOLS];
struct xpress_match *matches;
};
struct xpress_match *matches;
};
u8 *window;
u32 max_window_size;
struct xpress_match *matches;
u8 *window;
u32 max_window_size;
struct xpress_match *matches;
u32 codewords[XPRESS_NUM_SYMBOLS];
u8 lens[XPRESS_NUM_SYMBOLS];
struct xpress_record_ctx record_ctx;
u32 codewords[XPRESS_NUM_SYMBOLS];
u8 lens[XPRESS_NUM_SYMBOLS];
struct xpress_record_ctx record_ctx;
static void
xpress_write_matches_and_literals(struct output_bitstream *ostream,
const struct xpress_match matches[restrict],
static void
xpress_write_matches_and_literals(struct output_bitstream *ostream,
const struct xpress_match matches[restrict],
- input_idx_t num_matches,
const u32 codewords[restrict],
const u8 lens[restrict])
{
const u32 codewords[restrict],
const u8 lens[restrict])
{
- for (input_idx_t i = 0; i < num_matches; i++) {
+ for (u32 i = 0; i < num_matches; i++) {
if (matches[i].offset) {
/* Real match */
xpress_write_match(matches[i], ostream, codewords, lens);
if (matches[i].offset) {
/* Real match */
xpress_write_match(matches[i], ostream, codewords, lens);
struct xpress_compressor *c = _c;
u8 *cptr = compressed_data;
struct output_bitstream ostream;
struct xpress_compressor *c = _c;
u8 *cptr = compressed_data;
struct output_bitstream ostream;
- input_idx_t num_matches;
- input_idx_t i;
+ u32 num_matches;
+ u32 i;
size_t compressed_size;
/* XPRESS requires 256 bytes of overhead for the Huffman code, so it's
size_t compressed_size;
/* XPRESS requires 256 bytes of overhead for the Huffman code, so it's
/* Flush any pending data and get the length of the compressed data. */
compressed_size = flush_output_bitstream(&ostream);
/* Flush any pending data and get the length of the compressed data. */
compressed_size = flush_output_bitstream(&ostream);
- if (compressed_size == ~(input_idx_t)0)
+ if (compressed_size == (u32)~0UL)
return 0;
compressed_size += XPRESS_NUM_SYMBOLS / 2;
return 0;
compressed_size += XPRESS_NUM_SYMBOLS / 2;
* Returns the match length, or -1 if the data is invalid.
*/
static int
* Returns the match length, or -1 if the data is invalid.
*/
static int
-xpress_decode_match(unsigned sym, input_idx_t window_pos,
- input_idx_t window_len, u8 window[restrict],
+xpress_decode_match(unsigned sym, u32 window_pos,
+ u32 window_len, u8 window[restrict],
struct input_bitstream * restrict istream)
{
unsigned len_hdr;
struct input_bitstream * restrict istream)
{
unsigned len_hdr;
unsigned uncompressed_len,
const u16 decode_table[restrict])
{
unsigned uncompressed_len,
const u16 decode_table[restrict])
{
unsigned match_len;
for (curpos = 0; curpos < uncompressed_len; curpos += match_len) {
unsigned match_len;
for (curpos = 0; curpos < uncompressed_len; curpos += match_len) {