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

Function getUndirectedNeighbors

packages/effect/src/Graph.ts:3727–3748  ·  view source on GitHub ↗
(
  graph: Graph<N, E, "undirected"> | MutableGraph<N, E, "undirected">,
  nodeIndex: NodeIndex
)

Source from the content-addressed store, hash-verified

3725 * For undirected graphs, we need to find the other endpoint of each edge incident to the node.
3726 */
3727const getUndirectedNeighbors = <N, E>(
3728 graph: Graph<N, E, "undirected"> | MutableGraph<N, E, "undirected">,
3729 nodeIndex: NodeIndex
3730): Array<NodeIndex> => {
3731 const impl = graphImpl(graph)
3732 const neighbors = new Set<NodeIndex>()
3733
3734 // Check edges where this node is the source
3735 const adjacencyList = impl.adjacency.get(nodeIndex)
3736 if (adjacencyList !== undefined) {
3737 for (const edgeIndex of adjacencyList) {
3738 const edge = impl.edges.get(edgeIndex)
3739 if (edge !== undefined) {
3740 // For undirected graphs, the neighbor is the other endpoint
3741 const otherNode = edge.source === nodeIndex ? edge.target : edge.source
3742 neighbors.add(otherNode)
3743 }
3744 }
3745 }
3746
3747 return Array.from(neighbors)
3748}
3749
3750const getTraversalNeighbors = <N, E, T extends Kind>(
3751 graph: Graph<N, E, T> | MutableGraph<N, E, T>,

Callers 4

Graph.tsFile · 0.85
isBipartiteFunction · 0.85
getTraversalNeighborsFunction · 0.85
connectedComponentsFunction · 0.85

Calls 3

graphImplFunction · 0.85
getMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected