deep static method

  1. @Possible({StackOverflowError})
  2. @useResult
int deep(
  1. Object? value
)

Computes value's a deep hash code.

This function handles lists, maps, sets, iterables and map entries specially.

Where possible, DeepEqualityIterable.hashValue and DeepEqualityMap.hashValue are preferred.

Contract

A StackOverflowError is thrown if value contains itself.

final a = [];
a.add(a);

HashCodes.deep(a) // Throws a StackOverflowError

Implementation

@Possible({StackOverflowError})
@useResult static int deep(Object? value) => switch (value) {
  List _ => _ordered(_list, value),
  Set _ => _unordered(_set, value),
  Iterable _ => _unordered(_iterable, value),
  Map(:final entries) => _unordered(_map, entries),
  MapEntry(:final key, :final value) => _ordered(_entry, [key, value]),
  _ => value.hashCode,
};