Comments (5)
Here's a basic proof of concept https://github.com/alco/hashids.js/commit/0b268e6873d24095a5c82548cd6d09c9e8ceb95d
The idea is to wrap input numbers in objects that provide the necessary arithmetic functions. By default the wrapper is only used internally and it simply uses native arithmetic. We also limit the range of input numbers (https://github.com/alco/hashids.js/commit/0b268e6873d24095a5c82548cd6d09c9e8ceb95d#diff-ac45510b2aa86482ae1d7551d7e6a36cR137) to ensure compatibility with implementations that use 64-bit integers or big integers.
If the user of the library passes in an object instead of a number, we don't check its range and assume it is an already wrapped number that implements all the required functions. This way, users will be able to extend the library with support for larger numbers without touching its implementation.
The only change to the public interface is in the decrypt
function (https://github.com/alco/hashids.js/commit/0b268e6873d24095a5c82548cd6d09c9e8ceb95d#diff-ac45510b2aa86482ae1d7551d7e6a36cR339) were we need to pass a wrapped zero value so that we know which type to use when decoding the string back into numbers.
from hashids.github.io.
I like the idea of letting the user extend Hashids with their own library to handle big numbers a lot. I think this a) keeps Hashids small and independent of 3rd party libs for those that don't care about handling big numbers and b) the user is free to pick their own implementation.
For example I know for JavaScript, there's a few:
https://github.com/jtobey/javascript-bignum
https://github.com/alexbardas/bignumber.js
http://jsfromhell.com/classes/bignumber
So, people might be inclined to use one over the other. Or maybe make their own.
@alco, thanks for the proof of concept. One followup question though - is there a reason it would be better to provide objects with math functions included to encode(), rather than provide a math lib to the constructor initially and provide strings of large ints to encode() after that?
from hashids.github.io.
@ivanakimov It makes sense to pass the functions to encode or the Hashids constructor, it just didn't cross my mind at the time. I'll take a look at the libraries you mentioned and will try building another prototype with support for big numbers.
from hashids.github.io.
For perl, apparently it only breaks for 2^60.
I can probably use bignum here for >= 2^60.
from hashids.github.io.
Closing since the project is moving. New algo has maxValue()
method to determine upper integer limit, which will differ per implementation.
from hashids.github.io.
Related Issues (20)
- Online coder/decoder HOT 2
- WordPress plugin broken HOT 1
- Live hashids demo HOT 1
- Kotlin version is worse than useless HOT 1
- Why list? HOT 3
- Comparing hashids for sorting? HOT 2
- Update link for Symfony HOT 1
- hash collision HOT 2
- Decrypting Hash key HOT 2
- Rust implementation is unmaintained HOT 2
- Hashids organization maintanance HOT 15
- Swift 4.2 not decoding properly HOT 1
- JavaScript page needs more docs HOT 1
- Add Postgres pure SQL solution HOT 1
- Demo on Codepen is broken HOT 2
- Implementation question, should the hashid be stored in the database instead of a PK? HOT 4
- Limit length of hash? HOT 2
- Shared set of hashids tests HOT 2
- Hello everybody, I've wrote a new Java library which is compatible with the latest "niieani/hashids.js" version HOT 1
- Add dark theme HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hashids.github.io.