MCPcopy
hub / github.com/Effect-TS/effect / neighbors

Function neighbors

packages/effect/src/Graph.ts:1492–1515  ·  view source on GitHub ↗
(
  graph: Graph<N, E, T> | MutableGraph<N, E, T>,
  nodeIndex: NodeIndex
)

Source from the content-addressed store, hash-verified

1490 * @category getters
1491 */
1492export const neighbors = <N, E, T extends Kind = "directed">(
1493 graph: Graph<N, E, T> | MutableGraph<N, E, T>,
1494 nodeIndex: NodeIndex
1495): Array<NodeIndex> => {
1496 // For undirected graphs, use the specialized helper that returns the other endpoint
1497 if (graph.type === "undirected") {
1498 return getUndirectedNeighbors(graph as any, nodeIndex)
1499 }
1500
1501 const adjacencyList = graph.adjacency.get(nodeIndex)
1502 if (adjacencyList === undefined) {
1503 return []
1504 }
1505
1506 const result: Array<NodeIndex> = []
1507 for (const edgeIndex of adjacencyList) {
1508 const edge = graph.edges.get(edgeIndex)
1509 if (edge !== undefined) {
1510 result.push(edge.target)
1511 }
1512 }
1513
1514 return result
1515}
1516
1517/**
1518 * Get neighbors of a node in a specific direction for bidirectional traversal.

Callers 1

Calls 2

getUndirectedNeighborsFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected