41 lines
773 B
TypeScript

import * as fs from 'fs';
import { AbsPath } from ".";
class PathSet {
files: Set<AbsPath> = new Set<AbsPath>();
add(path: AbsPath) {
this.files.add(path);
}
checkAdd(path: AbsPath | AbsPath[]) {
if (path instanceof Array) {
path.forEach(p => this.checkAdd(p));
} else if (fs.existsSync(path)) {
this.files.add(path);
}
}
}
/**
* tell if two set are element-wise equal
* @param setA
* @param setB
*/
function isSameSet<T>(setA: Set<T>, setB: Set<T>): boolean {
if (setA.size !== setB.size) {
return false;
}
for (const el of setB) {
if (!setA.has(el)) {
return false;
}
}
return true;
}
export {
PathSet,
isSameSet
};