From cd28b679e5e1866cfa4860633cb7af058a4d557e Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 1 Nov 2006 11:31:20 +0000 Subject: [PATCH] Mike's changes to dsf.c alter the internal storage format of dsf structures, meaning that ad-hoc initialisation now doesn't work. Hence, this checkin converts all ad-hoc dsf initialisations into calls to dsf_init() or snew_dsf(). At least, I _hope_ I've caught all of them. git-svn-id: svn://svn.tartarus.org/sgt/puzzles@6888 cda61777-01e9-0310-a592-d414129be87e --- bridges.c | 6 ++---- map.c | 3 +-- net.c | 4 +--- slant.c | 13 ++++--------- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/bridges.c b/bridges.c index be173ff..93faf32 100644 --- a/bridges.c +++ b/bridges.c @@ -1064,8 +1064,7 @@ static void map_group(game_state *state) struct island *is, *is_join; /* Initialise dsf. */ - for (i = 0; i < wh; i++) - dsf[i] = i; + dsf_init(dsf, wh); /* For each island, find connected islands right or down * and merge the dsf for the island squares as well as the @@ -1602,9 +1601,8 @@ static game_state *new_state(game_params *params) ret->solved = ret->completed = 0; ret->solver = snew(struct solver_state); - ret->solver->dsf = snewn(wh, int); + ret->solver->dsf = snew_dsf(wh); ret->solver->tmpdsf = snewn(wh, int); - for (i = 0; i < wh; i++) ret->solver->dsf[i] = i; ret->solver->refcount = 1; diff --git a/map.c b/map.c index 4ab6c4f..d70d428 100644 --- a/map.c +++ b/map.c @@ -1695,8 +1695,7 @@ static char *parse_edge_list(game_params *params, char **desc, int *map) int i, k, pos, state; char *p = *desc; - for (i = 0; i < wh; i++) - map[wh+i] = i; + dsf_init(map+wh, wh); pos = -1; state = 0; diff --git a/net.c b/net.c index ad970b6..c479963 100644 --- a/net.c +++ b/net.c @@ -521,9 +521,7 @@ static int net_solver(int w, int h, unsigned char *tiles, * classes) by finding the representative of each tile and * setting equivalence[one]=the_other. */ - equivalence = snewn(w * h, int); - for (i = 0; i < w*h; i++) - equivalence[i] = i; /* initially all distinct */ + equivalence = snew_dsf(w * h); /* * On a non-wrapping grid, we instantly know that all the edges diff --git a/slant.c b/slant.c index 6c540ba..c1ddc09 100644 --- a/slant.c +++ b/slant.c @@ -468,15 +468,13 @@ static int slant_solve(int w, int h, const signed char *clues, * Establish a disjoint set forest for tracking connectedness * between grid points. */ - for (i = 0; i < W*H; i++) - sc->connected[i] = i; /* initially all distinct */ + dsf_init(sc->connected, W*H); /* * Establish a disjoint set forest for tracking which squares * are known to slant in the same direction. */ - for (i = 0; i < w*h; i++) - sc->equiv[i] = i; /* initially all distinct */ + dsf_init(sc->equiv, w*h); /* * Clear the slashval array. @@ -1006,9 +1004,7 @@ static void slant_generate(int w, int h, signed char *soln, random_state *rs) * Establish a disjoint set forest for tracking connectedness * between grid points. */ - connected = snewn(W*H, int); - for (i = 0; i < W*H; i++) - connected[i] = i; /* initially all distinct */ + connected = snew_dsf(W*H); /* * Prepare a list of the squares in the grid, and fill them in @@ -1389,8 +1385,7 @@ static int check_completion(game_state *state) * edge is visited at most twice. */ dsf = state->clues->tmpdsf; - for (i = 0; i < W*H; i++) - dsf[i] = i; /* initially all distinct */ + dsf_init(dsf, W*H); for (y = 0; y < h; y++) for (x = 0; x < w; x++) { int i1, i2; -- 2.11.0