huffmyfile

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(inputFileName, outputFileName string, e *Encoder)
Decode(): Takes an encoded .huff file, decodes and writes decoded text to

* an output file.

func Encode

func Encode(inputFileName, compressedFileName string, e *Encoder)

Encode(): Encodes a text file to a .huff file.

func GetCompressionRatio

func GetCompressionRatio(originalFileName, compressedFileName string) (float64, error)
GetCompressionRatio(): Compares the sizes of the original and the compressed

* files, returns the ratio as a float64.

Types

type BitReader

type BitReader struct {
	// contains filtered or unexported fields
}

func NewBitReader

func NewBitReader(reader io.Reader) *BitReader

func (*BitReader) ReadBit

func (br *BitReader) ReadBit() (bit bool, err error)

* ReadBit(): Wrapper function for readBit() to return a bool rather than uint8

func (*BitReader) ReadByte

func (br *BitReader) ReadByte() (b byte, err error)
ReadByte(): Wrapper function for readByte(). Throws an error if ReadByte() is called

* while the buffer is still full.

type BitWriter

type BitWriter struct {
	// contains filtered or unexported fields
}

func NewBitWriter

func NewBitWriter(writer io.Writer) *BitWriter

func (*BitWriter) Flush

func (bw *BitWriter) Flush() error

Flush(): Writes whatever bits are left to the underlying writer.

func (*BitWriter) WriteBit

func (bw *BitWriter) WriteBit(bit bool) error
WriteBit(): Sets bits into a buffer byte one at a time. When the byte is full (8 bits

* have been entered), the accumulated byte is written to the underlying writer.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

func (*Encoder) DecodeToDefaultOutputFile

func (e *Encoder) DecodeToDefaultOutputFile(inputFileName string)
DecodeToDefaultOutputFile():

* Wrapper function for Decode(). Allows for decoding without specifying an * output file. Creates an output file based on the name for the input file.

func (*Encoder) EncodeToDefaultOutputFile

func (e *Encoder) EncodeToDefaultOutputFile(inputFileName string)
EncodeToDefaultOutputFile():

* Wrapper for Encode() so an output file name doesn't need to be specified. * Creates an output file name based on the input file name.

type HTWrapper

type HTWrapper struct {
	// contains filtered or unexported fields
}

type HuffNode

type HuffNode struct {
	// contains filtered or unexported fields
}

type HuffTree

type HuffTree struct {
	// contains filtered or unexported fields
}

func (*HuffTree) CodeMap

func (ht *HuffTree) CodeMap() map[int]string

Returns a map of the unique codes which each character will be represented by in a particular encoding.

func (*HuffTree) Combine

func (a *HuffTree) Combine(b *HuffTree) *HuffTree

Returns a new HuffTree with a new root node pointing at the two which were combined. The left child has lower frequency, and the freq value of the root node is the sum of its children.

func (*HuffTree) Compare

func (a *HuffTree) Compare(b *HuffTree) int

func (*HuffTree) MakeHuffmanTree

func (a *HuffTree) MakeHuffmanTree(freqMap map[int]int)

func (*HuffTree) Print

func (a *HuffTree) Print()

Prints out a pre-order representation of the HuffmanTree. Characters are printed but only their ascii values are stored in the nodes.

type PriorityQueue

type PriorityQueue []*HTWrapper

PriorityQueue implemented using Heap interface in order to always be able to access the two trees with the lowest total frequencies of their leaves

func (PriorityQueue) Len

func (pq PriorityQueue) Len() int

func (PriorityQueue) Less

func (pq PriorityQueue) Less(i, j int) bool

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() any

func (*PriorityQueue) Print

func (pq *PriorityQueue) Print()

Prints an array representation of the priority queue's contents

func (*PriorityQueue) Println

func (pq *PriorityQueue) Println()

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(x any)

func (PriorityQueue) Swap

func (pq PriorityQueue) Swap(i, j int)

Jump to

Keyboard shortcuts

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