Class: Cabriolet::Binary::HLPStructures::HuffmanNode

Inherits:
BinData::Record
  • Object
show all
Defined in:
lib/cabriolet/binary/hlp_structures.rb

Overview

Huffman tree node (2 bytes per node)

Leaf node: bit 15 set, bits 0-7 contain symbol Internal node: bit 15 clear, node_value/2 is left child index, i+1 is right child

Instance Method Summary collapse

Instance Method Details

#leaf?Boolean

Check if this is a leaf node



131
132
133
# File 'lib/cabriolet/binary/hlp_structures.rb', line 131

def leaf?
  node_value.negative?
end

#left_child_indexObject

Get left child index for internal node



143
144
145
146
147
# File 'lib/cabriolet/binary/hlp_structures.rb', line 143

def left_child_index
  return nil if leaf?

  node_value / 2
end

#symbolObject

Get symbol for leaf node



136
137
138
139
140
# File 'lib/cabriolet/binary/hlp_structures.rb', line 136

def symbol
  return nil unless leaf?

  node_value & 0xFF
end