Class: Omnizip::Algorithms::LZMA::MatchFinderConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/algorithms/lzma/match_finder_config.rb

Overview

Configuration model for Match Finder behavior

This model separates configuration from implementation, allowing different match finding strategies (SDK-compatible vs simplified) to be configured declaratively.

Examples:

SDK-compatible configuration

config = MatchFinderConfig.new(
  mode: :sdk,
  hash_size: 65536,
  chain_length: 32,
  lazy_matching: false
)

Simplified configuration

config = MatchFinderConfig.new(
  mode: :simplified,
  hash_size: 65536,
  chain_length: 1024
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode: "simplified", hash_size: 65_536, chain_length: 1024, search_mode: "hash_chain", lazy_matching: false, max_match_length: 273, window_size: 65_536) ⇒ MatchFinderConfig

Returns a new instance of MatchFinderConfig.



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/omnizip/algorithms/lzma/match_finder_config.rb', line 50

def initialize(mode: "simplified", hash_size: 65_536,
               chain_length: 1024, search_mode: "hash_chain",
               lazy_matching: false, max_match_length: 273,
               window_size: 65_536)
  @mode = mode
  @hash_size = hash_size
  @chain_length = chain_length
  @search_mode = search_mode
  @lazy_matching = lazy_matching
  @max_match_length = max_match_length
  @window_size = window_size
end

Instance Attribute Details

#chain_lengthObject

Returns the value of attribute chain_length.



47
48
49
# File 'lib/omnizip/algorithms/lzma/match_finder_config.rb', line 47

def chain_length
  @chain_length
end

#hash_sizeObject

Returns the value of attribute hash_size.



47
48
49
# File 'lib/omnizip/algorithms/lzma/match_finder_config.rb', line 47

def hash_size
  @hash_size
end

#lazy_matchingObject

Returns the value of attribute lazy_matching.



47
48
49
# File 'lib/omnizip/algorithms/lzma/match_finder_config.rb', line 47

def lazy_matching
  @lazy_matching
end

#max_match_lengthObject

Returns the value of attribute max_match_length.



47
48
49
# File 'lib/omnizip/algorithms/lzma/match_finder_config.rb', line 47

def max_match_length
  @max_match_length
end

#modeObject

Returns the value of attribute mode.



47
48
49
# File 'lib/omnizip/algorithms/lzma/match_finder_config.rb', line 47

def mode
  @mode
end

#search_modeObject

Returns the value of attribute search_mode.



47
48
49
# File 'lib/omnizip/algorithms/lzma/match_finder_config.rb', line 47

def search_mode
  @search_mode
end

#window_sizeObject

Returns the value of attribute window_size.



47
48
49
# File 'lib/omnizip/algorithms/lzma/match_finder_config.rb', line 47

def window_size
  @window_size
end

Class Method Details

.sdk_config(dict_size: 65536, level: 5) ⇒ MatchFinderConfig

Create SDK-compatible configuration

Parameters:

  • dict_size (Integer) (defaults to: 65536)

    Dictionary size

  • level (Integer) (defaults to: 5)

    Compression level (0-9)

Returns:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/omnizip/algorithms/lzma/match_finder_config.rb', line 100

def self.sdk_config(dict_size: 65536, level: 5)
  # SDK uses different parameters based on dictionary size and level
  hash_size = dict_size >= (1 << 20) ? (1 << 20) : (1 << 16)

  # SDK nice_len varies by compression level:
  # Level 0-4: 32, Level 5-6: 64, Level 7-8: 128, Level 9: 273
  chain_length = case level
                 when 0..4 then 32
                 when 5..6 then 64
                 when 7..8 then 128
                 else 273
                 end

  new(
    mode: "sdk",
    hash_size: hash_size,
    chain_length: chain_length,
    search_mode: "hash_chain",
    lazy_matching: level >= 7, # Enable lazy matching for high compression
    max_match_length: 273,
    window_size: dict_size,
  )
end

.simplified_config(dict_size: 65536) ⇒ MatchFinderConfig

Create simplified configuration with sensible defaults.

Parameters:

  • dict_size (Integer) (defaults to: 65536)

    Dictionary size

Returns:



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/omnizip/algorithms/lzma/match_finder_config.rb', line 128

def self.simplified_config(dict_size: 65536)
  new(
    mode: "simplified",
    hash_size: 65536,
    chain_length: 1024,
    search_mode: "hash_chain",
    lazy_matching: false,
    max_match_length: 273,
    window_size: dict_size,
  )
end

Instance Method Details

#validate!Boolean

Validate configuration

Returns:

  • (Boolean)

    true if valid

Raises:

  • (ArgumentError)

    if configuration is invalid



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/omnizip/algorithms/lzma/match_finder_config.rb', line 67

def validate!
  unless %w[sdk simplified].include?(mode)
    raise ArgumentError, "mode must be :sdk or :simplified"
  end

  unless %w[hash_chain binary_tree].include?(search_mode)
    raise ArgumentError,
          "search_mode must be :hash_chain or :binary_tree"
  end

  raise ArgumentError, "hash_size must be positive" if hash_size <= 0

  if chain_length <= 0
    raise ArgumentError,
          "chain_length must be positive"
  end
  if max_match_length < 2
    raise ArgumentError,
          "max_match_length must be >= 2"
  end
  if window_size <= 0
    raise ArgumentError,
          "window_size must be positive"
  end

  true
end