tasks/huffman.rb in protocol-hpack-1.4.3 vs tasks/huffman.rb in protocol-hpack-1.5.0

- old
+ new

@@ -4,17 +4,18 @@ # Copyright, 2014, by Kaoru Maeda. # Copyright, 2015, by Tamir Duberstein. # Copyright, 2015, by Ilya Grigorik. # Copyright, 2016, by George Ulmer. # Copyright, 2018-2024, by Samuel Williams. +# Copyright, 2024, by Nathan Froyd. -require_relative '../lib/http/hpack/huffman' +require_relative '../lib/protocol/hpack/huffman' require 'set' module Huffman - BITS_AT_ONCE = HTTP::HPACK::Huffman::BITS_AT_ONCE + BITS_AT_ONCE = Protocol::HPACK::Huffman::BITS_AT_ONCE EOS = 256 class Node attr_accessor :next, :emit, :final, :depth attr_accessor :transitions @@ -47,11 +48,11 @@ end end def self.generate_tree @root = new(0) - HTTP::HPACK::Huffman::CODES.each_with_index do |c, chr| + Protocol::HPACK::Huffman::CODES.each_with_index do |c, chr| code, len = c @root.add(code, len, chr) end puts "#{@@id} nodes" @root @@ -69,11 +70,11 @@ next if node.transitions node.transitions = Array[1 << BITS_AT_ONCE] (1 << BITS_AT_ONCE).times do |input| n = node - emit = '' + emit = +'' (BITS_AT_ONCE - 1).downto(0) do |i| bit = (input & (1 << i)).zero? ? 0 : 1 n = n.next[bit] next unless n.emit if n.emit == EOS @@ -105,10 +106,10 @@ id_state[id] = s max_final = id if s.final id += 1 end - File.open(File.expand_path('../lib/http/hpack/huffman/machine.rb', File.dirname(__FILE__)), 'w') do |f| + File.open(File.expand_path('../lib/protocol/hpack/huffman/machine.rb', File.dirname(__FILE__)), 'w') do |f| f.print <<HEADER # frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2024, by Samuel Williams.