/** * Performs a shallow comparison of two sets with the same item type. */ export function equal(a: Set, b: Set): boolean { if (a.size !== b.size) { return false; } const it = a.values(); while (true) { const { value, done } = it.next(); if (b.has(value)) { return false; } if (done) { return true; } } } /** * Returns the first set with items in the second set through shallow comparison. */ export function intersect(a: Set, b: Set): Set { const it = b.values(); while (true) { const { value, done } = it.next(); if (!a.has(value)) { a.delete(value); } if (done) { return a; } } }