Class: Cabriolet::Binary::HLPStructures::HuffmanNode
- Inherits:
-
BinData::Record
- Object
- BinData::Record
- Cabriolet::Binary::HLPStructures::HuffmanNode
- 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
-
#leaf? ⇒ Boolean
Check if this is a leaf node.
-
#left_child_index ⇒ Object
Get left child index for internal node.
-
#symbol ⇒ Object
Get symbol for leaf node.
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_index ⇒ Object
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 |
#symbol ⇒ Object
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 |