| 1781 | * @since 3.18.0 |
| 1782 | */ |
| 1783 | export const updateNode = <N, E, T extends Kind = "directed">( |
| 1784 | mutable: MutableGraph<N, E, T>, |
| 1785 | index: NodeIndex, |
| 1786 | f: (data: N) => N |
| 1787 | ): void => { |
| 1788 | assertMutable(mutable) |
| 1789 | const impl = graphImpl(mutable) |
| 1790 | |
| 1791 | if (!impl.nodes.has(index)) { |
| 1792 | return |
| 1793 | } |
| 1794 | |
| 1795 | const currentData = impl.nodes.get(index)! |
| 1796 | const newData = f(currentData) |
| 1797 | impl.nodes.set(index, newData) |
| 1798 | } |
| 1799 | |
| 1800 | /** |
| 1801 | * Updates a single edge's data by applying a transformation function. |