javascript-collections-framework
    Preparing search index...

    Interface Equivalence<T>

    A notion of equality for a collection: an equals that is reflexive, symmetric and transitive, and a hash that returns the same finite number for equal values.

    Collections read both functions once, when they are created, and call them with this set to the equivalence. equals must return a boolean.

    const caseInsensitive: Equivalence<string> = {
    equals: (a, b) => a.toLowerCase() === b.toLowerCase(),
    hash: (s) => hashCode(s.toLowerCase()),
    }
    interface Equivalence<T> {
        equals(a: T, b: T): boolean;
        hash(value: T): number;
    }

    Type Parameters

    • T
    Index
    • Returns whether a and b are equal; must return a boolean.

      Parameters

      • a: T
      • b: T

      Returns boolean

    • Returns a finite number, the same for equal values.

      Parameters

      • value: T

      Returns number