renaming func
parent
fa46a571ec
commit
2bf760acd0
12
about.go
12
about.go
|
@ -6,11 +6,11 @@ package hyper
|
||||||
// of fuzzy hashes, as described in the following document:
|
// of fuzzy hashes, as described in the following document:
|
||||||
// https://vitali-fedulov.github.io/algorithm-for-hashing-high-dimensional-float-vectors.html
|
// https://vitali-fedulov.github.io/algorithm-for-hashing-high-dimensional-float-vectors.html
|
||||||
|
|
||||||
// A typical sequence of functions when using the package is:
|
// To use the package follow the sequence:
|
||||||
// 1) Params, 2) CubeSet or CentralCube, depending which one
|
// 1) Params, 2) CubeSet or CentralCube, depending which one
|
||||||
// is used for a database record and which one for a query,
|
// is used for a database record and which one for a query,
|
||||||
// 3) HashSet or CentralHash to get corresponding hashes
|
// 3) HashSet and Decimal to get corresponding hash set
|
||||||
// from results of (2).
|
// and central hash from results of (2). If Decimal hash
|
||||||
|
// is not suitable because of very large number of buckets
|
||||||
// It is possible to define own hashing function instead of
|
// or dimensions, use FNV1a to get both the hash set and
|
||||||
// using the default one.
|
// the central hash).
|
||||||
|
|
|
@ -12,14 +12,14 @@ import (
|
||||||
func Decimal(cube []int, numBuckets int) (h uint64) {
|
func Decimal(cube []int, numBuckets int) (h uint64) {
|
||||||
if numBuckets > 10 {
|
if numBuckets > 10 {
|
||||||
panic(`Decimal hash can only be used if
|
panic(`Decimal hash can only be used if
|
||||||
numBuckets <= 10. FVN1a can be used instead.`)
|
numBuckets <= 10. FNV1a can be used instead.`)
|
||||||
}
|
}
|
||||||
// Max uint64 equals 18446744073709551615,
|
// Max uint64 equals 18446744073709551615,
|
||||||
// therefore larger number of dimensions will overflow.
|
// therefore larger number of dimensions will overflow.
|
||||||
if len(cube) > 19 {
|
if len(cube) > 19 {
|
||||||
panic(`Decimal hash can only be used if
|
panic(`Decimal hash can only be used if
|
||||||
number of dimensions is less than 20.
|
number of dimensions is less than 20.
|
||||||
FVN1a hash can be used instead.`)
|
FNV1a hash can be used instead.`)
|
||||||
}
|
}
|
||||||
for _, v := range cube {
|
for _, v := range cube {
|
||||||
h = h*10 + uint64(v)
|
h = h*10 + uint64(v)
|
||||||
|
@ -27,10 +27,10 @@ func Decimal(cube []int, numBuckets int) (h uint64) {
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
// FVN1a hashes hypercubes with rare collisions,
|
// FNV1a hashes hypercubes with rare collisions,
|
||||||
// and should be used when Decimal cannot be used
|
// and should be used when Decimal cannot be used
|
||||||
// because of very large number of buckets or dimensions.
|
// because of very large number of buckets or dimensions.
|
||||||
func FVN1a(cube []int) uint64 {
|
func FNV1a(cube []int) uint64 {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
gob.NewEncoder(&b).Encode(cube)
|
gob.NewEncoder(&b).Encode(cube)
|
||||||
hash := fnv.New64a()
|
hash := fnv.New64a()
|
||||||
|
|
|
@ -15,9 +15,9 @@ func TestDecimal(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFVN1a(t *testing.T) {
|
func TestFNV1a(t *testing.T) {
|
||||||
buckets := []int{5, 59, 255, 9, 7, 12, 22, 31}
|
buckets := []int{5, 59, 255, 9, 7, 12, 22, 31}
|
||||||
hash := FVN1a(buckets)
|
hash := FNV1a(buckets)
|
||||||
want := uint64(13992349377752315208)
|
want := uint64(13992349377752315208)
|
||||||
if hash != want {
|
if hash != want {
|
||||||
t.Errorf(`Got %v, want %v.`, hash, want)
|
t.Errorf(`Got %v, want %v.`, hash, want)
|
||||||
|
@ -30,7 +30,7 @@ func TestHashSet(t *testing.T) {
|
||||||
{1, 0, 7, 3, 0, 0, 9},
|
{1, 0, 7, 3, 0, 0, 9},
|
||||||
{0, 0, 8, 3, 0, 0, 9},
|
{0, 0, 8, 3, 0, 0, 9},
|
||||||
{1, 0, 8, 3, 0, 0, 9}}
|
{1, 0, 8, 3, 0, 0, 9}}
|
||||||
hs := HashSet(tree, FVN1a)
|
hs := HashSet(tree, FNV1a)
|
||||||
want := []uint64{
|
want := []uint64{
|
||||||
14647827280143437043,
|
14647827280143437043,
|
||||||
17530493565529410009,
|
17530493565529410009,
|
||||||
|
|
Loading…
Reference in New Issue