MCPcopy Create free account
hub / github.com/Effect-TS/effect / getDirectedNeighbors

Function getDirectedNeighbors

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

Source from the content-addressed store, hash-verified

2621): number => graphImpl(graph).edges.size
2622
2623const getDirectedNeighbors = <N, E>(
2624 graph: Graph<N, E, "directed"> | MutableGraph<N, E, "directed">,
2625 nodeIndex: NodeIndex,
2626 direction: Direction
2627): Array<NodeIndex> => {
2628 const impl = graphImpl(graph)
2629 const adjacencyMap = direction === "incoming"
2630 ? impl.reverseAdjacency
2631 : impl.adjacency
2632
2633 const adjacencyList = adjacencyMap.get(nodeIndex)
2634 if (adjacencyList === undefined) {
2635 return []
2636 }
2637
2638 const result: Array<NodeIndex> = []
2639 for (const edgeIndex of adjacencyList) {
2640 const edge = impl.edges.get(edgeIndex)
2641 if (edge !== undefined) {
2642 result.push(direction === "incoming" ? edge.source : edge.target)
2643 }
2644 }
2645
2646 return result
2647}
2648
2649/**
2650 * Returns the neighboring node indices for a node.

Callers 5

Graph.tsFile · 0.85
isAcyclicFunction · 0.85
getTraversalNeighborsFunction · 0.85
nextMappedFunction · 0.85

Calls 3

graphImplFunction · 0.85
pushMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected