mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Use a dedicated copy function to copy dsfs.
Previously we were duplicating the contents of a dsf using straight-up memcpy. Now there's a dsf_copy function wrapping the same memcpy. For the moment, this still has to take a size parameter, because the size isn't stored inside the dsf itself. But once we make a proper data type, it will be.
This commit is contained in:
@ -1551,7 +1551,7 @@ static bool solve_island_stage3(struct island *is, bool *didsth_r)
|
|||||||
maxb = -1;
|
maxb = -1;
|
||||||
/* We have to squirrel the dsf away and restore it afterwards;
|
/* We have to squirrel the dsf away and restore it afterwards;
|
||||||
* it is additive only, and can't be removed from. */
|
* it is additive only, and can't be removed from. */
|
||||||
memcpy(ss->tmpdsf, ss->dsf, wh*sizeof(int));
|
dsf_copy(ss->tmpdsf, ss->dsf, wh);
|
||||||
for (n = curr+1; n <= curr+spc; n++) {
|
for (n = curr+1; n <= curr+spc; n++) {
|
||||||
solve_join(is, i, n, false);
|
solve_join(is, i, n, false);
|
||||||
map_update_possibles(is->state);
|
map_update_possibles(is->state);
|
||||||
@ -1567,7 +1567,7 @@ static bool solve_island_stage3(struct island *is, bool *didsth_r)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
solve_join(is, i, curr, false); /* put back to before. */
|
solve_join(is, i, curr, false); /* put back to before. */
|
||||||
memcpy(ss->dsf, ss->tmpdsf, wh*sizeof(int));
|
dsf_copy(ss->dsf, ss->tmpdsf, wh);
|
||||||
|
|
||||||
if (maxb != -1) {
|
if (maxb != -1) {
|
||||||
/*debug_state(is->state);*/
|
/*debug_state(is->state);*/
|
||||||
@ -1636,7 +1636,7 @@ static bool solve_island_stage3(struct island *is, bool *didsth_r)
|
|||||||
is->adj.points[j].dx ? G_LINEH : G_LINEV);
|
is->adj.points[j].dx ? G_LINEH : G_LINEV);
|
||||||
if (before[i] != 0) continue; /* this idea is pointless otherwise */
|
if (before[i] != 0) continue; /* this idea is pointless otherwise */
|
||||||
|
|
||||||
memcpy(ss->tmpdsf, ss->dsf, wh*sizeof(int));
|
dsf_copy(ss->tmpdsf, ss->dsf, wh);
|
||||||
|
|
||||||
for (j = 0; j < is->adj.npoints; j++) {
|
for (j = 0; j < is->adj.npoints; j++) {
|
||||||
spc = island_adjspace(is, true, missing, j);
|
spc = island_adjspace(is, true, missing, j);
|
||||||
@ -1651,7 +1651,7 @@ static bool solve_island_stage3(struct island *is, bool *didsth_r)
|
|||||||
|
|
||||||
for (j = 0; j < is->adj.npoints; j++)
|
for (j = 0; j < is->adj.npoints; j++)
|
||||||
solve_join(is, j, before[j], false);
|
solve_join(is, j, before[j], false);
|
||||||
memcpy(ss->dsf, ss->tmpdsf, wh*sizeof(int));
|
dsf_copy(ss->dsf, ss->tmpdsf, wh);
|
||||||
|
|
||||||
if (got) {
|
if (got) {
|
||||||
debug(("island at (%d,%d) must connect in direction (%d,%d) to"
|
debug(("island at (%d,%d) must connect in direction (%d,%d) to"
|
||||||
|
5
dsf.c
5
dsf.c
@ -74,6 +74,11 @@ void dsf_init(int *dsf, int size)
|
|||||||
* bits are the number of elements in the tree. */
|
* bits are the number of elements in the tree. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dsf_copy(int *to, int *from, int size)
|
||||||
|
{
|
||||||
|
memcpy(to, from, size * sizeof(int));
|
||||||
|
}
|
||||||
|
|
||||||
int *snew_dsf(int size)
|
int *snew_dsf(int size)
|
||||||
{
|
{
|
||||||
int *ret;
|
int *ret;
|
||||||
|
6
loopy.c
6
loopy.c
@ -457,8 +457,7 @@ static solver_state *dup_solver_state(const solver_state *sstate) {
|
|||||||
|
|
||||||
ret->dotdsf = snewn(num_dots, int);
|
ret->dotdsf = snewn(num_dots, int);
|
||||||
ret->looplen = snewn(num_dots, int);
|
ret->looplen = snewn(num_dots, int);
|
||||||
memcpy(ret->dotdsf, sstate->dotdsf,
|
dsf_copy(ret->dotdsf, sstate->dotdsf, num_dots);
|
||||||
num_dots * sizeof(int));
|
|
||||||
memcpy(ret->looplen, sstate->looplen,
|
memcpy(ret->looplen, sstate->looplen,
|
||||||
num_dots * sizeof(int));
|
num_dots * sizeof(int));
|
||||||
|
|
||||||
@ -487,8 +486,7 @@ static solver_state *dup_solver_state(const solver_state *sstate) {
|
|||||||
|
|
||||||
if (sstate->linedsf) {
|
if (sstate->linedsf) {
|
||||||
ret->linedsf = snewn(num_edges, int);
|
ret->linedsf = snewn(num_edges, int);
|
||||||
memcpy(ret->linedsf, sstate->linedsf,
|
dsf_copy(ret->linedsf, sstate->linedsf, num_edges);
|
||||||
num_edges * sizeof(int));
|
|
||||||
} else {
|
} else {
|
||||||
ret->linedsf = NULL;
|
ret->linedsf = NULL;
|
||||||
}
|
}
|
||||||
|
@ -431,6 +431,8 @@ void dsf_free(int *dsf);
|
|||||||
|
|
||||||
void print_dsf(int *dsf, int size);
|
void print_dsf(int *dsf, int size);
|
||||||
|
|
||||||
|
void dsf_copy(int *to, int *from, int size);
|
||||||
|
|
||||||
/* Return the canonical element of the equivalence class containing element
|
/* Return the canonical element of the equivalence class containing element
|
||||||
* val. If 'inverse' is non-NULL, this function will put into it a flag
|
* val. If 'inverse' is non-NULL, this function will put into it a flag
|
||||||
* indicating whether the canonical element is inverse to val. */
|
* indicating whether the canonical element is inverse to val. */
|
||||||
|
@ -482,7 +482,7 @@ static void dup_game_to(game_state *to, const game_state *from)
|
|||||||
memcpy(to->next, from->next, to->n*sizeof(int));
|
memcpy(to->next, from->next, to->n*sizeof(int));
|
||||||
memcpy(to->prev, from->prev, to->n*sizeof(int));
|
memcpy(to->prev, from->prev, to->n*sizeof(int));
|
||||||
|
|
||||||
memcpy(to->dsf, from->dsf, to->n*sizeof(int));
|
dsf_copy(to->dsf, from->dsf, to->n);
|
||||||
memcpy(to->numsi, from->numsi, (to->n+1)*sizeof(int));
|
memcpy(to->numsi, from->numsi, (to->n+1)*sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user