]> granicus.if.org Git - graphviz/commitdiff
cluster_map: replace boolean array 'assigned' with a bit array
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 12 Jan 2022 03:28:26 +0000 (19:28 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 12 Jan 2022 15:50:35 +0000 (07:50 -0800)
This is more memory efficient.

lib/neatogen/neatoinit.c

index 9401c60efaa6abb755464ef42013f5c3abec5eba..3c7bf59b8e5eb3707c93134f53f3c5fa08278c73 100644 (file)
@@ -26,6 +26,7 @@
 #include <neatogen/kkutils.h>
 #include <common/pointset.h>
 #include <neatogen/sgd.h>
+#include <cgraph/bitarray.h>
 #include <cgraph/strcasecmp.h>
 #include <stdbool.h>
 
@@ -188,7 +189,8 @@ static cluster_data* cluster_map(graph_t *mastergraph, graph_t *g)
      /* array of arrays of node indices in each cluster */
     int **cs,*cn;
     int i,j,nclusters=0;
-    boolean* assigned = N_NEW(agnnodes(g), boolean);
+    bitarray_t assigned = {0};
+    bitarray_resize_or_exit(&assigned, agnnodes(g));
     cluster_data *cdata = GNEW(cluster_data);
 
     cdata->ntoplevel = agnnodes(g);
@@ -217,7 +219,7 @@ static cluster_data* cluster_map(graph_t *mastergraph, graph_t *g)
                     ind++;
                 }
                 *c++=ind;
-                assigned[ind]=TRUE;
+                bitarray_set(assigned, ind, true);
                 cdata->ntoplevel--;
             }
         }
@@ -225,12 +227,12 @@ static cluster_data* cluster_map(graph_t *mastergraph, graph_t *g)
     cdata->bb=N_GNEW(cdata->nclusters,boxf);
     cdata->toplevel=N_GNEW(cdata->ntoplevel,int);
     for(i=j=0;i<agnnodes(g);i++) {
-        if(!assigned[i]) {
+        if(!bitarray_get(assigned, i)) {
             cdata->toplevel[j++]=i;
         }
     }
     assert(cdata->ntoplevel==agnnodes(g)-cdata->nvars);
-    free (assigned);
+    bitarray_reset(&assigned);
     return cdata;
 }