Comments (8)
This change came from commit 1e280f1
Javascript can only support integers up to 53 bits because the number type uses floating points. Looks like it was just a bug at the time. I'll merge in the PR that fixes it.
from hashids.net.
JS implementation produces an empty string for this case, see https://playcode.io/880757/
However, changing this to be an actual long.MaxValue length of 19 fixes the issue (and btw why it is 12? that's incorrect)
hashids.net/src/Hashids.net/Hashids.cs
Line 19 in 1d574f6
@ullmark @manigandham what are your thoughts on this?
from hashids.net.
The library is a port of a javascript library, which has since been ported in a lot of languages. My initial code was me trying to make a translation to C# that was a map/translation of the javascript code. That way, if the algoritm changes (which it did, quite a bit at one point) it would be easier to update the .NET version.
That's basically one of the reasons for the code not being optimal both in sense of memory usage, and C# coding standards. In javascript Number doesn't fully map to our Int32 & Int64, so the reason for it being 12 is probably a mistake for us with support for long.
from hashids.net.
Many users map database IDs to C# long type and I'm afraid the library will lose some amount of users if we remove support for long
from hashids.net.
I've checked the Python implementation and it works fine with long.MaxValue, producing the same result as if we changed MaxNumberHashLength
to 19:
from hashids.net.
yeah, I didn't mean remove it... I was just explaining why it probably was 12. I also think that we've strayed away from keeping a "similar" codebase, so making it more C# is also 👍
from hashids.net.
yeah, I didn't mean remove it... I was just explaining why it probably was 12. I also think that we've strayed away from keeping a "similar" codebase, so making it more C# is also 👍
Oh, I see. I misunderstood that as "long support was a mistake", my bad
from hashids.net.
Confirming that Go version returns the same:
package main
import (
"fmt"
"github.com/speps/go-hashids/v2"
)
func main() {
hd := hashids.NewData()
hd.Salt = "salt"
hd.Alphabet = "0123456789ABCDEF"
h, _ := hashids.NewWithData(hd)
e, _ := h.EncodeInt64([]int64{9223372036854775807})
fmt.Println(e)
d, _ := h.DecodeWithError(e)
fmt.Println(d)
}
58E9BDD9A7598254DA4E
[9223372036854775807]
from hashids.net.
Related Issues (20)
- Optimization: decode a single ID without allocating an array HOT 4
- how to Creates short unique ids from integers. (only positive numbers & zero) HOT 1
- Using multiple options for encoding/decoding HOT 1
- Attempting to Decode short strings results in incorrect exceptions being produced HOT 7
- Hashids not generating with proper minhashlength HOT 1
- HashIds not working after adding custom Output formatter HOT 2
- How do I get HashIDs of a specific length? HOT 1
- How use id with Guid/UUID/Sequential Guid HOT 1
- Is there a guarantee of encoded sequence uniqueness with differing salts? HOT 4
- Insufficient Variation In Generated HashIds HOT 1
- Document the effective character limit of the salt HOT 5
- Decoding input smaller than minHashLength unhandled exceptions are thrown HOT 4
- Json support? HOT 3
- Regarding HashidsNet HOT 1
- Website seems down HOT 2
- Valid use-case for library? HOT 1
- Is this lib still being maintained? HOT 2
- Decode null string thows NullReferenceException HOT 1
- Same id generated for different integers HOT 3
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.net.