( mutable: MutableGraph<N, E, T>, predicate: (data: N) => boolean )
| 2140 | * @since 3.18.0 |
| 2141 | */ |
| 2142 | export const filterNodes = <N, E, T extends Kind = "directed">( |
| 2143 | mutable: MutableGraph<N, E, T>, |
| 2144 | predicate: (data: N) => boolean |
| 2145 | ): void => { |
| 2146 | assertMutable(mutable) |
| 2147 | const impl = graphImpl(mutable) |
| 2148 | |
| 2149 | const nodesToRemove: Array<NodeIndex> = [] |
| 2150 | |
| 2151 | // Identify nodes to remove |
| 2152 | for (const [index, data] of impl.nodes) { |
| 2153 | if (!predicate(data)) { |
| 2154 | nodesToRemove.push(index) |
| 2155 | } |
| 2156 | } |
| 2157 | |
| 2158 | // Remove filtered out nodes (this also removes connected edges) |
| 2159 | for (const nodeIndex of nodesToRemove) { |
| 2160 | removeNode(mutable, nodeIndex) |
| 2161 | } |
| 2162 | } |
| 2163 | |
| 2164 | /** |
| 2165 | * Filters edges by removing those that don't match the predicate. |
nothing calls this directly
no test coverage detected