Skip to content

TobiasLoader/huffmango

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

huffmango

Go package

Huffman coding implemented in Go, Wikipedia.

mangotree

From /huffmango directory:

go run cmd/main.go

The core of the algorithm – in algo.go from line 84:

// create the Huffman tree
for p.Count()>1 {
  n1 := p.Dequeue()
  n2 := p.Dequeue()
  n0_name := n1.GetName()+n2.GetName()
  n0_weight := n1.GetWeight()+n2.GetWeight()
  n0 := node.NewHuffmanNode(n0_name,n0_weight)
  n0.SetChild1(n1)
  n0.SetChild2(n2)
  p.Enqueue(n0)
}

// extract the root
root := p.Dequeue()

// traverse the tree (with DFS) to create encoding
encoding := NewEncoding(name,blocksize)
encoding.DFS("",root)
encoding.Show()

return encoding;

About

Huffman coding implemented in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages