( mutable: MutableGraph<N, E, T>, data: N )
| 1476 | * @since 3.18.0 |
| 1477 | */ |
| 1478 | export const addNode = <N, E, T extends Kind = "directed">( |
| 1479 | mutable: MutableGraph<N, E, T>, |
| 1480 | data: N |
| 1481 | ): NodeIndex => { |
| 1482 | assertMutable(mutable) |
| 1483 | const impl = graphImpl(mutable) |
| 1484 | |
| 1485 | const nodeIndex = impl.nextNodeIndex |
| 1486 | |
| 1487 | // Add node data |
| 1488 | impl.nodes.set(nodeIndex, data) |
| 1489 | |
| 1490 | // Initialize empty adjacency lists |
| 1491 | impl.adjacency.set(nodeIndex, []) |
| 1492 | impl.reverseAdjacency.set(nodeIndex, []) |
| 1493 | |
| 1494 | // Update graph allocators |
| 1495 | impl.nextNodeIndex = impl.nextNodeIndex + 1 |
| 1496 | |
| 1497 | return nodeIndex |
| 1498 | } |
| 1499 | |
| 1500 | /** |
| 1501 | * Gets the data associated with a node index safely, if it exists. |
no test coverage detected