-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathmain.go
44 lines (35 loc) · 1.13 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
package main
import (
"fmt"
"path/filepath"
"time"
"github.com/donng/Play-with-Data-Structures/07-Set-and-Map/08-More-about-Map/BSTMap"
"github.com/donng/Play-with-Data-Structures/07-Set-and-Map/08-More-about-Map/Map"
"github.com/donng/Play-with-Data-Structures/07-Set-and-Map/08-More-about-Map/linkedlistmap"
"github.com/donng/Play-with-Data-Structures/utils"
)
func testSet(p Map.Map, filename string) time.Duration {
startTime := time.Now()
words := utils.ReadFile(filename)
fmt.Println("Total words:", len(words))
for _, word := range words {
if p.Contains(word) {
p.Set(word, p.Get(word).(int)+1)
} else {
p.Add(word, 1)
}
}
fmt.Println("Total different words: ", p.GetSize())
fmt.Println("Frequency of PRIDE:", p.Get("pride"))
fmt.Println("Frequency of PREJUDICE: ", p.Get("prejudice"))
return time.Now().Sub(startTime)
}
func main() {
filename, _ := filepath.Abs("pride-and-prejudice.txt")
bstMap := BSTMap.New()
time1 := testSet(bstMap, filename)
fmt.Println("BST map :", time1)
linkedListMap := linkedlistmap.New()
time2 := testSet(linkedListMap, filename)
fmt.Println("linkedListMap set:", time2)
}