Get rid of input_idx_t
authorEric Biggers <ebiggers3@gmail.com>
Sat, 5 Jul 2014 01:53:23 +0000 (20:53 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 5 Jul 2014 01:55:11 +0000 (20:55 -0500)
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/compress_common.h
include/wimlib/decompress_common.h
include/wimlib/lz.h
include/wimlib/lz_hash.h
src/compress_common.c
src/lz_hash.c
src/lzx-compress.c
src/xpress-compress.c
src/xpress-decompress.c

index d2b6310..9910d41 100644 (file)
 
 #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 {
@@ -47,7 +41,7 @@ struct output_bitstream {
        u8 *output;
 
        /* Number of bytes remaining in the @output buffer.  */
-       input_idx_t bytes_remaining;
+       u32 bytes_remaining;
 
        /* Set to true if the buffer has been exhausted.  */
        bool overrun;
@@ -57,7 +51,7 @@ extern void
 init_output_bitstream(struct output_bitstream *ostream,
                      void *data, unsigned num_bytes);
 
-extern input_idx_t
+extern u32
 flush_output_bitstream(struct output_bitstream *ostream);
 
 extern void
@@ -70,7 +64,7 @@ bitstream_put_byte(struct output_bitstream *ostream, u8 n);
 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]);
 
index d6c9089..fab3c3e 100644 (file)
 #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.
  *
@@ -39,13 +34,13 @@ struct input_bitstream {
        const u8 *data;
 
        /* Number of bytes of data that are left.  */
-       input_idx_t data_bytes_left;
+       u32 data_bytes_left;
 };
 
 /* 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;
index dfba7c2..7870c97 100644 (file)
@@ -20,8 +20,8 @@
  * 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;
+       u32 len;
+       u32 offset;
 };
 
 #endif /* _WIMLIB_LZ_H */
index 9d097ae..9a856a5 100644 (file)
@@ -19,12 +19,12 @@ typedef void (*lz_record_literal_t)(u8 lit, void *ctx);
 
 extern void
 lz_analyze_block(const u8 window[restrict],
-                input_idx_t window_size,
+                u32 window_size,
                 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  */
index bdac4ed..1653b04 100644 (file)
@@ -80,11 +80,11 @@ bitstream_put_byte(struct output_bitstream *ostream, u8 n)
  *
  * Returns -1 if the stream has overrun; otherwise returns the total number of
  * bytes in the output.  */
-input_idx_t
+u32
 flush_output_bitstream(struct output_bitstream *ostream)
 {
        if (unlikely(ostream->overrun))
-               return ~(input_idx_t)0;
+               return (u32)~0UL;
 
        *(le16*)ostream->bit_output =
                cpu_to_le16((u16)((u32)ostream->bitbuf << ostream->free_bits));
index ac469f2..af60c2e 100644 (file)
@@ -69,7 +69,7 @@ update_hash(unsigned hash, u8 c)
  * 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)
 {
@@ -106,7 +106,7 @@ insert_string(input_idx_t hash_tab[], input_idx_t prev_tab[],
  */
 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,
@@ -199,12 +199,12 @@ longest_match(const u8 window[], unsigned bytes_remaining,
  */
 void
 lz_analyze_block(const u8 window[restrict],
-                input_idx_t window_size,
+                u32 window_size,
                 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;
@@ -214,7 +214,7 @@ lz_analyze_block(const u8 window[restrict],
        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);
index fbe2556..49e1183 100644 (file)
@@ -294,9 +294,9 @@ struct lzx_codes {
 
 /* 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  */
@@ -325,16 +325,16 @@ struct lzx_block_spec {
        int block_type;
 
        /* 0-based position in the window at which this block starts.  */
-       input_idx_t window_pos;
+       u32 window_pos;
 
        /* The number of bytes of uncompressed data this block represents.  */
-       input_idx_t block_size;
+       u32 block_size;
 
        /* 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;
+       u32 num_chosen_items;
 
        /* Huffman codes for this block.  */
        struct lzx_codes codes;
@@ -363,10 +363,10 @@ struct lzx_compressor {
 
        /* 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;
+       u32 window_size;
 
        /* Allocated size of the @window.  */
-       input_idx_t max_window_size;
+       u32 max_window_size;
 
        /* Number of symbols in the main alphabet (depends on the
         * @max_window_size since it determines the maximum allowed offset).  */
@@ -397,17 +397,17 @@ struct lzx_compressor {
        struct lzx_costs costs;
 
        /* Fast algorithm only:  Array of hash table links.  */
-       input_idx_t *prev_tab;
+       u32 *prev_tab;
 
        /* 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;
+       u32 match_window_pos;
 
        /* The end-of-block position.  We can't allow any matches to span this
         * position.  */
-       input_idx_t match_window_end;
+       u32 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
@@ -453,22 +453,22 @@ struct lzx_mc_pos_data {
                        /* Position of the start of the match or literal that
                         * was taken to get to this position in the approximate
                         * minimum-cost parse.  */
-                       input_idx_t link;
+                       u32 link;
 
                        /* 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;
+                       u32 match_offset;
                } prev;
                struct {
                        /* Position at which the match or literal starting at
                         * this position ends in the minimum-cost parse.  */
-                       input_idx_t link;
+                       u32 link;
 
                        /* 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;
+                       u32 match_offset;
                } next;
        };
 
@@ -643,7 +643,7 @@ static unsigned
 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],
@@ -812,7 +812,7 @@ lzx_write_compressed_code(struct output_bitstream *out,
                          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];
@@ -2086,7 +2086,7 @@ lzx_compress(const void *uncompressed_data, size_t uncompressed_size,
 
        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;
index 228ac51..e505104 100644 (file)
@@ -41,7 +41,7 @@
 #include <string.h>
 
 struct xpress_record_ctx {
-       input_idx_t freqs[XPRESS_NUM_SYMBOLS];
+       u32 freqs[XPRESS_NUM_SYMBOLS];
        struct xpress_match *matches;
 };
 
@@ -49,7 +49,7 @@ struct xpress_compressor {
        u8 *window;
        u32 max_window_size;
        struct xpress_match *matches;
-       input_idx_t *prev_tab;
+       u32 *prev_tab;
        u32 codewords[XPRESS_NUM_SYMBOLS];
        u8 lens[XPRESS_NUM_SYMBOLS];
        struct xpress_record_ctx record_ctx;
@@ -94,11 +94,11 @@ xpress_write_match(struct xpress_match match,
 static void
 xpress_write_matches_and_literals(struct output_bitstream *ostream,
                                  const struct xpress_match matches[restrict],
-                                 input_idx_t num_matches,
+                                 u32 num_matches,
                                  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);
@@ -159,8 +159,8 @@ xpress_compress(const void *uncompressed_data, size_t uncompressed_size,
        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
@@ -214,7 +214,7 @@ xpress_compress(const void *uncompressed_data, size_t uncompressed_size,
 
        /* 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;
index 431563b..7ad4726 100644 (file)
@@ -85,8 +85,8 @@
  * 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;
@@ -135,7 +135,7 @@ xpress_lz_decode(struct input_bitstream * restrict istream,
                 unsigned uncompressed_len,
                 const u16 decode_table[restrict])
 {
-       input_idx_t curpos;
+       u32 curpos;
        unsigned match_len;
 
        for (curpos = 0; curpos < uncompressed_len; curpos += match_len) {