Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tuple/hashtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package tuple

import (
"errors"
"fmt"
"math"

"github.com/apache/datasketches-go/internal"
Expand All @@ -41,7 +40,8 @@ var (
ErrKeyNotFoundAndNoEmptySlots = errors.New("key not found and no empty slots")
// ErrZeroHashValue is used to indicate that the hash value is zero.
// Zero is a reserved value for empty slots in the hash table.
ErrZeroHashValue = errors.New("zero hash value")
ErrZeroHashValue = errors.New("zero hash value")
ErrHashExceedsTheta = errors.New("hash exceeds theta")
)

type entry[S Summary] struct {
Expand Down Expand Up @@ -104,7 +104,7 @@ func (t *hashtable[S]) HashStringAndScreen(data string) (uint64, error) {
h1, _ := internal.HashCharSliceMurmur3([]byte(data), 0, len(data), t.seed)
hash := h1 >> 1
if hash >= t.theta {
return 0, fmt.Errorf("hash %d is greater than or equal to theta %d", hash, t.theta)
return 0, ErrHashExceedsTheta
}
if hash == 0 {
return 0, ErrZeroHashValue
Expand All @@ -118,7 +118,7 @@ func (t *hashtable[S]) HashInt32AndScreen(data int32) (uint64, error) {
h1, _ := internal.HashInt32SliceMurmur3([]int32{data}, 0, 1, t.seed)
hash := h1 >> 1
if hash >= t.theta {
return 0, fmt.Errorf("hash %d is greater than or equal to theta %d", hash, t.theta)
return 0, ErrHashExceedsTheta
}
if hash == 0 {
return 0, ErrZeroHashValue
Expand All @@ -132,7 +132,7 @@ func (t *hashtable[S]) HashInt64AndScreen(data int64) (uint64, error) {
h1, _ := internal.HashInt64SliceMurmur3([]int64{data}, 0, 1, t.seed)
hash := h1 >> 1
if hash >= t.theta {
return 0, fmt.Errorf("hash %d is greater than or equal to theta %d", hash, t.theta)
return 0, ErrHashExceedsTheta
}
if hash == 0 {
return 0, ErrZeroHashValue
Expand All @@ -146,7 +146,7 @@ func (t *hashtable[S]) HashBytesAndScreen(data []byte) (uint64, error) {
h1, _ := internal.HashByteArrMurmur3(data, 0, len(data), t.seed)
hash := h1 >> 1
if hash >= t.theta {
return 0, fmt.Errorf("hash %d is greater than or equal to theta %d", hash, t.theta)
return 0, ErrHashExceedsTheta
}
if hash == 0 {
return 0, ErrZeroHashValue
Expand Down
8 changes: 4 additions & 4 deletions tuple/hashtable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestHashtable_HashStringAndScreen(t *testing.T) {
data: "test",
theta: 1,
seed: theta.DefaultSeed,
wantErrMsg: "is greater than or equal to theta 1",
wantErrMsg: "hash exceeds theta",
},
{
name: "different seed",
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestHashtable_HashInt32AndScreen(t *testing.T) {
data: 12345,
theta: 1,
seed: theta.DefaultSeed,
wantErrMsg: "is greater than or equal to theta 1",
wantErrMsg: "hash exceeds theta",
},
{
name: "different seed",
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestHashtable_HashInt64AndScreen(t *testing.T) {
data: 1234567890,
theta: 1,
seed: theta.DefaultSeed,
wantErrMsg: "is greater than or equal to theta 1",
wantErrMsg: "hash exceeds theta",
},
{
name: "different seed",
Expand Down Expand Up @@ -337,7 +337,7 @@ func TestHashtable_HashBytesAndScreen(t *testing.T) {
data: []byte{1, 2, 3, 4, 5},
theta: 100,
seed: theta.DefaultSeed,
wantErrMsg: "is greater than or equal to theta 1",
wantErrMsg: "hash exceeds theta",
},
{
name: "different seed",
Expand Down
Loading