Consistently use snew_dsf to allocate dsfs.

All remaining cases where a dsf was allocated via snewn(foo, int) are
removed by this change.
This commit is contained in:
Simon Tatham
2023-04-20 13:56:44 +01:00
parent 11a8149d67
commit f21c7d2766
8 changed files with 11 additions and 13 deletions

View File

@ -1771,7 +1771,7 @@ static game_state *new_state(const game_params *params)
ret->solver = snew(struct solver_state);
ret->solver->dsf = snew_dsf(wh);
ret->solver->tmpdsf = snewn(wh, int);
ret->solver->tmpdsf = snew_dsf(wh);
ret->solver->refcount = 1;

View File

@ -407,7 +407,7 @@ static void make_board(int *board, int w, int h, random_state *rs) {
* contains a shuffled list of numbers {0, ..., sz-1}. */
for (i = 0; i < sz; ++i) board[i] = i;
dsf = snewn(sz, int);
dsf = snew_dsf(sz);
retry:
dsf_init(dsf, sz);
shuffle(board, sz, sizeof (int), rs);

View File

@ -3959,7 +3959,7 @@ static void game_print(drawing *dr, const game_state *state, int sz)
/*
* Get the completion information.
*/
dsf = snewn(w * h, int);
dsf = snew_dsf(w * h);
colours = snewn(w * h, int);
check_complete(state, dsf, colours);

View File

@ -455,7 +455,7 @@ static solver_state *dup_solver_state(const solver_state *sstate) {
ret->solver_status = sstate->solver_status;
ret->diff = sstate->diff;
ret->dotdsf = snewn(num_dots, int);
ret->dotdsf = snew_dsf(num_dots);
ret->looplen = snewn(num_dots, int);
dsf_copy(ret->dotdsf, sstate->dotdsf, num_dots);
memcpy(ret->looplen, sstate->looplen,
@ -485,7 +485,7 @@ static solver_state *dup_solver_state(const solver_state *sstate) {
}
if (sstate->linedsf) {
ret->linedsf = snewn(num_edges, int);
ret->linedsf = snew_dsf(num_edges);
dsf_copy(ret->linedsf, sstate->linedsf, num_edges);
} else {
ret->linedsf = NULL;

View File

@ -349,7 +349,7 @@ static int pearl_solve(int w, int h, char *clues, char *result,
* We maintain a dsf of connected squares, together with a
* count of the size of each equivalence class.
*/
dsf = snewn(w*h, int);
dsf = snew_dsf(w*h);
dsfsize = snewn(w*h, int);
/*

View File

@ -498,7 +498,7 @@ static int check_rowcol(game_state *state, int starti, int di, int sz, unsigned
static bool check_complete(game_state *state, unsigned flags)
{
int *dsf = snewn(state->n, int);
int *dsf = snew_dsf(state->n);
int x, y, i, error = 0, nwhite, w = state->w, h = state->h;
if (flags & CC_MARK_ERRORS) {

View File

@ -312,10 +312,10 @@ static struct solver_scratch *new_scratch(int w, int h)
{
int W = w+1, H = h+1;
struct solver_scratch *ret = snew(struct solver_scratch);
ret->connected = snewn(W*H, int);
ret->connected = snew_dsf(W*H);
ret->exits = snewn(W*H, int);
ret->border = snewn(W*H, bool);
ret->equiv = snewn(w*h, int);
ret->equiv = snew_dsf(w*h);
ret->slashval = snewn(w*h, signed char);
ret->vbitmap = snewn(w*h, unsigned char);
return ret;

View File

@ -1373,8 +1373,7 @@ static int solve_check_loop(game_state *state)
/* TODO eventually we should pull this out into a solver struct and keep it
updated as we connect squares. For now we recreate it every time we try
this particular solver step. */
dsf = snewn(w*h, int);
dsf_init(dsf, w*h);
dsf = snew_dsf(w*h);
/* Work out the connectedness of the current loop set. */
for (x = 0; x < w; x++) {
@ -1878,8 +1877,7 @@ static bool check_completion(game_state *state, bool mark)
}
}
dsf = snewn(w*h, int);
dsf_init(dsf, w*h);
dsf = snew_dsf(w*h);
for (x = 0; x < w; x++) {
for (y = 0; y < h; y++) {