| 924 | |
| 925 | /** @internal */ |
| 926 | const buildNodeMaps = <N, E, T extends Kind, I>( |
| 927 | graph: Graph<N, E, T>, |
| 928 | identity: (node: N) => I |
| 929 | ): NodeMaps<N, I> => { |
| 930 | const impl = internal.toImpl(graph) |
| 931 | const byIdentity = MutableHashMap.empty<I, N>() |
| 932 | const byIndex = new Map<NodeIndex, I>() |
| 933 | |
| 934 | for (const [index, data] of impl.nodes) { |
| 935 | const nodeIdentity = identity(data) |
| 936 | MutableHashMap.set(byIdentity, nodeIdentity, data) |
| 937 | byIndex.set(index, nodeIdentity) |
| 938 | } |
| 939 | |
| 940 | return { byIdentity, byIndex } |
| 941 | } |
| 942 | |
| 943 | /** @internal */ |
| 944 | const nodeIdentityAt = <N, I>(maps: NodeMaps<N, I>, index: NodeIndex): I => maps.byIndex.get(index) as I |