From 9acb80003d1c251dfc8b19cca9ddd5d24ec0174a Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 18 Dec 2021 14:51:17 -0800 Subject: [PATCH] graph_sgd: convert 'pinned' bool array to a bit array --- lib/neatogen/dijkstra.c | 3 ++- lib/neatogen/sgd.c | 7 ++++--- lib/neatogen/sgd.h | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/neatogen/dijkstra.c b/lib/neatogen/dijkstra.c index 7b60ce68f..eb851501b 100644 --- a/lib/neatogen/dijkstra.c +++ b/lib/neatogen/dijkstra.c @@ -18,6 +18,7 @@ ******************************************/ #include +#include #include #include #include @@ -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] || closestpinneds, closest) || closest +#include #include #include #include @@ -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); diff --git a/lib/neatogen/sgd.h b/lib/neatogen/sgd.h index af11526c7..52f353a8a 100644 --- a/lib/neatogen/sgd.h +++ b/lib/neatogen/sgd.h @@ -1,5 +1,6 @@ #pragma once +#include #include #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]) -- 2.50.0