Skip to content

Instantly share code, notes, and snippets.

@invokr
Last active August 29, 2015 14:24
Show Gist options
  • Save invokr/9f60fc78ff2aea859413 to your computer and use it in GitHub Desktop.
Save invokr/9f60fc78ff2aea859413 to your computer and use it in GitHub Desktop.
// Node is either HuffmanLeaf or HuffmanNode
// Leaf = only value
// Node = left and right, both are either a leaf or a node
// This would be better
node := 'something'
for fp.finished == false {
if r.readBits(1) == 1 {
node = node.right
} else {
node = node.left
}
if node == isLeaf {
node.value.(FieldPathOpFcn)(r, fp)
}
}
// Current code
// Walk an encoded fieldpath based on a huffman tree
func (fp *fieldpath) fieldpath_walk(r *reader) []dt_field {
fields := make([]dt_field, 0)
// where is do-while when you need it -.-
node := (*fp.tree).(HuffmanNode)
for fp.finished == false {
if r.readBits(1) == 1 {
switch i := node.right.(type) {
case HuffmanLeaf:
i.value.(FieldPathOpFcn)(r, fp)
node = (*fp.tree).(HuffmanNode)
case HuffmanNode:
node = i
}
} else {
switch i := node.left.(type) {
case HuffmanLeaf:
i.value.(FieldPathOpFcn)(r, fp)
node = (*fp.tree).(HuffmanNode)
case HuffmanNode:
node = i
}
}
}
return fields
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment