-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
89 lines (72 loc) · 3.22 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"fmt"
"time"
"huffman_study/compression"
)
func huffmanString(input string) (string, int) {
root := compression.BuildHuffmanTree(input)
codes := make(map[rune]string)
compression.GenerateCodes(root, "", codes)
huffmanEncoded := compression.Encode(input, codes)
return huffmanEncoded, MeasureSpace(huffmanEncoded)
}
func main() {
// Sample input and various test cases
inputs := loadInputFromFile()
fmt.Println("Performance and Space comparison for various inputs:")
for _, in := range inputs {
fmt.Printf("\nTesting with input size: %d characters\n", len(in))
fmt.Printf("String:%s\n\n", in)
// Simple Encoding
start := time.Now()
simpleEncoded := compression.SimpleEncode(in)
TrackTime(start, "Simple Encoding")
simpleSize := MeasureSpace(simpleEncoded)
fmt.Printf("Simple Encoded size: %d bits\n", simpleSize)
fmt.Printf("Compression Ratio: %.5f\n\n", CompressionRatio(len(in)*8, simpleSize))
// Huffman Encoding
start = time.Now()
_, hufSize := huffmanString(in)
TrackTime(start, "Huffman Encoding")
fmt.Printf("Huffman Encoded size: %d bits\n", hufSize)
fmt.Printf("Compression Ratio: %.5f\n\n", CompressionRatio(len(in)*8, hufSize))
// BWT + Huffman Encoding
start = time.Now()
_, bwtHufSize := huffmanString(compression.BWTTransform(in))
TrackTime(start, "BWT + Huffman Encoding")
fmt.Printf("BWT + Huffman Encoded size: %d bits\n", bwtHufSize)
fmt.Printf("Compression Ratio: %.5f\n\n", CompressionRatio(len(in)*8, bwtHufSize))
// RLE + Huffman Encoding
start = time.Now()
_, rleHufSize := huffmanString(compression.RLECompress(in))
TrackTime(start, "RLE + Huffman Encoding")
fmt.Printf("RLE + Huffman Encoded size: %d bits\n", rleHufSize)
fmt.Printf("Compression Ratio: %.5f\n\n", CompressionRatio(len(in)*8, rleHufSize))
// BWT + RLE + Huffman Encoding
start = time.Now()
bwtRle := compression.RLECompress(compression.BWTTransform(in))
_, bwtRleHufSize := huffmanString(bwtRle)
TrackTime(start, "BWT + RLE + Huffman Encoding")
fmt.Printf("BWT + RLE + Huffman Encoded size: %d bits\n", bwtRleHufSize)
fmt.Printf("Compression Ratio: %.5f\n\n", CompressionRatio(len(in)*8, bwtRleHufSize))
// BWT + MTF + RLE + Huffman Encoding
start = time.Now()
bwtMtf := compression.MoveToFrontTransform(compression.BWTTransform(in))
_, bwtMtfRleHufSize := huffmanString(compression.RLECompress(bwtMtf))
TrackTime(start, "BWT + MTF + RLE + Huffman Encoding")
fmt.Printf("BWT + MTF + RLE + Huffman Encoding size: %d bits\n", bwtMtfRleHufSize)
fmt.Printf("Compression Ratio: %.5f\n\n", CompressionRatio(len(in)*8, bwtMtfRleHufSize))
/*
// BWT + MTF + RLE+ LZW + Huffman Encoding
start = time.Now()
bwtMtf = compression.MoveToFrontTransform(compression.BWTTransform(in))
bwtMtfRleLZW := compression.LZWCompress(compression.RLECompress(bwtMtf))
_, hufSize = huffmanString(bwtMtfRleLZW)
TrackTime(start, "BWT + MTF + RLE + LZW + Huffman Encoding")
fmt.Printf("BWT + MTF + RLE + LZW + Huffman Encoding size: %d bits\n", hufSize)
fmt.Printf("Compression Ratio: %.5f\n\n", CompressionRatio(len(in)*8, hufSize))
*/
}
fmt.Println("*****************************************************")
}