1
>
/*---------------------------------------------------------------------------------------------
graph.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
export class Node<T> {
7
>
8
>
9
>
readonly incoming = new Map<string, Node<T>>();
10
>
readonly outgoing = new Map<string, Node<T>>();
11
>
12
>
constructor(
13
readonly key: string,
14
readonly data: T
15
) { }
17
>
18
>
export class Graph<T> {
19
>
20
>
private readonly _nodes = new Map<string, Node<T>>();
21
>
22
>
constructor(private readonly _hashFn: (element: T) => string) {
23
// empty
24
}
26
>
roots(): Node<T>[] {
27
const ret: Node<T>[] = [];
28
for (const node of this._nodes.values()) {