Similar to the prior commit, the previous code was actually a _deoptimization_.
int i;
static boolean *node_in_neighborhood = NULL;
static int size = 0;
- static int *index;
Queue Q;
heap H;
int closestVertex, neighbor;
node_in_neighborhood[visited_nodes[i]] = TRUE;
}
-
- index = realloc(index, n * sizeof(int));
+ int *index = gcalloc(n, sizeof(int));
/* initial distances with edge weights: */
for (i = 0; i < n; i++) /* far, TOO COSTLY (O(n))! */
node_in_neighborhood[visited_nodes[i]] = FALSE;
}
freeHeap(&H);
+ free(index);
freeQueue(&Q);
return num_visited_nodes;
}