Skip to content

Function: findClusters()

ts
function findClusters(activeMask, neighbors): ClusterResult;

Defined in: src/utils/statistics.ts:182

Finds connected clusters using BFS flood-fill.

Algorithm:

  1. Initialize all cluster IDs to -1
  2. For each active vertex not yet assigned: a. Start a new cluster with BFS b. Mark all connected active neighbors with the same cluster ID
  3. Record cluster sizes

Time complexity: O(V + E) where E is the number of edges Space complexity: O(V) for cluster IDs and queue

Parameters

activeMask

Uint8Array

Binary mask (1 = active, 0 = inactive)

neighbors

Set<number>[]

Adjacency list (neighbors[v] = set of neighbor indices)

Returns

ClusterResult

Cluster result with IDs, sizes, and count

Released under the MIT License.