Skip to content
Snippets Groups Projects
Commit f1a7683c authored by dawehr's avatar dawehr
Browse files

Fixed error with reading/writing wrong bit location in ID exist array.

parent f0a8048e
No related branches found
No related tags found
1 merge request!11Add node to computation graph by ID
......@@ -11,9 +11,9 @@ static double exec_input_vals[GRAPH_MAX_INPUTS];
// Macro functions for setting and clearing single bits in int array
// From http://www.mathcs.emory.edu/~cheung/Courses/255/Syllabus/1-C-intro/bit-array.html
#define setBit(A,k) ( A[(k / sizeof(int))] |= (1 << (k % sizeof(int))) )
#define clearBit(A,k) ( A[(k / sizeof(int))] &= ~(1 << (k % sizeof(int))) )
#define testBit(A,k) ( A[(k / sizeof(int))] & (1 << (k % sizeof(int))) )
#define setBit(A,k) ( A[(k / (8*sizeof(int)))] |= (1 << (k % (8*sizeof(int)))) )
#define clearBit(A,k) ( A[(k / (8*sizeof(int)))] &= ~(1 << (k % (8*sizeof(int)))) )
#define testBit(A,k) ( A[(k / (8*sizeof(int)))] & (1 << (k % (8*sizeof(int)))) )
struct computation_graph *create_graph() {
struct computation_graph *the_graph = malloc(sizeof(struct computation_graph));
......@@ -120,16 +120,16 @@ int graph_add_node_id(struct computation_graph *graph,
if (!node_arr) { return -1; }
// Number of integers needed to hold new_size bits
size_t new_exist_size = ceil((float)new_size / (8 * sizeof(int))); // ceil(new_size / (bits per int))
int* exist_arr = realloc(graph->node_existence, sizeof(int) * new_exist_size);
if (!exist_arr) {return -1;}
// Set the newly allocated memory to 0
size_t old_exist_size = ceil((float)old_size / (8 * sizeof(int)));
if (old_exist_size != new_exist_size) {
int* exist_arr = realloc(graph->node_existence, sizeof(int) * new_exist_size);
if (!exist_arr) {return -1;}
memset(exist_arr + old_exist_size, 0, (new_exist_size - old_exist_size) * sizeof(int));
graph->node_existence = exist_arr;
}
graph->size = new_size;
graph->nodes = node_arr;
graph->node_existence = exist_arr;
}
struct graph_node *new_node = &graph->nodes[id];
new_node->name = strdup(name);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment