Comments (3)
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.
@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.
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)
- Release for inference change HOT 1
- Add const BuiltList<T>.empty() HOT 6
- Add ListBuilder.indexOf HOT 1
- Allow BuiltList<T?> HOT 2
- BuiltList first & elementAt should be nullable HOT 3
- Custom serializer for BuiltMap HOT 1
- Tighten generics HOT 2
- Use `@checkResult` annotation
- Cannot rebuild a BuiltSet entry in BuiltMap HOT 7
- (Question) how to rebuild every value in BuiltList? HOT 1
- Why is the return operator[] on BuiltSetMultimap nullable?
- Docs for `asList` misleading
- Unable to update nested BuiltList inside ListBuilder HOT 5
- [Feature Request/ Question] Native Support for json_serializable / json_annotation HOT 3
- Found 1 file excluded from sound null safety HOT 1
- Shouldn't BuiltMap<String, BuiltSet<int>> work out of the box? HOT 9
- BuiltMap.containsKey should accept `Object?` HOT 1
- Built Collections deep comparison question HOT 3
- asList() always returns a new instance HOT 1
- tighten `MapBuilder` factory parameter HOT 2
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 built_collection.dart.