| 785 | |
| 786 | /** @internal */ |
| 787 | const buildNodeMaps = <N, E, T extends Kind, I>( |
| 788 | graph: Graph<N, E, T>, |
| 789 | identity: (node: N) => I |
| 790 | ): NodeMaps<N, I> => { |
| 791 | const impl = graphImpl(graph) |
| 792 | const byIdentity = MutableHashMap.empty<I, N>() |
| 793 | const byIndex = new Map<NodeIndex, I>() |
| 794 | |
| 795 | for (const [index, data] of impl.nodes) { |
| 796 | const nodeIdentity = identity(data) |
| 797 | MutableHashMap.set(byIdentity, nodeIdentity, data) |
| 798 | byIndex.set(index, nodeIdentity) |
| 799 | } |
| 800 | |
| 801 | return { byIdentity, byIndex } |
| 802 | } |
| 803 | |
| 804 | /** @internal */ |
| 805 | const nodeIdentityAt = <N, I>(maps: NodeMaps<N, I>, index: NodeIndex): I => maps.byIndex.get(index) as I |