-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathmain.go
50 lines (37 loc) · 980 Bytes
/
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
package main
import (
"fmt"
"path/filepath"
"time"
"github.com/donng/Play-with-Data-Structures/10-Trie/04-Prefix-in-Trie/BSTSet"
"github.com/donng/Play-with-Data-Structures/10-Trie/04-Prefix-in-Trie/trie"
"github.com/donng/Play-with-Data-Structures/utils"
)
func main() {
fmt.Println("Pride and Prejudice")
filename, _ := filepath.Abs("pride-and-prejudice.txt")
words := utils.ReadFile(filename)
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()
t := trie.New()
for _, word := range words {
t.Add(word)
}
for _, word := range words {
t.Contains(word)
}
diffTime = time.Now().Sub(startTime)
fmt.Println("Total different words:", t.GetSize())
fmt.Println("BSTSet:", diffTime)
}