From 9e5184dbe89946dda121a2a427928d6ba850a43d Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Wed, 25 Jul 2018 18:37:47 -0400 Subject: replaced more in-house objects with c++ std lib ones, performance increased --- lib/cluster.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'lib/cluster.h') diff --git a/lib/cluster.h b/lib/cluster.h index 03b0ac0..8aae02a 100644 --- a/lib/cluster.h +++ b/lib/cluster.h @@ -4,23 +4,25 @@ #include #include #include +#include +#include #include "types.h" #include "state.h" -#include "stack.h" #include "graph.h" template void flip_cluster(state_t *state, v_t v0, R_t r, gsl_rng *rand) { v_t nv = 0; - ll_t *stack = NULL; // create a new stack - stack_push(&stack, v0); // push the initial vertex to the stack + std::stack stack; + stack.push(v0); - bool *marks = (bool *)calloc(state->nv + 1, sizeof(bool)); + std::vector marks(state->g.nv, false); - while (stack != NULL) { - v_t v = stack_pop(&stack); + while (!stack.empty()) { + v_t v = stack.top(); + stack.pop(); if (!marks[v]) { X_t si_old, si_new; @@ -93,7 +95,7 @@ void flip_cluster(state_t *state, v_t v0, R_t r, gsl_rng *rand) { } if (gsl_rng_uniform(rand) < prob) { // and with probability... - stack_push(&stack, vn); // push the neighboring vertex to the stack + stack.push(vn); // push the neighboring vertex to the stack } } @@ -111,8 +113,6 @@ void flip_cluster(state_t *state, v_t v0, R_t r, gsl_rng *rand) { } } - free(marks); - state->last_cluster_size = nv; } -- cgit v1.2.3-70-g09d2