areIdentical static method
Compares hashes until threshold mismatch is exceeded.
Used for fast comparison.
Implementation
static bool areIdentical(
ImageHash a,
ImageHash b,
double threshold,
) {
if (a.depth != b.depth ||
a.length != b.length ||
a.resolution != b.resolution) {
throw const HashIncompatibilityException(
message: 'Hash length mismatch',
);
}
final int length = a.length;
int notEqualCount = 0;
for (int i = 0; i < length; i++) {
if (a.hashList[i] != b.hashList[i]) {
notEqualCount++;
}
final mismatchPercent = notEqualCount / length;
final acceptablePercent = 1 - threshold;
if (mismatchPercent > acceptablePercent) {
return false;
}
}
return true;
}