Skip to content

Commit

Permalink
improve DI graph (#159849)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken authored Sep 2, 2022
1 parent b766391 commit 001eb8b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/vs/platform/instantiation/common/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

export class Node<T> {

readonly data: T;

readonly incoming = new Map<string, Node<T>>();
readonly outgoing = new Map<string, Node<T>>();

constructor(data: T) {
this.data = data;
}
constructor(
readonly key: string,
readonly data: T
) { }
}

export class Graph<T> {
Expand All @@ -36,8 +37,8 @@ export class Graph<T> {
const fromNode = this.lookupOrInsertNode(from);
const toNode = this.lookupOrInsertNode(to);

fromNode.outgoing.set(this._hashFn(to), toNode);
toNode.incoming.set(this._hashFn(from), fromNode);
fromNode.outgoing.set(toNode.key, toNode);
toNode.incoming.set(fromNode.key, fromNode);
}

removeNode(data: T): void {
Expand All @@ -54,7 +55,7 @@ export class Graph<T> {
let node = this._nodes.get(key);

if (!node) {
node = new Node(data);
node = new Node(key, data);
this._nodes.set(key, node);
}

Expand All @@ -72,7 +73,7 @@ export class Graph<T> {
toString(): string {
const data: string[] = [];
for (const [key, value] of this._nodes) {
data.push(`${key}, (incoming)[${[...value.incoming.keys()].join(', ')}], (outgoing)[${[...value.outgoing.keys()].join(',')}]`);
data.push(`${key}\n\t(-> incoming)[${[...value.incoming.keys()].join(', ')}]\n\t(outgoing ->)[${[...value.outgoing.keys()].join(',')}]\n`);

}
return data.join('\n');
Expand Down

0 comments on commit 001eb8b

Please sign in to comment.