]> granicus.if.org Git - graphviz/commitdiff
graph_sgd: convert 'pinned' bool array to a bit array
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 18 Dec 2021 22:51:17 +0000 (14:51 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 22 Dec 2021 01:06:26 +0000 (17:06 -0800)
lib/neatogen/dijkstra.c
lib/neatogen/sgd.c
lib/neatogen/sgd.h

index 7b60ce68faa042bb54263a19f26320fb500b8f1a..eb851501bbea65247da6d5f8fb0833e59b2bf389 100644 (file)
@@ -18,6 +18,7 @@
 ******************************************/
 
 #include <assert.h>
+#include <cgraph/bitarray.h>
 #include <common/memory.h>
 #include <float.h>
 #include <neatogen/bfs.h>
@@ -389,7 +390,7 @@ int dijkstra_sgd(graph_sgd *graph, int source, term_sgd *terms) {
         }
         // if the target is fixed then always create a term as shortest paths are not calculated from there
         // if not fixed then only create a term if the target index is lower
-        if (graph->pinneds[closest] || closest<source) {
+        if (bitarray_get(graph->pinneds, closest) || closest<source) {
             terms[offset].i = source;
             terms[offset].j = closest;
             terms[offset].d = d;
index c33c8206582203b69a563b96079b8cee090b1bb7..7ec0411af118ff1d9b24efb817834e782cfcf5f0 100644 (file)
@@ -1,4 +1,5 @@
 #include <assert.h>
+#include <cgraph/bitarray.h>
 #include <limits.h>
 #include <neatogen/neato.h>
 #include <neatogen/sgd.h>
@@ -51,7 +52,7 @@ static graph_sgd * extract_adjacency(graph_t *G, int model) {
     }
     graph_sgd *graph = N_NEW(1, graph_sgd);
     graph->sources = N_NEW(n_nodes+1, int);
-    graph->pinneds = N_NEW(n_nodes, bool);
+    bitarray_resize_or_exit(&graph->pinneds, n_nodes);
     graph->targets = N_NEW(n_edges, int);
     graph->weights = N_NEW(n_edges, float);
 
@@ -63,7 +64,7 @@ static graph_sgd * extract_adjacency(graph_t *G, int model) {
     for (np = agfstnode(G); np; np = agnxtnode(G,np)) {
         assert(n_edges <= INT_MAX);
         graph->sources[n_nodes] = (int)n_edges;
-        graph->pinneds[n_nodes] = isFixed(np);
+        bitarray_set(graph->pinneds, n_nodes, isFixed(np));
         for (ep = agfstedge(G, np); ep; ep = agnxtedge(G, ep, np)) {
             if (agtail(ep) == aghead(ep)) { // ignore self-loops and double edges
                 continue;
@@ -138,7 +139,7 @@ static graph_sgd * extract_adjacency(graph_t *G, int model) {
 }
 static void free_adjacency(graph_sgd *graph) {
     free(graph->sources);
-    free(graph->pinneds);
+    bitarray_reset(&graph->pinneds);
     free(graph->targets);
     free(graph->weights);
     free(graph);
index af11526c7fa7ee71424b1671f2496089463e50df..52f353a8a171504b2c1e13c99425712d759e8c2a 100644 (file)
@@ -1,5 +1,6 @@
 #pragma once
 
+#include <cgraph/bitarray.h>
 #include <stddef.h>
 
 #ifdef __cplusplus
@@ -14,7 +15,7 @@ typedef struct term_sgd {
 typedef struct graph_sgd {
     size_t n; // number of nodes
     int *sources; // index of first edge in *targets for each node (length n+1)
-    bool *pinneds; // whether a node is fixed or not
+    bitarray_t pinneds; // whether a node is fixed or not
 
     int *targets; // index of targets for each node (length sources[n])
     float *weights; // weights of edges (length sources[n])