summaryrefslogtreecommitdiffstats
path: root/lzip.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lzip.h40
1 files changed, 26 insertions, 14 deletions
diff --git a/lzip.h b/lzip.h
index 4cad6fa..4a8bc98 100644
--- a/lzip.h
+++ b/lzip.h
@@ -1,5 +1,5 @@
/* Lzip - LZMA lossless data compressor
- Copyright (C) 2008-2014 Antonio Diaz Diaz.
+ Copyright (C) 2008-2015 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -40,7 +40,7 @@ public:
enum {
min_dictionary_bits = 12,
- min_dictionary_size = 1 << min_dictionary_bits, // >= modeled_distances
+ min_dictionary_size = 1 << min_dictionary_bits, /* >= modeled_distances */
max_dictionary_bits = 29,
max_dictionary_size = 1 << max_dictionary_bits,
literal_context_bits = 3,
@@ -52,7 +52,7 @@ enum {
dis_slot_bits = 6,
start_dis_model = 4,
end_dis_model = 14,
- modeled_distances = 1 << (end_dis_model / 2), // 128
+ modeled_distances = 1 << (end_dis_model / 2), /* 128 */
dis_align_bits = 4,
dis_align_size = 1 << dis_align_bits,
@@ -64,8 +64,8 @@ enum {
len_high_symbols = 1 << len_high_bits,
max_len_symbols = len_low_symbols + len_mid_symbols + len_high_symbols,
- min_match_len = 2, // must be 2
- max_match_len = min_match_len + max_len_symbols - 1, // 273
+ min_match_len = 2, /* must be 2 */
+ max_match_len = min_match_len + max_len_symbols - 1, /* 273 */
min_match_len_limit = 5 };
inline int get_len_state( const int len )
@@ -82,7 +82,10 @@ enum { bit_model_move_bits = 5,
struct Bit_model
{
int probability;
- Bit_model() : probability( bit_model_total / 2 ) {}
+ void reset() { probability = bit_model_total / 2; }
+ void reset( const int size )
+ { for( int i = 0; i < size; ++i ) this[i].reset(); }
+ Bit_model() { reset(); }
};
struct Len_model
@@ -92,6 +95,15 @@ struct Len_model
Bit_model bm_low[pos_states][len_low_symbols];
Bit_model bm_mid[pos_states][len_mid_symbols];
Bit_model bm_high[len_high_symbols];
+
+ void reset()
+ {
+ choice1.reset();
+ choice2.reset();
+ bm_low[0][0].reset( pos_states * len_low_symbols );
+ bm_mid[0][0].reset( pos_states * len_mid_symbols );
+ bm_high[0].reset( len_high_symbols );
+ }
};
@@ -173,9 +185,9 @@ const uint8_t magic_string[4] = { 0x4C, 0x5A, 0x49, 0x50 }; // "LZIP"
struct File_header
{
- uint8_t data[6]; // 0-3 magic bytes
- // 4 version
- // 5 coded_dict_size
+ uint8_t data[6]; /* 0-3 magic bytes */
+ /* 4 version */
+ /* 5 coded_dict_size */
enum { size = 6 };
void set_magic() { std::memcpy( data, magic_string, 4 ); data[4] = 1; }
@@ -201,9 +213,9 @@ struct File_header
if( sz > min_dictionary_size )
{
const unsigned base_size = 1 << data[5];
- const unsigned wedge = base_size / 16;
+ const unsigned fraction = base_size / 16;
for( int i = 7; i >= 1; --i )
- if( base_size - ( i * wedge ) >= sz )
+ if( base_size - ( i * fraction ) >= sz )
{ data[5] |= ( i << 5 ); break; }
}
return true;
@@ -215,9 +227,9 @@ struct File_header
struct File_trailer
{
- uint8_t data[20]; // 0-3 CRC32 of the uncompressed data
- // 4-11 size of the uncompressed data
- // 12-19 member size including header and trailer
+ uint8_t data[20]; /* 0-3 CRC32 of the uncompressed data */
+ /* 4-11 size of the uncompressed data */
+ /* 12-19 member size including header and trailer */
static int size( const int version = 1 )
{ return ( ( version >= 1 ) ? 20 : 12 ); }