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

Function removeNodeInternal

packages/effect/src/Graph.ts:2757–2798  ·  view source on GitHub ↗
(
  impl: internal.GraphImpl<N, E, T>,
  nodeIndex: NodeIndex
)

Source from the content-addressed store, hash-verified

2755
2756/** @internal */
2757const removeNodeInternal = <N, E, T extends Kind = "directed">(
2758 impl: internal.GraphImpl<N, E, T>,
2759 nodeIndex: NodeIndex
2760): boolean => {
2761 // Check if node exists
2762 if (!impl.nodes.has(nodeIndex)) {
2763 return false // Node doesn't exist, nothing to remove
2764 }
2765
2766 const edgesToRemove = new Set(impl.adjacency.get(nodeIndex)!)
2767 for (const edgeIndex of impl.reverseAdjacency.get(nodeIndex)!) {
2768 edgesToRemove.add(edgeIndex)
2769 }
2770
2771 for (const edgeIndex of edgesToRemove) {
2772 const edge = impl.edges.get(edgeIndex)!
2773 if (edge.source !== nodeIndex) {
2774 const adjacency = impl.adjacency.get(edge.source)!
2775 adjacency.splice(adjacency.indexOf(edgeIndex), 1)
2776 if (impl.type === "undirected") {
2777 const reverseAdjacency = impl.reverseAdjacency.get(edge.source)!
2778 reverseAdjacency.splice(reverseAdjacency.indexOf(edgeIndex), 1)
2779 }
2780 }
2781 if (edge.target !== nodeIndex) {
2782 const reverseAdjacency = impl.reverseAdjacency.get(edge.target)!
2783 reverseAdjacency.splice(reverseAdjacency.indexOf(edgeIndex), 1)
2784 if (impl.type === "undirected") {
2785 const adjacency = impl.adjacency.get(edge.target)!
2786 adjacency.splice(adjacency.indexOf(edgeIndex), 1)
2787 }
2788 }
2789 impl.edges.delete(edgeIndex)
2790 }
2791
2792 // Remove the node itself
2793 impl.nodes.delete(nodeIndex)
2794 impl.adjacency.delete(nodeIndex)
2795 impl.reverseAdjacency.delete(nodeIndex)
2796
2797 return true
2798}
2799
2800/**
2801 * Removes an edge from a mutable graph.

Callers 2

removeNodeFunction · 0.85
removeNodesFunction · 0.85

Calls 4

hasMethod · 0.65
getMethod · 0.65
addMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected