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

Function buildNodeMaps

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

Source from the content-addressed store, hash-verified

924
925/** @internal */
926const 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 */
944const nodeIdentityAt = <N, I>(maps: NodeMaps<N, I>, index: NodeIndex): I => maps.byIndex.get(index) as I

Callers 1

Graph.tsFile · 0.85

Calls 2

identityFunction · 0.70
setMethod · 0.65

Tested by

no test coverage detected