Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buckets.max truncation in buckets.go #11

Open
mattlorimor opened this issue Dec 5, 2015 · 1 comment
Open

Buckets.max truncation in buckets.go #11

mattlorimor opened this issue Dec 5, 2015 · 1 comment

Comments

@mattlorimor
Copy link

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.

@tylertreat
Copy link
Owner

It can probably be a uint32 or uint64, but bucketSize should be capped to prevent an overflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants