summaryrefslogtreecommitdiffstats
path: root/encoder.h
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 07:23:00 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 07:23:00 +0000
commit7cad15d85d55c7ad11cb25c2ec5e8cd17ecc84ee (patch)
treec998e3ce491834f84eb9b733c757d83efed25842 /encoder.h
parentAdding upstream version 1.6~pre1. (diff)
downloadlzip-7cad15d85d55c7ad11cb25c2ec5e8cd17ecc84ee.tar.xz
lzip-7cad15d85d55c7ad11cb25c2ec5e8cd17ecc84ee.zip
Adding upstream version 1.6~pre2.upstream/1.6_pre2
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'encoder.h')
-rw-r--r--encoder.h49
1 files changed, 13 insertions, 36 deletions
diff --git a/encoder.h b/encoder.h
index 59cebb8..41daa48 100644
--- a/encoder.h
+++ b/encoder.h
@@ -86,7 +86,7 @@ inline int price_symbol( const Bit_model bm[], int symbol, const int num_bits )
{
const int bit = symbol & 1;
symbol >>= 1;
- price += price_bit( bm[symbol-1], bit );
+ price += price_bit( bm[symbol], bit );
}
return price;
}
@@ -100,7 +100,7 @@ inline int price_symbol_reversed( const Bit_model bm[], int symbol,
{
const int bit = symbol & 1;
symbol >>= 1;
- price += price_bit( bm[model-1], bit );
+ price += price_bit( bm[model], bit );
model = ( model << 1 ) | bit;
}
return price;
@@ -116,14 +116,14 @@ inline int price_matched( const Bit_model bm[], const int symbol,
{
const int match_bit = ( match_byte >> i ) & 1;
const int bit = ( symbol >> i ) & 1;
- price += price_bit( bm[(match_bit<<8)+model+0xFF], bit );
+ price += price_bit( bm[(match_bit<<8)+model+0x100], bit );
model = ( model << 1 ) | bit;
if( match_bit != bit )
{
while( --i >= 0 )
{
const int bit = ( symbol >> i ) & 1;
- price += price_bit( bm[model-1], bit );
+ price += price_bit( bm[model], bit );
model = ( model << 1 ) | bit;
}
break;
@@ -143,13 +143,12 @@ class Matchfinder
long long partial_data_pos;
int dictionary_size_; // bytes to keep in buffer before pos
- const int after_size; // bytes to keep in buffer after pos
- const int buffer_size;
- uint8_t * const buffer;
+ int buffer_size;
+ uint8_t * buffer;
int pos;
int cyclic_pos;
int stream_pos; // first byte not yet read from file
- const int pos_limit; // when reached, a new block must be read
+ int pos_limit; // when reached, a new block must be read
const int ides_;
const int match_len_limit_;
int32_t * const prev_positions; // last seen position of key
@@ -159,32 +158,10 @@ class Matchfinder
bool read_block() throw();
public:
- Matchfinder( const int dict_size, const int len_limit, const int ides )
- :
- partial_data_pos( 0 ),
- dictionary_size_( dict_size ),
- after_size( max_match_len ),
- buffer_size( ( 2 * std::max( 65536, dictionary_size_ ) ) +
- max_num_trials + after_size ),
- buffer( new uint8_t[buffer_size] ),
- pos( 0 ),
- cyclic_pos( 0 ),
- stream_pos( 0 ),
- pos_limit( buffer_size - after_size ),
- ides_( ides ),
- match_len_limit_( len_limit ),
- prev_positions( new int32_t[num_prev_positions] ),
- at_stream_end( false )
- {
- if( !read_block() ) throw Error( "read error" );
- if( at_stream_end && stream_pos < dictionary_size_ )
- dictionary_size_ = std::max( min_dictionary_size, stream_pos );
- prev_pos_tree = new int32_t[2*dictionary_size_];
- for( int i = 0; i < num_prev_positions; ++i ) prev_positions[i] = -1;
- }
+ Matchfinder( const int dict_size, const int len_limit, const int ides );
~Matchfinder()
- { delete[] prev_pos_tree; delete[] prev_positions; delete[] buffer; }
+ { delete[] prev_pos_tree; delete[] prev_positions; std::free( buffer ); }
uint8_t operator[]( const int i ) const throw() { return buffer[pos+i]; }
int available_bytes() const throw() { return stream_pos - pos; }
@@ -318,7 +295,7 @@ public:
for( int i = num_bits; i > 0; --i, mask >>= 1 )
{
const int bit = ( symbol & mask );
- encode_bit( bm[model-1], bit );
+ encode_bit( bm[model], bit );
model <<= 1;
if( bit ) model |= 1;
}
@@ -330,7 +307,7 @@ public:
for( int i = num_bits; i > 0; --i )
{
const int bit = symbol & 1;
- encode_bit( bm[model-1], bit );
+ encode_bit( bm[model], bit );
model = ( model << 1 ) | bit;
symbol >>= 1;
}
@@ -343,14 +320,14 @@ public:
{
const int bit = ( symbol >> i ) & 1;
const int match_bit = ( match_byte >> i ) & 1;
- encode_bit( bm[(match_bit<<8)+model+0xFF], bit );
+ encode_bit( bm[(match_bit<<8)+model+0x100], bit );
model = ( model << 1 ) | bit;
if( match_bit != bit )
{
while( --i >= 0 )
{
const int bit = ( symbol >> i ) & 1;
- encode_bit( bm[model-1], bit );
+ encode_bit( bm[model], bit );
model = ( model << 1 ) | bit;
}
break;