huffman

package
v0.0.0-...-ecf7a0d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2016 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package huffman implements Huffman prefix coding.

Index

Constants

View Source
const TreeSelectionLimit = 50

TreeSelectionLimit is the symbol limit for each tree selection.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code struct {
	Len  int
	Bits uint64
}

Code contains the bit code for a symbol.

type Node

type Node struct {
	Left  *Node
	Right *Node

	Value     uint16
	Frequency int
}

Node is a single node in the tree.

func (Node) Leaf

func (n Node) Leaf() bool

Leaf is used to check if the node has children.

type NodeQueue

type NodeQueue []*Node

NodeQueue is a priority queue that keeps track of nodes.

func (NodeQueue) Len

func (nq NodeQueue) Len() int

Len gets the number of nodes in the queue.

func (NodeQueue) Less

func (nq NodeQueue) Less(i, j int) bool

Less checks if the priority of node i is less than the priority of node j.

func (*NodeQueue) Pop

func (nq *NodeQueue) Pop() interface{}

Pop pops the lowest priority node from the queue.

func (*NodeQueue) Push

func (nq *NodeQueue) Push(x interface{})

Push pushes a new node to the queue.

func (NodeQueue) Swap

func (nq NodeQueue) Swap(i, j int)

Swap swaps the nodes i and j.

type Tree

type Tree struct {
	Codes []*Code
	// contains filtered or unexported fields
}

Tree is a binary tree that is navigated to produce bits for the frequencies of symbols.

func GenerateTrees

func GenerateTrees(freqs rle2.Frequencies, src []uint16) ([]*Tree, []int)

GenerateTrees creates the trees required to encode the data, and which tree to use for each 50 symbol block of data in src.

func NewTree

func NewTree(freqs rle2.Frequencies) *Tree

NewTree creates a huffman tree and gets the codes for the symbol frequencies given.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL