-
Notifications
You must be signed in to change notification settings - Fork 216
/
main.go
77 lines (63 loc) · 1.42 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
package main
import (
"bufio"
"fmt"
"os"
"runtime"
"sort"
)
func stats(i int) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Fprintf(os.Stderr, "%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n",
float64(i), // 1
float64(m.Mallocs)/1000., // 2
float64(m.Frees)/1000., // 3
float64(m.HeapObjects), // 4
float64(m.HeapSys), // 5
float64(m.HeapAlloc), // 6
float64(m.HeapIdle), // 7
float64(m.NumGC), // 8
float64(m.Alloc), // 9
float64(m.TotalAlloc), // 10
float64(m.Sys), // 11
float64(m.Lookups), // 12
float64(m.LastGC), // 13
float64(m.NextGC), // 14
float64(m.PauseTotalNs), // 15
)
}
func main() {
stdin := bufio.NewReader(os.Stdin)
// Change here to
// cache := iLRUCache{} for internal
// or
// cache := eLRUCache{} for external
cache := iLRUCache{}
cache.Init(1000)
var i = 0
for ; true; i++ {
line, err := stdin.ReadBytes('\n')
if err != nil {
break
}
key := string(line[:len(line)-1])
count := 0
if v, _ := cache.Get(key); v != nil {
count = v.(int)
}
cache.Set(key, count+1)
stats(i)
}
stats(i)
keys := make([]string, 0, len(cache.table))
for k, _ := range cache.table {
keys = append(keys, k)
}
fmt.Fprintf(os.Stderr, "[*] Results\n")
sort.Strings(keys)
for _, k := range keys {
v, _ := cache.Get(k)
fmt.Printf("%7d\t%s\n", v.(int), k)
}
}