******************************************/
#include <assert.h>
+#include <cgraph/bitarray.h>
#include <common/memory.h>
#include <float.h>
#include <neatogen/bfs.h>
}
// 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;
#include <assert.h>
+#include <cgraph/bitarray.h>
#include <limits.h>
#include <neatogen/neato.h>
#include <neatogen/sgd.h>
}
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);
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;
}
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);
#pragma once
+#include <cgraph/bitarray.h>
#include <stddef.h>
#ifdef __cplusplus
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])