yomorun / hashids-java

Hashids algorithm v1.0.0 implementation in Java
http://hashids.org
MIT License
1.02k stars 156 forks source link

Confusion about supported integer range #64

Closed patrickfav closed 5 years ago

patrickfav commented 5 years ago

The doc says:

decodable hashes from unsigned (long) integers

but then it says

All (long) integers need to be greater than or equal to zero

And the implementation caps the max number to 2^53 (0-9,007,199,254,740,992)

https://github.com/10cella/hashids-java/blob/162a263c8007652472bf1821a26d33190730f8a5/src/main/java/org/hashids/Hashids.java#L24


You currently support 53 bit long integers - I can only assume that is a bug? Java's primitives are always signed, so you have about 2^63 values in the plus and minus range. The most logical range would be 2^63 if you only want to support from 0 up and not make the caller convert to unsigned longs?

0x3333 commented 5 years ago

This is to be compatible with the original implementation.

Read Limitations on Readme.md, https://github.com/10cella/hashids-java#limitations

patrickfav commented 5 years ago

Ah I see, thanks. Maybe adapt the readme, because 'decodable hashes from unsigned (long) integers' is very misleading as it does not mean unsigned in the primitive type sense, but just that negative numbers are not allowed, it actually uses signed longs.

0x3333 commented 5 years ago

Feel free to create a PR, would help. Thanks!