summaryrefslogtreecommitdiff
path: root/lib/get_dual_clusters.c
blob: 9336106fca51dedc59f007123a27fa1eac7a20dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

#include "fracture.h"

components_t *get_clusters(net_t *instance) {
  components_t *c =
      graph_components_get(instance->graph, instance->fuses, true);
  return c;
}

unsigned int *get_cluster_dist(net_t *instance) {
  components_t *c = get_clusters(instance);
  unsigned int *cluster_dist =
      (unsigned int *)calloc(instance->graph->dnv, sizeof(unsigned int));

  for (uint32_t i = 1; i <= c->n; i++) {
    unsigned int num_in_cluster = 0;
    for (unsigned int j = 0; j < instance->graph->dnv; j++) {
      if (c->labels[j] == i)
        num_in_cluster++;
    }

    if (num_in_cluster == 0)
      break;

    cluster_dist[num_in_cluster - 1]++;
  }

  graph_components_free(c);

  return cluster_dist;
}