-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathmain.go
49 lines (43 loc) · 1.08 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
package main
import (
"fmt"
"path/filepath"
"time"
"github.com/donng/Play-with-Data-Structures/13-Red-Black-Tree/07-Adding-Elements-in-Red-Black-Tree/AVLTree"
"github.com/donng/Play-with-Data-Structures/13-Red-Black-Tree/07-Adding-Elements-in-Red-Black-Tree/BSTMap"
"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)
fmt.Println("Total words: ", len(words))
// Test BST
startTime := time.Now()
bst := BSTMap.New()
for _, word := range words {
if bst.Contains(word) {
bst.Set(word, bst.Get(word).(int)+1)
} else {
bst.Add(word, 1)
}
}
for _, word := range words {
bst.Contains(word)
}
fmt.Println("BST: ", time.Now().Sub(startTime))
// Test AVL
startTime = time.Now()
avl := AVLTree.New()
for _, word := range words {
if avl.Contains(word) {
avl.Set(word, avl.Get(word).(int)+1)
} else {
avl.Add(word, 1)
}
}
for _, word := range words {
avl.Contains(word)
}
fmt.Println("AVL: ", time.Now().Sub(startTime))
}