-
Notifications
You must be signed in to change notification settings - Fork 12
/
lshensemble_test.go
104 lines (99 loc) · 2.15 KB
/
lshensemble_test.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
94
95
96
97
98
99
100
101
102
103
104
package lshensemble
import (
"sort"
"testing"
)
func Test_LshEnsembleEquiDepth(t *testing.T) {
domains := [][]string{
[]string{"a", "b", "c", "d"},
[]string{"e", "f", "g", "h"},
[]string{"i", "j", "k", "l"},
[]string{"p", "o", "n", "m"},
}
keys := []string{
"1",
"2",
"3",
"4",
}
domainRecords := make([]*DomainRecord, 0)
for i := range domains {
mh := NewMinhash(1, 128)
for _, v := range domains[i] {
mh.Push([]byte(v))
}
domainRecords = append(domainRecords, &DomainRecord{
Key: keys[i],
Size: len(domains[i]),
Signature: mh.Signature(),
})
}
sort.Sort(BySize(domainRecords))
index, err := BootstrapLshEnsembleEquiDepth(4, 128, 4, len(domainRecords),
Recs2Chan(domainRecords))
if err != nil {
t.Error(err)
}
querySig := domainRecords[0].Signature
querySize := domainRecords[0].Size
threshold := 0.9
var found bool
done := make(chan struct{})
defer close(done)
for key := range index.Query(querySig, querySize, threshold, done) {
if key == "1" {
found = true
break
}
}
if !found {
t.Fatal("unable to retrieve inserted key")
}
}
func Test_LshEnsembleOptimal(t *testing.T) {
domains := [][]string{
[]string{"a", "b", "c", "d"},
[]string{"e", "f", "g", "h"},
[]string{"i", "j", "k", "l"},
[]string{"p", "o", "n", "m"},
}
keys := []string{
"1",
"2",
"3",
"4",
}
domainRecords := make([]*DomainRecord, 0)
for i := range domains {
mh := NewMinhash(1, 128)
for _, v := range domains[i] {
mh.Push([]byte(v))
}
domainRecords = append(domainRecords, &DomainRecord{
Key: keys[i],
Size: len(domains[i]),
Signature: mh.Signature(),
})
}
sort.Sort(BySize(domainRecords))
index, err := BootstrapLshEnsembleOptimal(4, 128, 4,
func() <-chan *DomainRecord { return Recs2Chan(domainRecords) })
if err != nil {
t.Error(err)
}
querySig := domainRecords[0].Signature
querySize := domainRecords[0].Size
threshold := 0.9
var found bool
done := make(chan struct{})
defer close(done)
for key := range index.Query(querySig, querySize, threshold, done) {
if key == "1" {
found = true
break
}
}
if !found {
t.Fatal("unable to retrieve inserted key")
}
}