( mutable: MutableGraph<N, E, T>, data: N )
| 1739 | * @since 3.18.0 |
| 1740 | */ |
| 1741 | export const addNode = <N, E, T extends Kind = "directed">( |
| 1742 | mutable: MutableGraph<N, E, T>, |
| 1743 | data: N |
| 1744 | ): NodeIndex => { |
| 1745 | const impl = getMutableImplForMutation(mutable) |
| 1746 | const nodeIndex = impl.nextNodeIndex |
| 1747 | if (!Number.isSafeInteger(nodeIndex)) { |
| 1748 | throw new GraphError({ message: "Graph has exhausted safe node indexes" }) |
| 1749 | } |
| 1750 | |
| 1751 | // Add node data |
| 1752 | impl.nodes.set(nodeIndex, data) |
| 1753 | |
| 1754 | // Initialize empty adjacency lists |
| 1755 | impl.adjacency.set(nodeIndex, []) |
| 1756 | impl.reverseAdjacency.set(nodeIndex, []) |
| 1757 | |
| 1758 | // Update graph allocators |
| 1759 | impl.nextNodeIndex = impl.nextNodeIndex + 1 |
| 1760 | |
| 1761 | return nodeIndex |
| 1762 | } |
| 1763 | |
| 1764 | /** |
| 1765 | * Gets the data associated with a node index safely, if it exists. |
no test coverage detected