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
7 changes: 5 additions & 2 deletions filters/bloom_filter_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ import (
"encoding/binary"
"fmt"
"math"

"github.com/apache/datasketches-go/internal"
)

// Default seed value for hash functions
// DefaultSeed is the default seed value for hash functions
const DefaultSeed = uint64(9001)

var maxBits = uint64((math.MaxInt32 - internal.FamilyEnum.BloomFilter.MaxPreLongs) * 64)

// bloomFilterOptions holds optional parameters for filter construction.
type bloomFilterOptions struct {
seed uint64
Expand Down Expand Up @@ -59,7 +63,6 @@ func NewBloomFilterBySize(numBits uint64, numHashes uint16, opts ...BloomFilterO
}

// Check for overflow
maxBits := uint64(math.MaxInt32-32) * 64
if numBits > maxBits {
return nil, fmt.Errorf("numBits exceeds maximum allowed size")
}
Expand Down
4 changes: 4 additions & 0 deletions filters/bloom_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func TestInvalidConstructorArguments(t *testing.T) {
_, err = NewBloomFilterBySize(1<<60, 3)
assert.Error(t, err)

// numBits exceeds maxBits by 1
_, err = NewBloomFilterBySize(maxBits+1, 3)
assert.ErrorContains(t, err, "numBits exceeds maximum allowed size")

// Invalid FPP
_, err = NewBloomFilterByAccuracy(1000, 0.0)
assert.Error(t, err)
Expand Down
Loading