BoomFilters
BoomFilters copied to clipboard
Buckets.max truncation in buckets.go
Buckets.max
can never be larger than 255
even though the math allows for larger numbers. This is because the type of Buckets.max
is set to uint8
. Obviously, if this behavior is intended, feel free to close this.
The math for setting Buckets.max
is:
(1 << bucketSize) -1
where bucketSize
is a uint8
.
(1 << bucketSize) - 1
will have these outputs given a uint8
:
for i := 0; i < 255; i++ {
fmt.Println(uint64((1 << uint8(i)) - 1))
}
input | output |
---|---|
0 | 0 |
1 | 1 |
2 | 3 |
3 | 7 |
4 | 15 |
5 | 31 |
6 | 63 |
7 | 127 |
8 | 255 |
... | ... |
62 | 4611686018427387903 |
63 | 9223372036854775807 |
64 | 18446744073709551615 |
Anything past 64
would overflow a uint64
.
I'm not sure what the best solution would be (or even if Buckets.max
allowing nothing larger than 255
is even a problem). Should Buckets.max
be changed to a uint
? A uint64
? I'm not that familiar with what maximum, if any, should be enforced on Buckets.max
.
It can probably be a uint32 or uint64, but bucketSize
should be capped to prevent an overflow.