summaryrefslogtreecommitdiffstats
path: root/encoder.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--encoder.h111
1 files changed, 59 insertions, 52 deletions
diff --git a/encoder.h b/encoder.h
index 21c683d..75250ca 100644
--- a/encoder.h
+++ b/encoder.h
@@ -23,7 +23,7 @@ class Dis_slots
unsigned char data[1<<12];
public:
- void init() throw()
+ void init()
{
for( int slot = 0; slot < 4; ++slot ) data[slot] = slot;
for( int i = 4, size = 2, slot = 4; slot < 24; slot += 2 )
@@ -35,9 +35,9 @@ public:
}
}
- unsigned char table( const int dis ) const throw() { return data[dis]; }
+ unsigned char table( const int dis ) const { return data[dis]; }
- int operator[]( const uint32_t dis ) const throw()
+ int operator[]( const uint32_t dis ) const
{
if( dis < (1 << 12) ) return data[dis];
if( dis < (1 << 23) ) return data[dis>>11] + 22;
@@ -53,7 +53,7 @@ class Prob_prices
int data[bit_model_total >> 2];
public:
- void init() throw()
+ void init()
{
const int num_bits = ( bit_model_total_bits - 2 );
int j = 1, end = 2;
@@ -66,24 +66,24 @@ public:
}
}
- int operator[]( const int probability ) const throw()
+ int operator[]( const int probability ) const
{ return data[probability >> 2]; }
};
extern Prob_prices prob_prices;
-inline int price0( const Bit_model & bm ) throw()
+inline int price0( const Bit_model & bm )
{ return prob_prices[bm.probability]; }
-inline int price1( const Bit_model & bm ) throw()
+inline int price1( const Bit_model & bm )
{ return prob_prices[bit_model_total-bm.probability]; }
-inline int price_bit( const Bit_model & bm, const int bit ) throw()
+inline int price_bit( const Bit_model & bm, const int bit )
{ if( bit ) return price1( bm ); else return price0( bm ); }
-inline int price_symbol( const Bit_model bm[], int symbol, const int num_bits ) throw()
+inline int price_symbol( const Bit_model bm[], int symbol, const int num_bits )
{
int price = 0;
symbol |= ( 1 << num_bits );
@@ -98,7 +98,7 @@ inline int price_symbol( const Bit_model bm[], int symbol, const int num_bits )
inline int price_symbol_reversed( const Bit_model bm[], int symbol,
- const int num_bits ) throw()
+ const int num_bits )
{
int price = 0;
int model = 1;
@@ -114,7 +114,7 @@ inline int price_symbol_reversed( const Bit_model bm[], int symbol,
inline int price_matched( const Bit_model bm[], const int symbol,
- const int match_byte ) throw()
+ const int match_byte )
{
int price = 0;
int model = 1;
@@ -142,12 +142,12 @@ inline int price_matched( const Bit_model bm[], const int symbol,
class Matchfinder_base
{
- Matchfinder_base( const Matchfinder_base & ); // declared as private
- void operator=( const Matchfinder_base & ); // declared as private
-
bool read_block();
void normalize_pos();
+ Matchfinder_base( const Matchfinder_base & ); // declared as private
+ void operator=( const Matchfinder_base & ); // declared as private
+
protected:
enum { after_size = max_match_len }; // bytes to keep in buffer after pos
@@ -177,15 +177,15 @@ protected:
{ delete[] pos_array; std::free( buffer ); delete[] prev_positions; }
public:
- uint8_t operator[]( const int i ) const throw() { return buffer[pos+i]; }
- int available_bytes() const throw() { return stream_pos - pos; }
- long long data_position() const throw() { return partial_data_pos + pos; }
- int dictionary_size() const throw() { return dictionary_size_; }
- bool finished() const throw() { return at_stream_end && pos >= stream_pos; }
- int match_len_limit() const throw() { return match_len_limit_; }
- const uint8_t * ptr_to_current_pos() const throw() { return buffer + pos; }
-
- int true_match_len( const int index, const int distance, int len_limit ) const throw()
+ uint8_t operator[]( const int i ) const { return buffer[pos+i]; }
+ int available_bytes() const { return stream_pos - pos; }
+ long long data_position() const { return partial_data_pos + pos; }
+ int dictionary_size() const { return dictionary_size_; }
+ bool finished() const { return at_stream_end && pos >= stream_pos; }
+ int match_len_limit() const { return match_len_limit_; }
+ const uint8_t * ptr_to_current_pos() const { return buffer + pos; }
+
+ int true_match_len( const int index, const int distance, int len_limit ) const
{
if( index + len_limit > available_bytes() )
len_limit = available_bytes() - index;
@@ -225,8 +225,16 @@ public:
cycles( ( len_limit < max_match_len ) ? 16 + ( len_limit / 2 ) : 256 )
{}
- bool dec_pos( const int ahead ) throw();
- int longest_match_len( int * const distances = 0 ) throw();
+ bool dec_pos( const int ahead )
+ {
+ if( ahead < 0 || pos < ahead ) return false;
+ pos -= ahead;
+ cyclic_pos -= ahead;
+ if( cyclic_pos < 0 ) cyclic_pos += dictionary_size_;
+ return true;
+ }
+
+ int longest_match_len( int * const distances = 0 );
};
@@ -244,8 +252,8 @@ class Range_encoder
void shift_low()
{
- const uint32_t carry = low >> 32;
- if( low < 0xFF000000U || carry == 1 )
+ const bool carry = ( low > 0xFFFFFFFFU );
+ if( carry || low < 0xFF000000U )
{
put_byte( cache + carry );
for( ; ff_count > 0; --ff_count ) put_byte( 0xFF + carry );
@@ -255,8 +263,8 @@ class Range_encoder
low = ( low & 0x00FFFFFFU ) << 8;
}
- Range_encoder( const Range_encoder & );
- void operator=( const Range_encoder & );
+ Range_encoder( const Range_encoder & ); // declared as private
+ void operator=( const Range_encoder & ); // declared as private
public:
explicit Range_encoder( const int ofd )
@@ -268,11 +276,12 @@ public:
range( 0xFFFFFFFFU ),
ff_count( 0 ),
outfd( ofd ),
- cache( 0 ) {}
+ cache( 0 )
+ {}
~Range_encoder() { delete[] buffer; }
- long long member_position() const throw()
+ long long member_position() const
{ return partial_member_pos + pos + ff_count; }
void flush() { for( int i = 0; i < 5; ++i ) shift_low(); }
@@ -371,7 +380,7 @@ class Len_encoder
const int len_symbols;
int counters[pos_states];
- void update_prices( const int pos_state ) throw()
+ void update_prices( const int pos_state )
{
int * const pps = prices[pos_state];
int tmp = price0( choice1 );
@@ -401,7 +410,7 @@ public:
void encode( Range_encoder & range_encoder, int symbol,
const int pos_state );
- int price( const int symbol, const int pos_state ) const throw()
+ int price( const int symbol, const int pos_state ) const
{ return prices[pos_state][symbol - min_match_len]; }
};
@@ -410,7 +419,7 @@ class Literal_encoder
{
Bit_model bm_literal[1<<literal_context_bits][0x300];
- int lstate( const uint8_t prev_byte ) const throw()
+ int lstate( const uint8_t prev_byte ) const
{ return ( prev_byte >> ( 8 - literal_context_bits ) ); }
public:
@@ -423,11 +432,11 @@ public:
{ range_encoder.encode_matched( bm_literal[lstate(prev_byte)],
symbol, match_byte ); }
- int price_symbol( uint8_t prev_byte, uint8_t symbol ) const throw()
+ int price_symbol( uint8_t prev_byte, uint8_t symbol ) const
{ return ::price_symbol( bm_literal[lstate(prev_byte)], symbol, 8 ); }
int price_matched( uint8_t prev_byte, uint8_t symbol,
- uint8_t match_byte ) const throw()
+ uint8_t match_byte ) const
{ return ::price_matched( bm_literal[lstate(prev_byte)],
symbol, match_byte ); }
};
@@ -458,7 +467,7 @@ protected:
const int num_dis_slots;
- uint32_t crc() const throw() { return crc_ ^ 0xFFFFFFFFU; }
+ uint32_t crc() const { return crc_ ^ 0xFFFFFFFFU; }
LZ_encoder_base( const File_header & header, const int dictionary_size,
const int match_len_limit, const int outfd )
@@ -474,7 +483,7 @@ protected:
}
// move-to-front dis in/into reps
- void mtf_reps( const int dis, int reps[num_rep_distances] ) throw()
+ void mtf_reps( const int dis, int reps[num_rep_distances] )
{
if( dis >= num_rep_distances )
{
@@ -489,7 +498,7 @@ protected:
}
}
- void encode_pair( const uint32_t dis, const int len, const int pos_state ) throw()
+ void encode_pair( const uint32_t dis, const int len, const int pos_state )
{
len_encoder.encode( range_encoder, len, pos_state );
const int dis_slot = dis_slots[dis];
@@ -512,11 +521,10 @@ protected:
}
}
- void full_flush( const long long data_position, const State & state );
+ void full_flush( const long long data_position, const State state );
public:
- long long member_position() const throw()
- { return range_encoder.member_position(); }
+ long long member_position() const { return range_encoder.member_position(); }
};
@@ -531,7 +539,7 @@ class LZ_encoder : public LZ_encoder_base
int prev_index; // index of prev trial in trials[]
int price; // dual use var; cumulative price, match length
int reps[num_rep_distances];
- void update( const int d, const int p_i, const int pr ) throw()
+ void update( const int d, const int p_i, const int pr )
{ if( pr < price ) { dis = d; prev_index = p_i; price = pr; } }
};
@@ -545,16 +553,15 @@ class LZ_encoder : public LZ_encoder_base
int align_prices[dis_align_size];
int align_price_count;
- void fill_align_prices() throw();
- void fill_distance_prices() throw();
+ void fill_align_prices();
+ void fill_distance_prices();
- int price_rep_len1( const State & state, const int pos_state ) const throw()
+ int price_rep_len1( const int pos_state, const State state ) const
{
return price0( bm_rep0[state()] ) + price0( bm_len[state()][pos_state] );
}
- int price_rep( const int rep, const State & state,
- const int pos_state ) const throw()
+ int price_rep( const int rep, const int pos_state, const State state ) const
{
if( rep == 0 ) return price0( bm_rep0[state()] ) +
price1( bm_len[state()][pos_state] );
@@ -569,7 +576,7 @@ class LZ_encoder : public LZ_encoder_base
return price;
}
- int price_dis( const int dis, const int dis_state ) const throw()
+ int price_dis( const int dis, const int dis_state ) const
{
if( dis < modeled_distances )
return dis_prices[dis_state][dis];
@@ -578,7 +585,7 @@ class LZ_encoder : public LZ_encoder_base
align_prices[dis & (dis_align_size - 1)];
}
- int price_pair( const int dis, const int len, const int pos_state ) const throw()
+ int price_pair( const int dis, const int len, const int pos_state ) const
{
if( len <= min_match_len && dis >= modeled_distances )
return infinite_price;
@@ -586,7 +593,7 @@ class LZ_encoder : public LZ_encoder_base
price_dis( dis, get_dis_state( len ) );
}
- int read_match_distances() throw()
+ int read_match_distances()
{
int len = matchfinder.longest_match_len( match_distances );
if( len == matchfinder.match_len_limit() && len < max_match_len )
@@ -619,7 +626,7 @@ class LZ_encoder : public LZ_encoder_base
}
int sequence_optimizer( const int reps[num_rep_distances],
- const State & state );
+ const State state );
public:
LZ_encoder( Matchfinder & mf, const File_header & header, const int outfd )