( graph: Graph<N, E, "undirected"> | MutableGraph<N, E, "undirected">, nodeIndex: NodeIndex )
| 2084 | * For undirected graphs, we need to find the other endpoint of each edge incident to the node. |
| 2085 | */ |
| 2086 | const 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 | |
| 2108 | const getTraversalNeighbors = <N, E, T extends Kind>( |
| 2109 | graph: Graph<N, E, T> | MutableGraph<N, E, T>, |
no test coverage detected