Class: Omnizip::Algorithms::LZMA::LengthEncoder
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::LZMA::LengthEncoder
- Includes:
- Constants
- Defined in:
- lib/omnizip/algorithms/lzma/xz_probability_models.rb
Overview
Length encoder with probability models and price tables
Encodes match lengths using a 3-tier structure:
- Low: lengths 2-9 (choice=0, 3 bits)
- Mid: lengths 10-17 (choice=1, choice2=0, 3 bits)
- High: lengths 18-273 (choice=1, choice2=1, 8 bits)
Constant Summary
Constants included from Constants
Constants::BIT_MODEL_TOTAL, Constants::COMPRESSION_LEVEL_DEFAULT, Constants::COMPRESSION_LEVEL_MAX, Constants::COMPRESSION_LEVEL_MIN, Constants::DICT_SIZE_MAX, Constants::DICT_SIZE_MIN, Constants::DIST_ALIGN_BITS, Constants::DIST_ALIGN_SIZE, Constants::DIST_SLOT_FAST_LIMIT, Constants::END_POS_MODEL_INDEX, Constants::EOS_MARKER, Constants::INIT_PROBS, Constants::LEN_HIGH_SYMBOLS, Constants::LEN_LOW_SYMBOLS, Constants::LEN_MID_SYMBOLS, Constants::LIT_SIZE_MAX, Constants::MATCH_LEN_MAX, Constants::MATCH_LEN_MIN, Constants::MOVE_BITS, Constants::NUM_DIRECT_BITS, Constants::NUM_DIST_SLOTS, Constants::NUM_DIST_SLOT_BITS, Constants::NUM_FULL_DISTANCES, Constants::NUM_LEN_HIGH_BITS, Constants::NUM_LEN_LOW_BITS, Constants::NUM_LEN_MID_BITS, Constants::NUM_LEN_TO_POS_STATES, Constants::NUM_LIT_CONTEXT_BITS_MAX, Constants::NUM_LIT_POS_BITS_MAX, Constants::NUM_POS_BITS_MAX, Constants::NUM_STATES, Constants::POS_STATES_MAX, Constants::START_POS_MODEL_INDEX, Constants::TOP
Instance Attribute Summary collapse
-
#choice ⇒ Object
readonly
Returns the value of attribute choice.
-
#choice2 ⇒ Object
readonly
Returns the value of attribute choice2.
-
#counters ⇒ Object
readonly
Returns the value of attribute counters.
-
#high ⇒ Object
readonly
Returns the value of attribute high.
-
#low ⇒ Object
readonly
Returns the value of attribute low.
-
#mid ⇒ Object
readonly
Returns the value of attribute mid.
-
#prices ⇒ Object
readonly
Returns the value of attribute prices.
Instance Method Summary collapse
-
#decrement_counter(pos_state) ⇒ Boolean
Decrement counter for position state.
-
#get_price(pos_state, length) ⇒ Integer
Get price for encoding length at position state.
-
#initialize(pb) ⇒ LengthEncoder
constructor
Initialize length encoder.
-
#reset ⇒ Object
Reset all models to initial state.
-
#reset_counter(pos_state, value) ⇒ Object
Reset counter for position state.
-
#set_price(pos_state, length, price) ⇒ Object
Set price for length at position state.
Constructor Details
#initialize(pb) ⇒ LengthEncoder
Initialize length encoder
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/omnizip/algorithms/lzma/xz_probability_models.rb', line 169 def initialize(pb) @pb = pb @num_pos_states = 1 << pb # Choice bits @choice = XzBufferedRangeEncoder::Probability.new @choice2 = XzBufferedRangeEncoder::Probability.new # Low lengths (per position state) @low = Array.new(@num_pos_states) do Array.new(LEN_LOW_SYMBOLS) { XzBufferedRangeEncoder::Probability.new } end # Mid lengths (per position state) @mid = Array.new(@num_pos_states) do Array.new(LEN_MID_SYMBOLS) { XzBufferedRangeEncoder::Probability.new } end # High lengths (shared across position states) @high = Array.new(LEN_HIGH_SYMBOLS) { XzBufferedRangeEncoder::Probability.new } # Price tables (updated incrementally) # prices[pos_state][length - MATCH_LEN_MIN] @prices = Array.new(@num_pos_states) do Array.new(MATCH_LEN_MAX - MATCH_LEN_MIN + 1, 0) end # Counters for price table updates @counters = Array.new(@num_pos_states, 0) end |
Instance Attribute Details
#choice ⇒ Object (readonly)
Returns the value of attribute choice.
164 165 166 |
# File 'lib/omnizip/algorithms/lzma/xz_probability_models.rb', line 164 def choice @choice end |
#choice2 ⇒ Object (readonly)
Returns the value of attribute choice2.
164 165 166 |
# File 'lib/omnizip/algorithms/lzma/xz_probability_models.rb', line 164 def choice2 @choice2 end |
#counters ⇒ Object (readonly)
Returns the value of attribute counters.
164 165 166 |
# File 'lib/omnizip/algorithms/lzma/xz_probability_models.rb', line 164 def counters @counters end |
#high ⇒ Object (readonly)
Returns the value of attribute high.
164 165 166 |
# File 'lib/omnizip/algorithms/lzma/xz_probability_models.rb', line 164 def high @high end |
#low ⇒ Object (readonly)
Returns the value of attribute low.
164 165 166 |
# File 'lib/omnizip/algorithms/lzma/xz_probability_models.rb', line 164 def low @low end |
#mid ⇒ Object (readonly)
Returns the value of attribute mid.
164 165 166 |
# File 'lib/omnizip/algorithms/lzma/xz_probability_models.rb', line 164 def mid @mid end |
#prices ⇒ Object (readonly)
Returns the value of attribute prices.
164 165 166 |
# File 'lib/omnizip/algorithms/lzma/xz_probability_models.rb', line 164 def prices @prices end |
Instance Method Details
#decrement_counter(pos_state) ⇒ Boolean
Decrement counter for position state
243 244 245 246 |
# File 'lib/omnizip/algorithms/lzma/xz_probability_models.rb', line 243 def decrement_counter(pos_state) @counters[pos_state] -= 1 @counters[pos_state] <= 0 end |
#get_price(pos_state, length) ⇒ Integer
Get price for encoding length at position state
226 227 228 |
# File 'lib/omnizip/algorithms/lzma/xz_probability_models.rb', line 226 def get_price(pos_state, length) @prices[pos_state][length - MATCH_LEN_MIN] end |
#reset ⇒ Object
Reset all models to initial state
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/omnizip/algorithms/lzma/xz_probability_models.rb', line 201 def reset @choice.value = BIT_MODEL_TOTAL >> 1 @choice2.value = BIT_MODEL_TOTAL >> 1 @low.each do |models| models.each do |prob| prob.value = BIT_MODEL_TOTAL >> 1 end end @mid.each do |models| models.each do |prob| prob.value = BIT_MODEL_TOTAL >> 1 end end @high.each { |prob| prob.value = BIT_MODEL_TOTAL >> 1 } # Reset price tables @prices.each { |pos_prices| pos_prices.fill(0) } @counters.fill(0) end |
#reset_counter(pos_state, value) ⇒ Object
Reset counter for position state
252 253 254 |
# File 'lib/omnizip/algorithms/lzma/xz_probability_models.rb', line 252 def reset_counter(pos_state, value) @counters[pos_state] = value end |
#set_price(pos_state, length, price) ⇒ Object
Set price for length at position state
235 236 237 |
# File 'lib/omnizip/algorithms/lzma/xz_probability_models.rb', line 235 def set_price(pos_state, length, price) @prices[pos_state][length - MATCH_LEN_MIN] = price end |