Expose `Graph.mergeManyConservative` (#209)
Summary: This offers #205 to general users. Test Plan: Existing tests suffice. wchargin-branch: merge-many-conservative
This commit is contained in:
parent
e3469f157d
commit
a642ed46b9
|
@ -338,6 +338,28 @@ export class Graph<NP, EP> {
|
|||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Equivalent to
|
||||
*
|
||||
* graphs.reduce((g, h) => Graph.mergeConservative(g, h), new Graph()),
|
||||
*
|
||||
* but uses a mutable accumulator for improved performance.
|
||||
*/
|
||||
static mergeManyConservative<NP, EP>(
|
||||
graphs: $ReadOnlyArray<Graph<$Subtype<NP>, $Subtype<EP>>>
|
||||
): Graph<NP, EP> {
|
||||
const result = new Graph();
|
||||
graphs.forEach((graph) => {
|
||||
graph.nodes().forEach((node) => {
|
||||
result.addNode(node);
|
||||
});
|
||||
graph.edges().forEach((edge) => {
|
||||
result.addEdge(edge);
|
||||
});
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export function edgeID(src: Address, dst: Address): string {
|
||||
|
|
|
@ -41,7 +41,7 @@ class GitGraphCreator {
|
|||
const treeAndNameToSubmoduleUrls = this.treeAndNameToSubmoduleUrls(
|
||||
repository
|
||||
);
|
||||
const graphs = [
|
||||
return Graph.mergeManyConservative([
|
||||
...Object.keys(repository.commits).map((hash) =>
|
||||
this.commitGraph(repository.commits[hash])
|
||||
),
|
||||
|
@ -49,17 +49,7 @@ class GitGraphCreator {
|
|||
this.treeGraph(repository.trees[hash], treeAndNameToSubmoduleUrls)
|
||||
),
|
||||
this.becomesEdges(repository),
|
||||
];
|
||||
const result = new Graph();
|
||||
graphs.forEach((g) => {
|
||||
g.nodes().forEach((node) => {
|
||||
result.addNode(node);
|
||||
});
|
||||
g.edges().forEach((edge) => {
|
||||
result.addEdge(edge);
|
||||
});
|
||||
});
|
||||
return result;
|
||||
]);
|
||||
}
|
||||
|
||||
treeAndNameToSubmoduleUrls(repository: Repository) {
|
||||
|
|
Loading…
Reference in New Issue