// TODO: Change lib to pick up this type definition
export function equals(a, b) {
    if (a.size !== b.size) {
        return false;
    }
    const iterator = a.keys();
    for (let { done, value } = iterator.next(); !done; { done, value } = iterator.next()) {
        if (!b.has(value)) {
            return false;
        }
    }
    return true;
}
export function union(...sets) {
    const result = new Set();
    for (const set of sets) {
        const iterator = set.keys();
        for (let { done, value } = iterator.next(); !done; { done, value } = iterator.next()) {
            result.add(value);
        }
    }
    return result;
}
export function intersection(a, b) {
    const result = new Set();
    if (a.size > b.size) {
        // Optimization: iterate over the smaller Set.
        const swap = a;
        a = b;
        b = swap;
    }
    const iterator = a.keys();
    for (let { done, value } = iterator.next(); !done; { done, value } = iterator.next()) {
        if (b.has(value)) {
            result.add(value);
        }
    }
    return result;
}
/**
 * Returns the elements in {@linkcode a} that are not in {@linkcode b}.
 */
export function difference(a, b) {
    const result = new Set();
    const iterator = a.keys();
    for (let { done, value } = iterator.next(); !done; { done, value } = iterator.next()) {
        if (!b.has(value)) {
            result.add(value);
        }
    }
    return result;
}
export function symmetricDifferences(a, b) {
    const onlyA = new Set();
    const iteratorA = a.keys();
    for (let { done, value } = iteratorA.next(); !done; { done, value } = iteratorA.next()) {
        onlyA.add(value);
    }
    const onlyB = new Set();
    const iteratorB = b.keys();
    for (let { done, value } = iteratorB.next(); !done; { done, value } = iteratorB.next()) {
        if (a.has(value)) {
            onlyA.delete(value);
            onlyB.delete(value);
        }
        else {
            onlyB.add(value);
        }
    }
    return [onlyA, onlyB];
}
//# sourceMappingURL=set-utils.js.map