Class: Omnizip::Algorithms::LZMA::XzBufferedRangeEncoder::Probability

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/omnizip/algorithms/lzma/xz_buffered_range_encoder.rb

Overview

Mutable probability model for XZ Utils encoder Unlike BitModel, this has a mutable value attribute for inline updates

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

Instance Method Summary collapse

Constructor Details

#initialize(initial_value = BIT_MODEL_TOTAL >> 1) ⇒ Probability

Returns a new instance of Probability.



38
39
40
# File 'lib/omnizip/algorithms/lzma/xz_buffered_range_encoder.rb', line 38

def initialize(initial_value = BIT_MODEL_TOTAL >> 1)
  @value = initial_value
end

Instance Attribute Details

#valueObject Also known as: probability

Returns the value of attribute value.



36
37
38
# File 'lib/omnizip/algorithms/lzma/xz_buffered_range_encoder.rb', line 36

def value
  @value
end

Instance Method Details

#update(bit) ⇒ Object

Update the probability model based on an actual bit value Compatibility with BitModel interface



44
45
46
47
48
49
50
# File 'lib/omnizip/algorithms/lzma/xz_buffered_range_encoder.rb', line 44

def update(bit)
  if bit.zero?
    @value += ((BIT_MODEL_TOTAL - @value) >> MOVE_BITS)
  else
    @value -= (@value >> MOVE_BITS)
  end
end