Class: Omnizip::Algorithms::LZMA::State
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::LZMA::State
- Defined in:
- lib/omnizip/algorithms/lzma/state.rb
Overview
LZMA State Machine for managing compression states
This class implements the state machine used by LZMA to track the current compression context. The state determines which probability models are used for encoding the next symbol.
LZMA uses 12 states that transition based on the type of symbol being encoded (literal, match, rep match, etc.). The state affects probability model selection for better compression.
Direct Known Subclasses
Constant Summary collapse
- NUM_STATES =
Total number of LZMA states
12- LIT_STATES =
State transition tables After encoding a literal
[0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5].freeze
- MATCH_STATES =
After encoding a match
[7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10].freeze
- REP_STATES =
After encoding a rep match
[8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11].freeze
- SHORT_REP_STATES =
After encoding a short rep
[9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11].freeze
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
Instance Method Summary collapse
-
#dup ⇒ State
Create a copy of this state.
-
#initialize(initial_state = 0) ⇒ State
constructor
Initialize the state machine.
-
#literal? ⇒ Boolean
Check if current state is a literal state.
-
#match? ⇒ Boolean
Check if current state is a match state.
-
#reset ⇒ void
Reset state to initial value.
-
#to_i ⇒ Integer
Get state index for probability model selection.
-
#update_literal ⇒ void
Update state after encoding a literal.
-
#update_match ⇒ void
Update state after encoding a match.
-
#update_rep ⇒ void
Update state after encoding a repeat match.
-
#update_short_rep ⇒ void
Update state after encoding a short repeat match.
Constructor Details
#initialize(initial_state = 0) ⇒ State
Initialize the state machine
58 59 60 |
# File 'lib/omnizip/algorithms/lzma/state.rb', line 58 def initialize(initial_state = 0) @index = initial_state end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
53 54 55 |
# File 'lib/omnizip/algorithms/lzma/state.rb', line 53 def index @index end |
Instance Method Details
#dup ⇒ State
Create a copy of this state
114 115 116 |
# File 'lib/omnizip/algorithms/lzma/state.rb', line 114 def dup State.new(@index) end |
#literal? ⇒ Boolean
Check if current state is a literal state
93 94 95 |
# File 'lib/omnizip/algorithms/lzma/state.rb', line 93 def literal? @index < 7 end |
#match? ⇒ Boolean
Check if current state is a match state
100 101 102 |
# File 'lib/omnizip/algorithms/lzma/state.rb', line 100 def match? @index >= 7 end |
#reset ⇒ void
This method returns an undefined value.
Reset state to initial value
107 108 109 |
# File 'lib/omnizip/algorithms/lzma/state.rb', line 107 def reset @index = 0 end |
#to_i ⇒ Integer
Get state index for probability model selection
121 122 123 |
# File 'lib/omnizip/algorithms/lzma/state.rb', line 121 def to_i @index end |
#update_literal ⇒ void
This method returns an undefined value.
Update state after encoding a literal
65 66 67 |
# File 'lib/omnizip/algorithms/lzma/state.rb', line 65 def update_literal @index = LIT_STATES[@index] end |
#update_match ⇒ void
This method returns an undefined value.
Update state after encoding a match
72 73 74 |
# File 'lib/omnizip/algorithms/lzma/state.rb', line 72 def update_match @index = MATCH_STATES[@index] end |
#update_rep ⇒ void
This method returns an undefined value.
Update state after encoding a repeat match
79 80 81 |
# File 'lib/omnizip/algorithms/lzma/state.rb', line 79 def update_rep @index = REP_STATES[@index] end |
#update_short_rep ⇒ void
This method returns an undefined value.
Update state after encoding a short repeat match
86 87 88 |
# File 'lib/omnizip/algorithms/lzma/state.rb', line 86 def update_short_rep @index = SHORT_REP_STATES[@index] end |