Class: Omnizip::Algorithms::Zstandard::MatchFinder::MatchState

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

Overview

Persistent hash table (and optional chain) shared by all blocks of a frame. Positions are absolute offsets into the input; the table is NOT cleared between blocks.

Constant Summary

Constants included from Constants

Constants::BLOCK_HEADER_SIZE, Constants::BLOCK_MAX_SIZE, Constants::BLOCK_TYPE_COMPRESSED, Constants::BLOCK_TYPE_RAW, Constants::BLOCK_TYPE_RESERVED, Constants::BLOCK_TYPE_RLE, Constants::BUFFER_SIZE, Constants::DEFAULT_LEVEL, Constants::DEFAULT_REPEAT_OFFSETS, Constants::FSE_DEFAULT_TABLELOG, Constants::FSE_MAX_ACCURACY_LOG, Constants::FSE_MIN_ACCURACY_LOG, Constants::HUFFMAN_MAX_BITS, Constants::HUFFMAN_MAX_CODE_LENGTH, Constants::HUFFMAN_MAX_LOG, Constants::HUFFMAN_STANDARD_TABLE_SIZE, Constants::HUF_SYMBOLVALUE_MAX, Constants::LDM_MIN_LEVEL, Constants::LITERALS_BLOCK_COMPRESSED, Constants::LITERALS_BLOCK_RAW, Constants::LITERALS_BLOCK_RLE, Constants::LITERALS_BLOCK_TREELESS, Constants::LITERALS_LENGTH_ACCURACY_LOG, Constants::LITERAL_LENGTH_TABLE, Constants::MAGIC_BYTES, Constants::MAGIC_NUMBER, Constants::MATCH_LENGTH_ACCURACY_LOG, Constants::MATCH_LENGTH_TABLE, Constants::MAX_LEVEL, Constants::MIN_LEVEL, Constants::MODE_FSE, Constants::MODE_PREDEFINED, Constants::MODE_REPEAT, Constants::MODE_RLE, Constants::OFFSET_ACCURACY_LOG, Constants::OF_BASE, Constants::OF_BITS, Constants::PREDEFINED_LL_DISTRIBUTION, Constants::PREDEFINED_ML_DISTRIBUTION, Constants::PREDEFINED_OFFSET_DISTRIBUTION, Constants::REPEAT_OFFSET_1, Constants::REPEAT_OFFSET_2, Constants::REPEAT_OFFSET_3, Constants::SKIPPABLE_MAGIC_BASE, Constants::SKIPPABLE_MAGIC_MASK, Constants::WINDOW_LOG_MAX, Constants::WINDOW_LOG_MIN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Constants

highbit32

Constructor Details

#initialize(hash_log) ⇒ MatchState

Returns a new instance of MatchState.



74
75
76
77
78
79
# File 'lib/omnizip/algorithms/zstandard/match_finder.rb', line 74

def initialize(hash_log)
  @hash_log = hash_log
  @hash_table = Array.new(1 << hash_log, 0)
  @chain = []
  @max_chain = 0
end

Instance Attribute Details

#chainObject (readonly)

Returns the value of attribute chain.



71
72
73
# File 'lib/omnizip/algorithms/zstandard/match_finder.rb', line 71

def chain
  @chain
end

#hash_logObject

Returns the value of attribute hash_log.



72
73
74
# File 'lib/omnizip/algorithms/zstandard/match_finder.rb', line 72

def hash_log
  @hash_log
end

#hash_tableObject (readonly)

Returns the value of attribute hash_table.



71
72
73
# File 'lib/omnizip/algorithms/zstandard/match_finder.rb', line 71

def hash_table
  @hash_table
end

#max_chainObject (readonly)

Returns the value of attribute max_chain.



71
72
73
# File 'lib/omnizip/algorithms/zstandard/match_finder.rb', line 71

def max_chain
  @max_chain
end

Instance Method Details

#disable_chainObject



88
89
90
# File 'lib/omnizip/algorithms/zstandard/match_finder.rb', line 88

def disable_chain
  @max_chain = 0
end

#enable_chain(max_chain) ⇒ Object



81
82
83
84
85
86
# File 'lib/omnizip/algorithms/zstandard/match_finder.rb', line 81

def enable_chain(max_chain)
  @max_chain = max_chain
  return unless max_chain.positive? && @chain.empty?

  @chain = Array.new(BLOCK_MAX_SIZE + 1, 0)
end

#seed_prefix(src, prefix_len) ⇒ Object

Seed the hash table with a prefix's positions (dictionary content prepended to the plaintext): the most recent position per hash wins, matching insert order.



95
96
97
98
99
100
101
102
# File 'lib/omnizip/algorithms/zstandard/match_finder.rb', line 95

def seed_prefix(src, prefix_len)
  return if prefix_len < MIN_MATCH

  limit = prefix_len - MIN_MATCH + 1
  (0...limit).each do |pos|
    @hash_table[MatchFinder.hash4(src, pos, @hash_log)] = pos
  end
end