
import { int32 } from "./Int32.ts";
import { compare, IComparer, physicalHash, equals as equals_1, structuralHash, IEqualityComparer } from "./Util.ts";

export function HashIdentity_FromFunctions<T>(hasher: ((arg0: T) => int32), equals: ((arg0: T, arg1: T) => boolean)): IEqualityComparer<T> {
    return {
        GetHashCode(x: T): int32 {
            return hasher(x) | 0;
        },
        Equals(x_1: T, y: T): boolean {
            return (x_1 == null) ? (y == null) : ((y == null) ? false : equals(x_1, y));
        },
    };
}

export function HashIdentity_Structural<T>(): IEqualityComparer<T> {
    return {
        GetHashCode(x: T): int32 {
            return structuralHash(x) | 0;
        },
        Equals(x_1: T, y: T): boolean {
            return equals_1(x_1, y);
        },
    };
}

export function HashIdentity_Reference<T>(): IEqualityComparer<T> {
    return {
        GetHashCode(x: T): int32 {
            return physicalHash(x) | 0;
        },
        Equals(x_1: T, y: T): boolean {
            return equals_1(x_1, y);
        },
    };
}

export function ComparisonIdentity_FromFunction<T>(comparer: ((arg0: T, arg1: T) => int32)): IComparer<T> {
    return {
        Compare(x: T, y: T): int32 {
            return ((x == null) ? ((y == null) ? 0 : -1) : ((y == null) ? 1 : comparer(x, y))) | 0;
        },
    };
}

export function ComparisonIdentity_Structural<T>(): IComparer<T> {
    return {
        Compare(x: T, y: T): int32 {
            return compare(x, y) | 0;
        },
    };
}

