( mutable: MutableGraph<N, E, T>, predicate: (data: N) => boolean )
| 2471 | * @since 3.18.0 |
| 2472 | */ |
| 2473 | export const filterNodes = <N, E, T extends Kind = "directed">( |
| 2474 | mutable: MutableGraph<N, E, T>, |
| 2475 | predicate: (data: N) => boolean |
| 2476 | ): void => { |
| 2477 | const impl = getMutableImplForMutation(mutable) |
| 2478 | const remove: Array<NodeIndex> = [] |
| 2479 | |
| 2480 | internal.withTransformation(mutable, () => { |
| 2481 | // Identify nodes to remove |
| 2482 | for (const [index, data] of impl.nodes) { |
| 2483 | if (!predicate(data)) { |
| 2484 | remove.push(index) |
| 2485 | } |
| 2486 | } |
| 2487 | }) |
| 2488 | |
| 2489 | // Remove filtered out nodes (this also removes connected edges) |
| 2490 | removeNodes(mutable, remove) |
| 2491 | } |
| 2492 | |
| 2493 | /** |
| 2494 | * Filters edges by removing those that don't match the predicate. |
nothing calls this directly
no test coverage detected