Class: Omnizip::Algorithms::LZMA::State

Inherits:
Object
  • Object
show all
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.

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

Instance Method Summary collapse

Constructor Details

#initialize(initial_state = 0) ⇒ State

Initialize the state machine

Parameters:

  • initial_state (Integer) (defaults to: 0)

    Initial state index (default: 0)



58
59
60
# File 'lib/omnizip/algorithms/lzma/state.rb', line 58

def initialize(initial_state = 0)
  @index = initial_state
end

Instance Attribute Details

#indexObject (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

#dupState

Create a copy of this state

Returns:

  • (State)

    A new State with the same index



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

Returns:

  • (Boolean)

    True if state < 7



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

Returns:

  • (Boolean)

    True if state >= 7



100
101
102
# File 'lib/omnizip/algorithms/lzma/state.rb', line 100

def match?
  @index >= 7
end

#resetvoid

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_iInteger

Get state index for probability model selection

Returns:

  • (Integer)

    Current state index



121
122
123
# File 'lib/omnizip/algorithms/lzma/state.rb', line 121

def to_i
  @index
end

#update_literalvoid

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_matchvoid

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_repvoid

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_repvoid

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