In my project , the best distance is 12,so i reform the stuct of store6 . I add a function ,codes are below.
func (s *Store6) FindWithX(sig uint64, distance int) table {
// empty store
if s.Count == 0 {
return nil
}
var ids []uint64
// TODO(dgryski): search in parallel
t := 0
var p uint64
for i := 0; i < 6; i++ {
p = sig
ids = append(ids, s.unshuffleList(s.rhashes[t].find(p, mask6_9_8, distance), t)...)
t++
p = (sig & 0xff80007fffffffff) | (sig & 0x007f800000000000 >> 8) | (sig & 0x00007f8000000000 << 8)
ids = append(ids, s.unshuffleList(s.rhashes[t].find(p, mask6_9_8, distance), t)...)
t++
p = (sig & 0xff807f807fffffff) | (sig & 0x007f800000000000 >> 16) | (sig & 0x0000007f80000000 << 16)
ids = append(ids, s.unshuffleList(s.rhashes[t].find(p, mask6_9_8, distance), t)...)
t++
p = (sig & 0xff807fff807fffff) | (sig & 0x007f800000000000 >> 24) | (sig & 0x000000007f800000 << 24)
ids = append(ids, s.unshuffleList(s.rhashes[t].find(p, mask6_9_8, distance), t)...)
t++
p = (sig & 0xff807fffff807fff) | (sig & 0x007f800000000000 >> 32) | (sig & 0x00000000007f8000 << 32)
ids = append(ids, s.unshuffleList(s.rhashes[t].find(p, mask6_9_8, distance), t)...)
t++
p = (sig & 0xff807fffffff807f) | (sig & 0x007f800000000000 >> 40) | (sig & 0x0000000000007f80 << 40)
ids = append(ids, s.unshuffleList(s.rhashes[t].find(p, mask6_9_8, distance), t)...)
t++
p = (sig & 0xff80ffffffffff80) | (sig & 0x007f000000000000 >> 48) | (sig & 0x000000000000007f << 48)
ids = append(ids, s.unshuffleList(s.rhashes[t].find(p, mask6_9_7, distance), t)...)
t++
sig = (sig << 9) | (sig >> (64 - 9))
}
p = sig
ids = append(ids, s.unshuffleList(s.rhashes[t].find(p, mask6_10_8, distance), t)...)
t++
p = (sig & 0xffc0003fffffffff) | (sig & 0x003fc00000000000 >> 8) | (sig & 0x00003fc000000000 << 8)
ids = append(ids, s.unshuffleList(s.rhashes[t].find(p, mask6_10_8, distance), t)...)
t++
p = (sig & 0xffc03fc03fffffff) | (sig & 0x003fc00000000000 >> 16) | (sig & 0x0000003fc0000000 << 16)
ids = append(ids, s.unshuffleList(s.rhashes[t].find(p, mask6_10_8, distance), t)...)
t++
p = (sig & 0xffc03fffc03fffff) | (sig & 0x003fc00000000000 >> 24) | (sig & 0x000000003fc00000 << 24)
ids = append(ids, s.unshuffleList(s.rhashes[t].find(p, mask6_10_8, distance), t)...)
t++
p = (sig & 0xffc03fffffc03fff) | (sig & 0x003fc00000000000 >> 32) | (sig & 0x00000000003fc000 << 32)
ids = append(ids, s.unshuffleList(s.rhashes[t].find(p, mask6_10_8, distance), t)...)
t++
p = (sig & 0xffc07fffffffc07f) | (sig & 0x003f800000000000 >> 40) | (sig & 0x0000000000003f80 << 40)
ids = append(ids, s.unshuffleList(s.rhashes[t].find(p, mask6_10_7, distance), t)...)
t++
p = (sig & 0xffc07fffffffff80) | (sig & 0x003f800000000000 >> 47) | (sig & 0x000000000000007f << 47)
ids = append(ids, s.unshuffleList(s.rhashes[t].find(p, mask6_10_7, distance), t)...)
t++
ids = unique(ids)
var ts table
for _, v := range ids {
ts = append(ts, s.docids.search(v)...)
}
return ts
}
But , when i tested the demo ,i found a problem , test's code and result is below.
Test:
func TestAdd6(t *testing.T) {
s := New6(size, NewU64Slice)
testRealAdd(t, s, size, queries, 6)
}
func testRealAdd(t *testing.T, s Storage, size, queries, d int) {
s.Add(1189710714089908775, 111)
for i := 0; i < 20; i++ {
s.Add(uint64(rand.Int63()), uint64(i))
}
s.Finish()
table := s.FindWithX(6451357090505977391, 12)
t.Logf("result %+v", table)
}
Found NOTHING!,the Hamming distance 1189710714089908775 and 6451357090505977391 is 12.