|
@@ -67,6 +67,14 @@ export namespace SetUtils {
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
+ export function intersectionSize<T>(setA: ReadonlySet<T>, setB: ReadonlySet<T>): number {
|
|
|
+ let count = 0
|
|
|
+ setB.forEach(elem => {
|
|
|
+ if (setA.has(elem)) count += 1;
|
|
|
+ })
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
/** Create set containing elements of set a that are not in set b. */
|
|
|
export function difference<T>(setA: ReadonlySet<T>, setB: ReadonlySet<T>): Set<T> {
|
|
|
const difference = new Set(setA);
|
|
@@ -74,6 +82,15 @@ export namespace SetUtils {
|
|
|
return difference;
|
|
|
}
|
|
|
|
|
|
+ /** Number of elements that are in set a but not in set b. */
|
|
|
+ export function differenceSize<T>(setA: ReadonlySet<T>, setB: ReadonlySet<T>): number {
|
|
|
+ let count = setA.size;
|
|
|
+ setA.forEach(elem => {
|
|
|
+ if (setB.has(elem)) count -= 1
|
|
|
+ })
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
/** Test if set a and b contain the same elements. */
|
|
|
export function areEqual<T>(setA: ReadonlySet<T>, setB: ReadonlySet<T>) {
|
|
|
if (setA.size !== setB.size) return false
|