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