Class: Omnizip::Algorithms::LZMA::MatchFinderConfig
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::LZMA::MatchFinderConfig
- 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.
Instance Attribute Summary collapse
-
#chain_length ⇒ Object
Returns the value of attribute chain_length.
-
#hash_size ⇒ Object
Returns the value of attribute hash_size.
-
#lazy_matching ⇒ Object
Returns the value of attribute lazy_matching.
-
#max_match_length ⇒ Object
Returns the value of attribute max_match_length.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#search_mode ⇒ Object
Returns the value of attribute search_mode.
-
#window_size ⇒ Object
Returns the value of attribute window_size.
Class Method Summary collapse
-
.sdk_config(dict_size: 65536, level: 5) ⇒ MatchFinderConfig
Create SDK-compatible configuration.
-
.simplified_config(dict_size: 65536) ⇒ MatchFinderConfig
Create simplified configuration with sensible defaults.
Instance Method Summary collapse
-
#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
constructor
A new instance of MatchFinderConfig.
-
#validate! ⇒ Boolean
Validate configuration.
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_length ⇒ Object
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_size ⇒ Object
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_matching ⇒ Object
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_length ⇒ Object
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 |
#mode ⇒ Object
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_mode ⇒ Object
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_size ⇒ Object
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
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.
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
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 |