int main() { dfs_stack_t stack = dfs_stack_create (ARRAY_SIZE); size_t x; printf("Filling stack\n"); for (x = 0; x<NUM; x++) { int ar[ARRAY_SIZE]; ar[0] = x; ar[ARRAY_SIZE-1] = -x; dfs_stack_push(stack, ar); if (x%(NUM/FRAMES)==0) { printf("entered frame after: %zu - %zu\n", x, -x); dfs_stack_enter(stack); } } char tmp[256]; ssize_t tmpsz = sizeof tmp; printf("%s\n", dfs_stack_to_string(stack, tmp, &tmpsz)); for (x = 0; x<=FRAMES; x++) { int* ar = dfs_stack_peek_top(stack, x); printf("peek_top(%zu): %d - %d\n", x, ar[0], ar[ARRAY_SIZE-1]); } printf("Emptying stack stack\n"); for (x = 0; x<NUM; x++) { int* ar; if ((ar = dfs_stack_top(stack))==NULL) { dfs_stack_leave(stack); ar = dfs_stack_top(stack); printf("leave frame before: %d - %d\n", ar[0], ar[ARRAY_SIZE-1]); } ar = dfs_stack_pop(stack); } printf("DONE\n"); //pop(stack); dfs_stack_destroy(stack); return 0; }
/** * update lowlink for the parent (top of previous stackframe in search_stack) */ static void update_parent (wctx_t *ctx, uint32_t low_child) { alg_local_t *loc = ctx->local; raw_data_t state_data; // the initial state has no parent if (dfs_stack_nframes (loc->search_stack) == 0) return; // store the top of the previous stackframe to loc->target state_data = dfs_stack_peek_top (loc->search_stack, 1); state_info_deserialize (loc->target, state_data); if (loc->target_tarjan.lowlink > low_child) { Debug ("Updating %zu from low %d --> %d", loc->target->ref, loc->target_tarjan.lowlink, low_child); loc->target_tarjan.lowlink = low_child; state_info_serialize (loc->target, state_data); } }