src/vs/workbench/contrib/files/common/explorerFileNestingTrie.ts/ExplorerFileNestingTrie/nest
class ExplorerFileNestingTrie:	nest(files: string[], dirname: string): Map<string, Set<string>> {
		const parentFinder = new PreTrie();

		for (const potentialParent of files) {
			const attributes = this.getAttributes(potentialParent, dirname);
			const children = this.root.get(potentialParent, attributes);
			for (const child of children) {
				parentFinder.add(child, potentialParent);
			}
		}

		const findAllRootAncestors = (file: string, seen: Set<string> = new Set()): string[] => {
			if (seen.has(file)) { return []; }
			seen.add(file);
			const attributes = this.getAttributes(file, dirname);
			const ancestors = parentFinder.get(file, attributes);
			if (ancestors.length === 0) {
				return [file];
			}

			if (ancestors.length === 1 && ancestors[0] === file) {
				return [file];
			}

			return ancestors.flatMap(a => findAllRootAncestors(a, seen));
		};

		const result = new Map<string, Set<string>>();
		for (const file of files) {
			let ancestors = findAllRootAncestors(file);
			if (ancestors.length === 0) { ancestors = [file]; }
			for (const ancestor of ancestors) {
				let existing = result.get(ancestor);
				if (!existing) { result.set(ancestor, existing = new Set()); }
				if (file !== ancestor) {
					existing.add(file);
				}
			}
		}
		return result;
	}