MCPcopy Create free account
hub / github.com/effect-app/libs / addEdge

Function addEdge

repos/effect/packages/effect/src/Graph.ts:1411–1463  ·  view source on GitHub ↗
(
  mutable: MutableGraph<N, E, T>,
  source: NodeIndex,
  target: NodeIndex,
  data: E
)

Source from the content-addressed store, hash-verified

1409export const complement: {
1410 <N, E>(
1411 createEdge: (source: N, target: N) => E
1412 ): <T extends Kind = "directed">(self: Graph<N, E, T>) => Graph<N, E, T>
1413 <N, E, T extends Kind = "directed">(
1414 self: Graph<N, E, T>,
1415 createEdge: (source: N, target: N) => E
1416 ): Graph<N, E, T>
1417} = dual(2, <N, E, T extends Kind>(
1418 self: Graph<N, E, T>,
1419 createEdge: (source: N, target: N) => E
1420): Graph<N, E, T> => {
1421 const cache = csr.get(self)
1422 const outgoing = csr.getOutgoing(cache)
1423 const neighborMarks = new Uint32Array(cache.nodeIds.length)
1424
1425 return make(self.type)<N, E>((mutable) => {
1426 const newIndices = new Uint32Array(cache.nodeIds.length)
1427
1428 for (let i = 0; i < cache.nodeIds.length; i++) {
1429 newIndices[i] = addNode(mutable, cache.nodeData[i] as N)
1430 }
1431
1432 for (let i = 0; i < cache.nodeIds.length; i++) {
1433 const generation = i + 1
1434 for (let edge = outgoing.rowOffsets[i]; edge < outgoing.rowOffsets[i + 1]; edge++) {
1435 neighborMarks[outgoing.columnIndices[edge]] = generation
1436 }
1437 const start = self.type === "undirected" ? i + 1 : 0
1438
1439 for (let j = start; j < cache.nodeIds.length; j++) {
1440 if (i === j || neighborMarks[j] === generation) {
1441 continue
1442 }
1443 addEdge(mutable, newIndices[i], newIndices[j], createEdge(cache.nodeData[i] as N, cache.nodeData[j] as N))
1444 }
1445 }
1446 })
1447})
1448
1449/**
1450 * Configuration for selecting a graph neighborhood.
1451 *
1452 * **Details**
1453 *
1454 * `radius` limits the edge distance from the center node and defaults to `1`.
1455 * It accepts non-negative integers and `Infinity`.
1456 * `direction` controls how directed edges are traversed and defaults to
1457 * `"outgoing"`.
1458 *
1459 * @category configuration
1460 * @since 4.0.0
1461 */
1462export interface NeighborhoodConfig {
1463 readonly radius?: number
1464 readonly direction?: TraversalDirection
1465}
1466

Callers

nothing calls this directly

Calls 6

missingNodeFunction · 0.85
pushMethod · 0.80
setMethod · 0.65
getMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…