-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
55 lines (46 loc) · 1015 Bytes
/
utils.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
package main
import (
"bufio"
"os"
"time"
"fmt"
)
func TrackTime(start time.Time, name string) {
elapsed := time.Since(start)
fmt.Printf("%s took %s\n", name, elapsed)
}
func CompressionRatio(originalSize, compressedSize int) float64 {
if originalSize == 0 {
return 0
}
return float64(compressedSize) / float64(originalSize)
}
func MeasureSpace(encoded string) int {
return len(encoded)
}
func getPercentage(algorithmSpace int, simpleSpace int) float32 {
if algorithmSpace == 0 {
return 0
}
return float32(simpleSpace) / float32(algorithmSpace) * 100
}
func loadInputFromFile() []string {
if len(os.Args) < 2 {
fmt.Println("Usage: go run main.go <input-file>")
os.Exit(1)
}
filepath := os.Args[1]
readFile, err := os.Open(filepath)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
scanner := bufio.NewScanner(readFile)
scanner.Split(bufio.ScanLines)
var inputs []string
for scanner.Scan() {
inputs = append(inputs, scanner.Text())
}
readFile.Close()
return inputs
}