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

Function addNode

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

Source from the content-addressed store, hash-verified

1739 * @since 3.18.0
1740 */
1741export const addNode = <N, E, T extends Kind = "directed">(
1742 mutable: MutableGraph<N, E, T>,
1743 data: N
1744): NodeIndex => {
1745 const impl = getMutableImplForMutation(mutable)
1746 const nodeIndex = impl.nextNodeIndex
1747 if (!Number.isSafeInteger(nodeIndex)) {
1748 throw new GraphError({ message: "Graph has exhausted safe node indexes" })
1749 }
1750
1751 // Add node data
1752 impl.nodes.set(nodeIndex, data)
1753
1754 // Initialize empty adjacency lists
1755 impl.adjacency.set(nodeIndex, [])
1756 impl.reverseAdjacency.set(nodeIndex, [])
1757
1758 // Update graph allocators
1759 impl.nextNodeIndex = impl.nextNodeIndex + 1
1760
1761 return nodeIndex
1762}
1763
1764/**
1765 * 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 2

setMethod · 0.65

Tested by

no test coverage detected