mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 23:51:29 -07:00
Stop putting dsfs in existing scratch int arrays.
I'm going to work towards turning 'dsf' into an opaque type, so that I can improve its implementation without breaking clients. The first step is to deal manually with puzzles that currently reuse a single array of ints for multiple purposes, some of which are dsf and some are not. In divvy_rectangle_attempt, 'tmp' was used as an int array and later a dsf, and I've made a new 'tmpdsf' to be the latter. In Dominosa, solver->pc_scratch2 was sometimes a dsf, and now there's a new solver->dsf_scratch. In Map, parse_edge_list() needed a dsf internally and then never exported it; it expected to be passed an array of 2*w*h ints and used the second half as a dsf. Now it expects only w*h ints, and allocates its own dsf internally, freeing it again before returning. And in Tents, find_errors() was allocating a single block of 2*w*h ints and using the second half of it as a dsf, apparently just to save one malloc. Now we malloc and free the dsf separately.
This commit is contained in:
5
tents.c
5
tents.c
@ -2006,7 +2006,7 @@ static int *find_errors(const game_state *state, char *grid)
|
||||
{
|
||||
int w = state->p.w, h = state->p.h;
|
||||
int *ret = snewn(w*h + w + h, int);
|
||||
int *tmp = snewn(w*h*2, int), *dsf = tmp + w*h;
|
||||
int *tmp = snewn(w*h, int), *dsf;
|
||||
int x, y;
|
||||
|
||||
/*
|
||||
@ -2223,7 +2223,7 @@ static int *find_errors(const game_state *state, char *grid)
|
||||
* all the tents in any component which has a smaller tree
|
||||
* count.
|
||||
*/
|
||||
dsf_init(dsf, w*h);
|
||||
dsf = snew_dsf(w*h);
|
||||
/* Construct the equivalence classes. */
|
||||
for (y = 0; y < h; y++) {
|
||||
for (x = 0; x < w-1; x++) {
|
||||
@ -2302,6 +2302,7 @@ static int *find_errors(const game_state *state, char *grid)
|
||||
#undef TENT
|
||||
|
||||
sfree(tmp);
|
||||
sfree(dsf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user