Coder Social home page Coder Social logo

Comments (8)

manigandham avatar manigandham commented on May 31, 2024 2

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.

KeterSCP avatar KeterSCP commented on May 31, 2024 1

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)

private const int MaxNumberHashLength = 12; // Length of long.MaxValue;

@ullmark @manigandham what are your thoughts on this?

from hashids.net.

ullmark avatar ullmark commented on May 31, 2024

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.

KeterSCP avatar KeterSCP commented on May 31, 2024

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.

KeterSCP avatar KeterSCP commented on May 31, 2024

I've checked the Python implementation and it works fine with long.MaxValue, producing the same result as if we changed MaxNumberHashLength to 19:

C#:
image

Python:
image

from hashids.net.

ullmark avatar ullmark commented on May 31, 2024

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.

KeterSCP avatar KeterSCP commented on May 31, 2024

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.

manigandham avatar manigandham commented on May 31, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.