Comments (7)
hashCode is also overridden, and forwards to _calcHashCode, which uses a ListEquality to compare byte for byte.
Do you have a specific test case that is showing a false positive?
from flutter_blue.
Closing for now. We can reopen if needed.
from flutter_blue.
I really looks like ListEquality.hash does a conventional hash rather than returning an int value that is a unique representation of the input value (Furthermore, ListEquality.hash is returning a 63 bit value, which is way fewer bits than in a GUID (see the & _HASH_MASK))
Source:
https://github.com/dart-lang/collection/blob/master/lib/src/equality.dart
class ListEquality implements Equality<List> {
// ....
int hash(List list) {
if (list == null) return null.hashCode;
// Jenkins's one-at-a-time hash function.
// This code is almost identical to the one in IterableEquality, except
// that it uses indexing instead of iterating to get the elements.
int hash = 0;
for (int i = 0; i < list.length; i++) {
int c = _elementEquality.hash(list[i]);
hash = (hash + c) & _HASH_MASK;
hash = (hash + (hash << 10)) & _HASH_MASK;
hash ^= (hash >> 6);
}
hash = (hash + (hash << 3)) & _HASH_MASK;
hash ^= (hash >> 11);
hash = (hash + (hash << 15)) & _HASH_MASK;
return hash;
}
}
from flutter_blue.
Interesting, I wonder what the collision rate would be, and if it's something to be concerned with. I'll reopen for now.
Consider looking into what the UUID lib does for this.
Related to #10
from flutter_blue.
Given that GUIDs have 128 bits and the hash codes you are using have 63 bits, each GUID will collide on average with 2^65 other GUIDs (36893488147419103232 other GUIDs).
As a general 'Globally Unique ID' class, having an '==' like this would kind of wreck the 'Unique ID' property.
However, given, that this is a flutter blue specific class, and that each program would only know about relatively few UUIDs (devices it has seen, service ids, characteristic ids etc), actual collisions will probably be pretty small.
However, if they do happen, it will be a really weird and hard to reproduce bug (for example a user will setup a fitness application with the UUID of the heart rate monitor. But it will just happen to collide with the UUID of a wireless camera - and you will have a really weird, hard to track down problem only effecting one user. Personally, I find these kinds of situations much more terrifying than a common bug - which one finds in testing and fixes.
For my purposes, I am just comparing the .toString () values of GUIDs - so it is not actually a problem for me.
On the other hand adding a check if ListEquality.equals () after the hash checks will add essentially no overhead.
Thank you for writing flutter blue - it is a massive relief to be free of Android SDK programming (which I am not a fan of), and I couldn't make the move until you wrote flutter blue.
from flutter_blue.
I'm also afraid certain 'potential' false-positives on the current implementation.
Apparently, if equals(a, b) then hash(a) == hash(b)
is true as mentioned on ListEquality hash method but the reverse is not always true.
The only and correct way is to compare all the bytes one by one though it is assumed to be slower than just comparing hashes.
from flutter_blue.
I think, the operator == should be like this:
operator ==(other) =>
other is Guid && this.hashCode == other.hashCode && (const ListEquality<int>()).equals(_bytes, other._bytes);
from flutter_blue.
Related Issues (20)
- Gamepanel gp isn't null buy I still get a null pointer exception when I call speak()
- 🚨🚨🚨 [Public Service Announcement] flutter_blue_plus is the successor to this library 🚨🚨🚨
- Command execution not working?
- C:\Users\ABS\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_blue_plus-1.15.2\android\src\main\java\com\boskokg\flutter_blue_plus\FlutterBluePlusPlugin.java uses or overrides a deprecated API.
- Help to resolve this error HOT 3
- ITMS-90863: Apple silicon Macs support issue HOT 3
- App crash when try readValue on android but on windows work fine
- 🚨🚨🚨 [Public Service Announcement] flutter_blue is deprecated❗Use flutter_blue_plus 🚨🚨🚨 HOT 1
- reading return value from
- 🚨🚨🚨 [Public Service Announcement] flutter_blue is deprecated❗Use flutter_blue_plus 🚨🚨🚨
- Could not resolve all files for configuration ':lib-transparency-api:protobufToolsLocator_protoc'. HOT 1
- 🚨🚨🚨 [Public Service Announcement] flutter_blue is deprecated❗Use flutter_blue_plus 🚨🚨🚨
- Execution failed for task ':flutter_blue:generateDebugProto'. HOT 2
- 🚨🚨🚨 [Public Service Announcement] flutter_blue is deprecated❗Use flutter_blue_plus 🚨🚨🚨
- How to connect the device that specifies the MAC address? For example, scan a QR code to get the MAC address of the device,
- 🚨🚨🚨 [Public Service Announcement] flutter_blue is deprecated❗Use flutter_blue_plus 🚨🚨🚨
- when i add package to my project flutter pub get not work
- 🚨🚨🚨 [Public Service Announcement] flutter_blue is deprecated❗Use flutter_blue_plus 🚨🚨🚨
- Zero services for ios
- Remove references to deprecated v1 Android embedding
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 flutter_blue.