MCPcopy Create free account
hub / github.com/Effect-TS/effect / buildNodeMaps

Function buildNodeMaps

packages/effect/src/Graph.ts:787–802  ·  view source on GitHub ↗
(
  graph: Graph<N, E, T>,
  identity: (node: N) => I
)

Source from the content-addressed store, hash-verified

785
786/** @internal */
787const 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 */
805const nodeIdentityAt = <N, I>(maps: NodeMaps<N, I>, index: NodeIndex): I => maps.byIndex.get(index) as I

Callers 1

Graph.tsFile · 0.85

Calls 3

graphImplFunction · 0.85
identityFunction · 0.85
setMethod · 0.65

Tested by

no test coverage detected