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

Function addNode

packages/effect/src/Graph.ts:1478–1498  ·  view source on GitHub ↗
(
  mutable: MutableGraph<N, E, T>,
  data: N
)

Source from the content-addressed store, hash-verified

1476 * @since 3.18.0
1477 */
1478export const addNode = <N, E, T extends Kind = "directed">(
1479 mutable: MutableGraph<N, E, T>,
1480 data: N
1481): NodeIndex => {
1482 assertMutable(mutable)
1483 const impl = graphImpl(mutable)
1484
1485 const nodeIndex = impl.nextNodeIndex
1486
1487 // Add node data
1488 impl.nodes.set(nodeIndex, data)
1489
1490 // Initialize empty adjacency lists
1491 impl.adjacency.set(nodeIndex, [])
1492 impl.reverseAdjacency.set(nodeIndex, [])
1493
1494 // Update graph allocators
1495 impl.nextNodeIndex = impl.nextNodeIndex + 1
1496
1497 return nodeIndex
1498}
1499
1500/**
1501 * Gets the data associated with a node index safely, if it exists.

Callers 3

addNodesByIdentityFunction · 0.85
Graph.tsFile · 0.85
copyIntoFunction · 0.85

Calls 3

assertMutableFunction · 0.85
graphImplFunction · 0.85
setMethod · 0.65

Tested by

no test coverage detected