Count distinct community labels in a result. */
| 1523 | |
| 1524 | /* Count distinct community labels in a result. */ |
| 1525 | static int leiden_count_communities(const cbm_louvain_result_t *r, int n) { |
| 1526 | int *seen = malloc((size_t)n * sizeof(int)); |
| 1527 | int nd = 0; |
| 1528 | for (int i = 0; i < n; i++) { |
| 1529 | bool found = false; |
| 1530 | for (int j = 0; j < nd; j++) { |
| 1531 | if (seen[j] == r[i].community) { |
| 1532 | found = true; |
| 1533 | break; |
| 1534 | } |
| 1535 | } |
| 1536 | if (!found) { |
| 1537 | seen[nd++] = r[i].community; |
| 1538 | } |
| 1539 | } |
| 1540 | free(seen); |
| 1541 | return nd; |
| 1542 | } |
| 1543 | |
| 1544 | /* Verify every community induces a connected subgraph under `edges` — the |
| 1545 | * property Leiden's refinement guarantees and single-level Louvain does not. */ |