diff options
| author | Simon Tatham <anakin@pobox.com> | 2023-04-20 14:46:46 +0100 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2023-04-20 17:30:03 +0100 |
| commit | 348aac4c85da21e09c29c58866d178df3204d73c (patch) | |
| tree | eff802bf3ef3b5459bbe268e35328b1155cf3472 /dsf.c | |
| parent | dad2f35502c611dae758915cfb6dface4a303550 (diff) | |
| download | puzzles-348aac4c85da21e09c29c58866d178df3204d73c.zip puzzles-348aac4c85da21e09c29c58866d178df3204d73c.tar.gz puzzles-348aac4c85da21e09c29c58866d178df3204d73c.tar.bz2 puzzles-348aac4c85da21e09c29c58866d178df3204d73c.tar.xz | |
Remove size parameter from dsf init and copy functions.
Now that the dsf knows its own size internally, there's no need to
tell it again when one is copied or reinitialised.
This makes dsf_init much more about *re*initialising a dsf, since now
dsfs are always allocated using a function that will initialise them
anyway. So I think it deserves a rename.
Diffstat (limited to 'dsf.c')
| -rw-r--r-- | dsf.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -66,11 +66,12 @@ done: sfree(inverse_elements); }*/ -void dsf_init(DSF *dsf, int size) +void dsf_reinit(DSF *dsf) { int i; - for (i = 0; i < size; i++) dsf->p[i] = 6; + for (i = 0; i < dsf->size; i++) + dsf->p[i] = 6; /* Bottom bit of each element of this array stores whether that * element is opposite to its parent, which starts off as * false. Second bit of each element stores whether that element @@ -79,9 +80,10 @@ void dsf_init(DSF *dsf, int size) * bits are the number of elements in the tree. */ } -void dsf_copy(DSF *to, DSF *from, int size) +void dsf_copy(DSF *to, DSF *from) { - memcpy(to->p, from->p, size * sizeof(int)); + assert(to->size == from->size && "Mismatch in dsf_copy"); + memcpy(to->p, from->p, to->size * sizeof(int)); } DSF *snew_dsf(int size) @@ -90,7 +92,7 @@ DSF *snew_dsf(int size) ret->size = size; ret->p = snewn(size, int); - dsf_init(ret, size); + dsf_reinit(ret); /*print_dsf(ret, size); */ |