MCPcopy Index your code
hub / github.com/Effect-TS/effect / getUndirectedNeighbors

Function getUndirectedNeighbors

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

Source from the content-addressed store, hash-verified

2084 * For undirected graphs, we need to find the other endpoint of each edge incident to the node.
2085 */
2086const getUndirectedNeighbors = <N, E>(
2087 graph: Graph<N, E, "undirected"> | MutableGraph<N, E, "undirected">,
2088 nodeIndex: NodeIndex
2089): Array<NodeIndex> => {
2090 const neighbors = new Set<NodeIndex>()
2091
2092 // Check edges where this node is the source
2093 const adjacencyList = graph.adjacency.get(nodeIndex)
2094 if (adjacencyList !== undefined) {
2095 for (const edgeIndex of adjacencyList) {
2096 const edge = graph.edges.get(edgeIndex)
2097 if (edge !== undefined) {
2098 // For undirected graphs, the neighbor is the other endpoint
2099 const otherNode = edge.source === nodeIndex ? edge.target : edge.source
2100 neighbors.add(otherNode)
2101 }
2102 }
2103 }
2104
2105 return Array.from(neighbors)
2106}
2107
2108const getTraversalNeighbors = <N, E, T extends Kind>(
2109 graph: Graph<N, E, T> | MutableGraph<N, E, T>,

Callers 5

neighborsFunction · 0.85
isAcyclicFunction · 0.85
isBipartiteFunction · 0.85
getTraversalNeighborsFunction · 0.85
connectedComponentsFunction · 0.85

Calls 2

getMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected