Метод hash
- @Since("2.14")
- Object? object1,
- Object? object2,
- [Object? object3 = sentinelValue,
- Object? object4 = sentinelValue,
- Object? object5 = sentinelValue,
- Object? object6 = sentinelValue,
- Object? object7 = sentinelValue,
- Object? object8 = sentinelValue,
- Object? object9 = sentinelValue,
- Object? object10 = sentinelValue,
- Object? object11 = sentinelValue,
- Object? object12 = sentinelValue,
- Object? object13 = sentinelValue,
- Object? object14 = sentinelValue,
- Object? object15 = sentinelValue,
- Object? object16 = sentinelValue,
- Object? object17 = sentinelValue,
- Object? object18 = sentinelValue,
- Object? object19 = sentinelValue,
- Object? object20 = sentinelValue]
Создаёт комбинированный хэш-код для нескольких объектов.
Хэш-код вычисляется для всех фактически переданных аргументов, даже если они null, путём численного объединения Object.hashCode каждого аргумента.
Пример:
class SomeObject {
final Object a, b, c;
SomeObject(this.a, this.b, this.c);
bool operator ==(Object other) =>
other is SomeObject && a == other.a && b == other.b && c == other.c;
int get hashCode => Object.hash(a, b, c);
} Вычисленное значение будет согласованным, когда функция вызывается с одними и теми же аргументами несколько раз во время выполнения одной программы.
Значение хэша, сгенерированное этой функцией, не гарантируется стабильным при разных запусках одной и той же программы или между кодом, запущенным в разных изолятах одной программы. Точный алгоритм может отличаться на разных платформах или между разными версиями библиотек платформы, и он может зависеть от значений, которые меняются при каждом запуске программы.
Функция hashAll даёт такой же результат, как и эта функция, когда она вызывается с коллекцией, содержащей фактические аргументы этой функции в том же порядке.
Реализация
@Since("2.14")
static int hash(Object? object1, Object? object2,
[Object? object3 = sentinelValue,
Object? object4 = sentinelValue,
Object? object5 = sentinelValue,
Object? object6 = sentinelValue,
Object? object7 = sentinelValue,
Object? object8 = sentinelValue,
Object? object9 = sentinelValue,
Object? object10 = sentinelValue,
Object? object11 = sentinelValue,
Object? object12 = sentinelValue,
Object? object13 = sentinelValue,
Object? object14 = sentinelValue,
Object? object15 = sentinelValue,
Object? object16 = sentinelValue,
Object? object17 = sentinelValue,
Object? object18 = sentinelValue,
Object? object19 = sentinelValue,
Object? object20 = sentinelValue]) {
if (sentinelValue == object3) {
return SystemHash.hash2(object1.hashCode, object2.hashCode, _hashSeed);
}
if (sentinelValue == object4) {
return SystemHash.hash3(
object1.hashCode, object2.hashCode, object3.hashCode, _hashSeed);
}
if (sentinelValue == object5) {
return SystemHash.hash4(object1.hashCode, object2.hashCode,
object3.hashCode, object4.hashCode, _hashSeed);
}
if (sentinelValue == object6) {
return SystemHash.hash5(object1.hashCode, object2.hashCode,
object3.hashCode, object4.hashCode, object5.hashCode, _hashSeed);
}
if (sentinelValue == object7) {
return SystemHash.hash6(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
_hashSeed);
}
if (sentinelValue == object8) {
return SystemHash.hash7(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
object7.hashCode,
_hashSeed);
}
if (sentinelValue == object9) {
return SystemHash.hash8(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
object7.hashCode,
object8.hashCode,
_hashSeed);
}
if (sentinelValue == object10) {
return SystemHash.hash9(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
object7.hashCode,
object8.hashCode,
object9.hashCode,
_hashSeed);
}
if (sentinelValue == object11) {
return SystemHash.hash10(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
object7.hashCode,
object8.hashCode,
object9.hashCode,
object10.hashCode,
_hashSeed);
}
if (sentinelValue == object12) {
return SystemHash.hash11(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
object7.hashCode,
object8.hashCode,
object9.hashCode,
object10.hashCode,
object11.hashCode,
_hashSeed);
}
if (sentinelValue == object13) {
return SystemHash.hash12(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
object7.hashCode,
object8.hashCode,
object9.hashCode,
object10.hashCode,
object11.hashCode,
object12.hashCode,
_hashSeed);
}
if (sentinelValue == object14) {
return SystemHash.hash13(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
object7.hashCode,
object8.hashCode,
object9.hashCode,
object10.hashCode,
object11.hashCode,
object12.hashCode,
object13.hashCode,
_hashSeed);
}
if (sentinelValue == object15) {
return SystemHash.hash14(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
object7.hashCode,
object8.hashCode,
object9.hashCode,
object10.hashCode,
object11.hashCode,
object12.hashCode,
object13.hashCode,
object14.hashCode,
_hashSeed);
}
if (sentinelValue == object16) {
return SystemHash.hash15(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
object7.hashCode,
object8.hashCode,
object9.hashCode,
object10.hashCode,
object11.hashCode,
object12.hashCode,
object13.hashCode,
object14.hashCode,
object15.hashCode,
_hashSeed);
}
if (sentinelValue == object17) {
return SystemHash.hash16(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
object7.hashCode,
object8.hashCode,
object9.hashCode,
object10.hashCode,
object11.hashCode,
object12.hashCode,
object13.hashCode,
object14.hashCode,
object15.hashCode,
object16.hashCode,
_hashSeed);
}
if (sentinelValue == object18) {
return SystemHash.hash17(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
object7.hashCode,
object8.hashCode,
object9.hashCode,
object10.hashCode,
object11.hashCode,
object12.hashCode,
object13.hashCode,
object14.hashCode,
object15.hashCode,
object16.hashCode,
object17.hashCode,
_hashSeed);
}
if (sentinelValue == object19) {
return SystemHash.hash18(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
object7.hashCode,
object8.hashCode,
object9.hashCode,
object10.hashCode,
object11.hashCode,
object12.hashCode,
object13.hashCode,
object14.hashCode,
object15.hashCode,
object16.hashCode,
object17.hashCode,
object18.hashCode,
_hashSeed);
}
if (sentinelValue == object20) {
return SystemHash.hash19(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
object7.hashCode,
object8.hashCode,
object9.hashCode,
object10.hashCode,
object11.hashCode,
object12.hashCode,
object13.hashCode,
object14.hashCode,
object15.hashCode,
object16.hashCode,
object17.hashCode,
object18.hashCode,
object19.hashCode,
_hashSeed);
}
return SystemHash.hash20(
object1.hashCode,
object2.hashCode,
object3.hashCode,
object4.hashCode,
object5.hashCode,
object6.hashCode,
object7.hashCode,
object8.hashCode,
object9.hashCode,
object10.hashCode,
object11.hashCode,
object12.hashCode,
object13.hashCode,
object14.hashCode,
object15.hashCode,
object16.hashCode,
object17.hashCode,
object18.hashCode,
object19.hashCode,
object20.hashCode,
_hashSeed);
}
© 2012 the Dart project authors
Licensed under the BSD 3-Clause "New" or "Revised" License.
https://api.dart.dev/stable/2.18.5/dart-core/Object/hash.html