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

Function neighborsDirected

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

Source from the content-addressed store, hash-verified

1541 * @category queries
1542 */
1543export const neighborsDirected = <N, E, T extends Kind = "directed">(
1544 graph: Graph<N, E, T> | MutableGraph<N, E, T>,
1545 nodeIndex: NodeIndex,
1546 direction: Direction
1547): Array<NodeIndex> => {
1548 const adjacencyMap = direction === "incoming"
1549 ? graph.reverseAdjacency
1550 : graph.adjacency
1551
1552 const adjacencyList = adjacencyMap.get(nodeIndex)
1553 if (adjacencyList === undefined) {
1554 return []
1555 }
1556
1557 const result: Array<NodeIndex> = []
1558 for (const edgeIndex of adjacencyList) {
1559 const edge = graph.edges.get(edgeIndex)
1560 if (edge !== undefined) {
1561 // For incoming direction, we want the source node instead of target
1562 const neighborNode = direction === "incoming"
1563 ? edge.source
1564 : edge.target
1565 result.push(neighborNode)
1566 }
1567 }
1568
1569 return result
1570}
1571
1572// =============================================================================
1573// GraphViz Export

Callers 3

isAcyclicFunction · 0.85
getTraversalNeighborsFunction · 0.85
nextMappedFunction · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected