-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathmain.go
93 lines (69 loc) · 1.92 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
90
91
92
93
package main
import (
"fmt"
"path/filepath"
"time"
"github.com/donng/Play-with-Data-Structures/10-Trie/08-Trie-Using-HashMap-and-Array/BSTSet"
"github.com/donng/Play-with-Data-Structures/10-Trie/08-Trie-Using-HashMap-and-Array/trie"
"github.com/donng/Play-with-Data-Structures/10-Trie/08-Trie-Using-HashMap-and-Array/trie2"
"github.com/donng/Play-with-Data-Structures/10-Trie/08-Trie-Using-HashMap-and-Array/trie3"
"github.com/donng/Play-with-Data-Structures/utils"
)
func main() {
fmt.Println("Pride and Prejudice")
filename1, _ := filepath.Abs("pride-and-prejudice.txt")
filename2, _ := filepath.Abs("a-tale-of-two-cities.txt")
words1 := utils.ReadFile(filename1)
words2 := utils.ReadFile(filename2)
words := append(words1, words2...)
for i := 0; i < 200; i++ {
fmt.Println(words[i])
}
startTime := time.Now()
bstSet := BSTSet.New()
for _, word := range words {
bstSet.Add(word)
}
for _, word := range words {
bstSet.Contains(word)
}
diffTime := time.Now().Sub(startTime)
fmt.Println("Total different words:", bstSet.GetSize())
fmt.Println("BSTSet:", diffTime)
// ---
startTime = time.Now()
t1 := trie.New()
for _, word := range words {
t1.Add(word)
}
for _, word := range words {
t1.Contains(word)
}
diffTime = time.Now().Sub(startTime)
fmt.Println("Total different words:", t1.GetSize())
fmt.Println("TreeMap Trie:", diffTime)
// ---
startTime = time.Now()
t2 := trie2.New()
for _, word := range words {
t2.Add(word)
}
for _, word := range words {
t2.Contains(word)
}
diffTime = time.Now().Sub(startTime)
fmt.Println("Total different words:", t2.GetSize())
fmt.Println("HashMap Trie:", diffTime)
// ---
startTime = time.Now()
t3 := trie3.New()
for _, word := range words {
t3.Add(word)
}
for _, word := range words {
t3.Contains(word)
}
diffTime = time.Now().Sub(startTime)
fmt.Println("Total different words:", t3.GetSize())
fmt.Println("array(Map) Trie:", diffTime)
}