renaming func

master
Vitali Fedulov 2021-12-19 05:04:50 +01:00
parent fa46a571ec
commit 2bf760acd0
3 changed files with 13 additions and 13 deletions

View File

@ -6,11 +6,11 @@ package hyper
// of fuzzy hashes, as described in the following document:
// 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
// is used for a database record and which one for a query,
// 3) HashSet or CentralHash to get corresponding hashes
// from results of (2).
// It is possible to define own hashing function instead of
// using the default one.
// 3) HashSet and Decimal to get corresponding hash set
// and central hash from results of (2). If Decimal hash
// is not suitable because of very large number of buckets
// or dimensions, use FNV1a to get both the hash set and
// the central hash).

View File

@ -12,14 +12,14 @@ import (
func Decimal(cube []int, numBuckets int) (h uint64) {
if numBuckets > 10 {
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,
// therefore larger number of dimensions will overflow.
if len(cube) > 19 {
panic(`Decimal hash can only be used if
number of dimensions is less than 20.
FVN1a hash can be used instead.`)
FNV1a hash can be used instead.`)
}
for _, v := range cube {
h = h*10 + uint64(v)
@ -27,10 +27,10 @@ func Decimal(cube []int, numBuckets int) (h uint64) {
return h
}
// FVN1a hashes hypercubes with rare collisions,
// FNV1a hashes hypercubes with rare collisions,
// and should be used when Decimal cannot be used
// because of very large number of buckets or dimensions.
func FVN1a(cube []int) uint64 {
func FNV1a(cube []int) uint64 {
var b bytes.Buffer
gob.NewEncoder(&b).Encode(cube)
hash := fnv.New64a()

View File

@ -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}
hash := FVN1a(buckets)
hash := FNV1a(buckets)
want := uint64(13992349377752315208)
if 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},
{0, 0, 8, 3, 0, 0, 9},
{1, 0, 8, 3, 0, 0, 9}}
hs := HashSet(tree, FVN1a)
hs := HashSet(tree, FNV1a)
want := []uint64{
14647827280143437043,
17530493565529410009,