WeakHashSet<E extends Object> constructor

WeakHashSet<E extends Object>({
  1. bool equals(
    1. E,
    2. E
    )?,
  2. int hashCode(
    1. E
    )?,
  3. bool isValidKey(
    1. dynamic
    )?,
})

Create a hash set using the provided equals as equality.

The provided equals must define a stable equivalence relation, and hashCode must be consistent with equals.

If equals or hashCode are omitted, the set uses the elements' intrinsic Object.== and Object.hashCode.

If you supply one of equals and hashCode, you should generally also supply the other.

Some equals or hashCode functions might not work for all objects. If isValidKey is supplied, it's used to check a potential element which is not necessarily an instance of E, like the argument to contains which is typed as Object?. If isValidKey returns false, for an object, the equals and hashCode functions are not called, and no key equal to that object is assumed to be in the map. The isValidKey function defaults to just testing if the object is an instance of E

Implementation

WeakHashSet(
    {bool Function(E, E)? equals,
    int Function(E)? hashCode,
    bool Function(dynamic)? isValidKey})
    : _weakHashMap = WeakHashMap<E, dynamic>(
          equals: equals, hashCode: hashCode, isValidKey: isValidKey);