Git Product home page Git Product logo

Comments (3)

davidmorgan avatar davidmorgan commented on May 1, 2024

Hi Daniel,

Thanks for the detailed issue.

Such an equals method will work most of the time, but it fails as soon as there are hash collisions. That is, if different lists end up with the same hash. Since we're using a 32 bit hash, the best case is a one in four billion chance of a collision. (If the hash function is perfect).

That sounds like a lot, but due to the birthday paradox you need to square root it for collections. So actually the number of hashes that will lead to a problem is only 2^16, i.e. 65536. This is a number that is easily small enough to turn up in practice.

An equals method is supposed to work 100% of the time :) ... if people want "probably equals", which would indeed be much faster, they can directly check the hashCode. This will probably happen as part of an algorithm that takes into account the probability of collisions and does check using "equals" when needed.

from built_collection.dart.

daniel-v avatar daniel-v commented on May 1, 2024

@davidmorgan, thanks for the answer. Since it's not really an issue, we can close this :)

TL;DR: hashCode match does not guarantee equality, hence the algorithm.

from built_collection.dart.

davidmorgan avatar davidmorgan commented on May 1, 2024

It's interesting to think about adding a wide enough hash that it can be used for equality, though. You could keep 128 bit hashes, then you should be okay with ~2^64 items. Plenty :)

I think we should have a use case for it first, though, i.e. an algorithm/system that's slow because of equality on lists and needs speeding up.

For UI code of the type I work on lists are usually limited in size to what you can display to a user, and the major cost is rendering rather than data processing. So, not much benefit to be had.

from built_collection.dart.

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.