-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
54 lines (44 loc) · 1.1 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
package main
import (
"bufio"
"fmt"
"os"
"path/filepath"
"log"
"github.com/seiflotfy/hyperbitbit"
)
func main() {
files, err := filepath.Glob(fmt.Sprintf("%s/*", os.Args[1]))
if err != nil {
log.Fatalln(err)
return
}
totalUnique := map[string]bool{}
totalHBB := hyperbitbit.New()
for _, f := range files {
f, err := os.Open(f)
if err != nil {
log.Fatalln(err)
return
}
reader := bufio.NewReader(f)
unique := map[string]bool{}
hbb := hyperbitbit.New()
for {
text, _, err := reader.ReadLine()
if err != nil {
break
}
unique[string(text)] = true
totalUnique[string(text)] = true
hbb.Add([]byte(text))
totalHBB.Add([]byte(text))
}
est := hbb.Cardinality()
ratio := fmt.Sprintf("%.2f%%", 100*(1-float64(len(unique))/float64(est)))
log.Println("\n\tfile: ", f.Name(), "\n\texact:", len(unique), "\n\testimate:", est, "\n\tratio:", ratio)
}
est := totalHBB.Cardinality()
ratio := fmt.Sprintf("%.2f%%", 100*(1-float64(len(totalUnique))/float64(est)))
log.Println("\n\ttotal\n\texact:", len(totalUnique), "\n\testimate:", est, "\n\tratio:", ratio)
}