Skip to content

Buckets.max truncation in buckets.go #11

@mattlorimor

Description

@mattlorimor

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions