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.

[originally from svn r6888]
This commit is contained in:
Simon Tatham
2006-11-01 11:31:20 +00:00
parent fe4fd0ebc5
commit 9b31ed25d8
4 changed files with 8 additions and 18 deletions

View File

@ -1064,8 +1064,7 @@ static void map_group(game_state *state)
struct island *is, *is_join; struct island *is, *is_join;
/* Initialise dsf. */ /* Initialise dsf. */
for (i = 0; i < wh; i++) dsf_init(dsf, wh);
dsf[i] = i;
/* For each island, find connected islands right or down /* For each island, find connected islands right or down
* and merge the dsf for the island squares as well as the * 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->solved = ret->completed = 0;
ret->solver = snew(struct solver_state); ret->solver = snew(struct solver_state);
ret->solver->dsf = snewn(wh, int); ret->solver->dsf = snew_dsf(wh);
ret->solver->tmpdsf = snewn(wh, int); ret->solver->tmpdsf = snewn(wh, int);
for (i = 0; i < wh; i++) ret->solver->dsf[i] = i;
ret->solver->refcount = 1; ret->solver->refcount = 1;

3
map.c
View File

@ -1695,8 +1695,7 @@ static char *parse_edge_list(game_params *params, char **desc, int *map)
int i, k, pos, state; int i, k, pos, state;
char *p = *desc; char *p = *desc;
for (i = 0; i < wh; i++) dsf_init(map+wh, wh);
map[wh+i] = i;
pos = -1; pos = -1;
state = 0; state = 0;

4
net.c
View File

@ -521,9 +521,7 @@ static int net_solver(int w, int h, unsigned char *tiles,
* classes) by finding the representative of each tile and * classes) by finding the representative of each tile and
* setting equivalence[one]=the_other. * setting equivalence[one]=the_other.
*/ */
equivalence = snewn(w * h, int); equivalence = snew_dsf(w * h);
for (i = 0; i < w*h; i++)
equivalence[i] = i; /* initially all distinct */
/* /*
* On a non-wrapping grid, we instantly know that all the edges * On a non-wrapping grid, we instantly know that all the edges

13
slant.c
View File

@ -468,15 +468,13 @@ static int slant_solve(int w, int h, const signed char *clues,
* Establish a disjoint set forest for tracking connectedness * Establish a disjoint set forest for tracking connectedness
* between grid points. * between grid points.
*/ */
for (i = 0; i < W*H; i++) dsf_init(sc->connected, W*H);
sc->connected[i] = i; /* initially all distinct */
/* /*
* Establish a disjoint set forest for tracking which squares * Establish a disjoint set forest for tracking which squares
* are known to slant in the same direction. * are known to slant in the same direction.
*/ */
for (i = 0; i < w*h; i++) dsf_init(sc->equiv, w*h);
sc->equiv[i] = i; /* initially all distinct */
/* /*
* Clear the slashval array. * 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 * Establish a disjoint set forest for tracking connectedness
* between grid points. * between grid points.
*/ */
connected = snewn(W*H, int); connected = snew_dsf(W*H);
for (i = 0; i < W*H; i++)
connected[i] = i; /* initially all distinct */
/* /*
* Prepare a list of the squares in the grid, and fill them in * 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. * edge is visited at most twice.
*/ */
dsf = state->clues->tmpdsf; dsf = state->clues->tmpdsf;
for (i = 0; i < W*H; i++) dsf_init(dsf, W*H);
dsf[i] = i; /* initially all distinct */
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
for (x = 0; x < w; x++) { for (x = 0; x < w; x++) {
int i1, i2; int i1, i2;