mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 17:43:35 -06:00
35 lines
694 B
TypeScript
35 lines
694 B
TypeScript
|
/**
|
||
|
* Performs a shallow comparison of two sets with the same item type.
|
||
|
*/
|
||
|
export function equal<T>(a: Set<T>, b: Set<T>): 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<T>(a: Set<T>, b: Set<T>): Set<T> {
|
||
|
const it = b.values();
|
||
|
while (true) {
|
||
|
const { value, done } = it.next();
|
||
|
if (!a.has(value)) {
|
||
|
a.delete(value);
|
||
|
}
|
||
|
if (done) {
|
||
|
return a;
|
||
|
}
|
||
|
}
|
||
|
}
|