Giter Site home page Giter Site logo

Comments (6)

lantiga avatar lantiga commented on July 18, 2024

In general, any hash will provide the following guarantee: if A and B have different hashes, then A and B are not equivalent (for some definition of equivalence). They don't however provide you with the converse, i.e. that if A and B have the same hashes then A and B are equivalent. Of course there can be better and worse hashing algorithms, e.g. count is a lousy hash for a vector, while Clojure 1.6 just obtained a performance gain by introducing a new hashing algorithm that leads to fewer collisions.

So you shouldn't rely on hashes as unique keys unless you design for collision, e.g. for associative structures you can use hashes as keys and a list of objects as values (rather than just one object) and then resort to a linear search when you have to disambiguate.

In the case of react component keys, object hashes alone are probably not a good choice.

from mori.

eyston avatar eyston commented on July 18, 2024

Thanks. I was a bit surprised by the frequency of collisions so figured I'd ask :)

from mori.

lantiga avatar lantiga commented on July 18, 2024

Apparently there's ongoing work for supporting the new Clojure 1.6 hashing in ClojureScript: http://dev.clojure.org/jira/browse/CLJS-754
Once this is merged collisions will be a lot fewer.

from mori.

swannodette avatar swannodette commented on July 18, 2024

Yes hash collisions will be greatly diminished soon, that said I would still not use the hash code as a React key.

from mori.

swannodette avatar swannodette commented on July 18, 2024

Closing this as it's not really a Mori issue. This will be resolved when it's resolved in ClojureScript itself.

from mori.

eyston avatar eyston commented on July 18, 2024

Agreed. I'll take a look at how some other libraries handle the key thing. Thanks for quick responses.

from mori.

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.