import { assert } from "../../assert.js";

/**
 * Returns common elements between two sets
 * @template T
 * @returns Set<T>
 * @param {Set<T>} a
 * @param {Set<T>} b
 */
export function compute_set_intersection(a, b) {
    assert.defined(a, 'a');
    assert.defined(b, 'b');

    assert.isInstanceOf(a, Set, 'a');
    assert.isInstanceOf(b, Set, 'b');

    const result = new Set();

    const a_array = Array.from(a);

    const n = a_array.length;
    for (let i = 0; i < n; i++) {
        const t = a_array[i];

        if (b.has(t)) {
            result.add(t);
        }
    }

    return result;
}
