lib/gziprb/deflate.rb
# Distance codes 0-31 are represented by (fixed-length) 5-bit codes, with possible additional
# bits as shown in the table shown in Paragraph 3.2.5, above. Note that distance codes 30-31
# will never actually occur in the compressed data.
Distance codes 0-31 are represented by (fixed-length) 5-bit codes, with possible additional
bits as shown in the table shown in Paragraph 3.2.5, above. Note that distance codes 30-31
will never actually occur in the compressed data.
Distance codes 0 - 31 are represented by ( fixed - length ) 5 - bit codes with possible additional bits as shown in the table shown in Paragraph 3 . 2 . 5 above . Note that distance codes 30 - 31 will never actually occur in the compressed data .
def define_code_writer(bases:, extra_bits:, code_range:, value_range:)
      Class.new do
        define_method(:to_code) do |value|
          raise "Unexpected value #{value} in #{self.class}" unless value_range.include?(value)
          _, _, index = last_entry_with_base_less_or_equal_to(value)
          index + code_range.min
        end
        define_method(:write) do |value, huffman_encoding, on_code, output_number|
          on_code.call(huffman_encoding.fetch(to_code(value)))
          base, extra, _index = last_entry_with_base_less_or_equal_to(value)
          output_number.call(extra, value - base) if extra.positive?
        end
        private
        define_method(:last_entry_with_base_less_or_equal_to) do |value|
          @reversed_entries ||= bases.zip(extra_bits).each_with_index.to_a.map(&:flatten).reverse
          @reversed_entries.bsearch { |(base, _, _)| base <= value }
        end
      end
    end
def define_code_writer ( bases : , extra_bits : , code_range : , value_range : ) Class . new do define_method ( :to_code ) do | value | raise "Unexpected value #{value} in #{self.class}" unless value_range . include? ( value ) _ , _ , index = last_entry_with_base_less_or_equal_to ( value ) index + code_range . min end define_method ( :write ) do | value , huffman_encoding , on_code , output_number | on_code . call ( huffman_encoding . fetch ( to_code ( value ) ) ) base , extra , _index = last_entry_with_base_less_or_equal_to ( value ) output_number . call ( extra , value - base ) if extra . positive? end private define_method ( :last_entry_with_base_less_or_equal_to ) do | value | @reversed_entries ||= bases . zip ( extra_bits ) . each_with_index . to_a . map ( & :flatten ) . reverse @reversed_entries . bsearch { | ( base , _ , _ ) | base <= value } end end end
Distance codes 0-31 are represented by (fixed-length) 5-bit codes, with possible additional
bits as shown in the table shown in Paragraph 3.2.5, above.
Distance codes 0 - 31 are represented by ( fixed - length ) 5 - bit codes with possible additional bits as shown in the table shown in Paragraph 3 . 2 . 5 above .
bases
extra_bits
code_range
value_range