cl_list* clusterization(grid *grd)
{
    int_list *cell = NULL;
    cluster *parent = NULL;
    cl_list *current = NULL;
    cl_list *clusters = NULL;
    
    int k;
    
    for (k = 0; k < grd->width * grd->height; k++)
    {
        if (grd->cells[k] == SITE_OPEN)
        {
            cell = int_list_create_node(k);
            parent = cluster_create(cell, k < grd->width, k >= (grd->height - 1) * grd->width);
            
            // get list of clusters that contain grd->cells[k]
            current = find_neighbors(&clusters, grd, k);
            while (current != NULL)
            {
                cluster_join(&parent, &(current->item));
                free(current->item);
                current = current->next;
            }
            
            cl_list_push_item(&clusters, parent);
            grd->cells[k] = SITE_FULL;
            
        }
    }
    

    return clusters;
}
Example #2
0
void handle_clustering(state *s, Filedata *a, Filedata *b)
{
  bool a_has = a->has_cluster(), b_has = b->has_cluster();

  // In the easiest case, one of these has a cluster and one doesn't
  if (a_has and not b_has)
  {
    cluster_add(a,b);
    return;
  }
  if (b_has and not a_has)
  {
    cluster_add(b,a);
    return;
  }
  
  // Combine existing clusters
  if (a_has and b_has)
  {
    cluster_join(s,a,b);
    return;
  }

  // Create a new cluster
  std::set<Filedata *> * cluster = new std::set<Filedata *>();
  cluster->insert(a);
  cluster->insert(b);

  s->all_clusters.insert(cluster);

  a->set_cluster(cluster);
  b->set_cluster(cluster);
}