Class: Baykit::BayServer::Docker::Http::H2::Huffman::HTree
- Inherits:
-
Object
- Object
- Baykit::BayServer::Docker::Http::H2::Huffman::HTree
- Defined in:
- lib/baykit/bayserver/docker/http/h2/huffman/htree.rb
Class Attribute Summary collapse
-
.root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Class Attribute Details
.root ⇒ Object (readonly)
Returns the value of attribute root.
14 15 16 |
# File 'lib/baykit/bayserver/docker/http/h2/huffman/htree.rb', line 14 def root @root end |
Class Method Details
.decode(data) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/baykit/bayserver/docker/http/h2/huffman/htree.rb', line 19 def self.decode(data) w = "" cur = @root data.length.times do |i| if data[i] == nil BayLog.info "NIL" end 8.times do |j| bit = data[i].codepoints[0] >> (8-j-1) & 0x1 # down tree if bit == 1 cur = cur.one else cur = cur.zero end if cur.value > 0 # leaf node w.concat(cur.value.chr) cur = @root end end end return w end |
.insert(code, len_in_bits, sym) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/baykit/bayserver/docker/http/h2/huffman/htree.rb', line 46 def self.insert(code, len_in_bits, sym) bits = Array.new(len_in_bits) len_in_bits.times do |i| bits[i] = code >> (len_in_bits - i - 1) & 0x1 end insert_bits bits, sym end |
.insert_bits(code, sym) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/baykit/bayserver/docker/http/h2/huffman/htree.rb', line 54 def self.insert_bits(code, sym) cur = @root code.length.times do |i| if code[i] == 1 if cur.one == nil cur.one = HNode.new() end cur = cur.one else if cur.zero == nil cur.zero = HNode.new() end cur = cur.zero end end cur.value = sym end |