simon-git: puzzles (main): Simon Tatham
Commits to Tartarus hosted VCS
tartarus-commits at lists.tartarus.org
Thu Apr 20 18:49:03 BST 2023
TL;DR:
6c02b72 Remove an unnecessary extern function declaration.
16f997d Stop putting dsfs in existing scratch int arrays.
bb561ee Use a dedicated free function to free dsfs.
11a8149 Use a dedicated copy function to copy dsfs.
f21c7d2 Consistently use snew_dsf to allocate dsfs.
7abf85a Remove a direct use of dsf internals in Filling.
89c438e Declare all dsfs as a dedicated type name 'DSF'.
095224d Actually make DSF an opaque structure type.
dad2f35 Store a size field inside the DSF type.
348aac4 Remove size parameter from dsf init and copy functions.
088fdee Remove conditioned-out dsf diagnostic code.
14e1e05 Introduce a new dsf_equivalent() function.
c5e253a Reorganise the dsf API into three kinds of dsf.
68d242c Actually rewrite the dsf implementation.
9f08986 Update the documentation for the dsf functions.
Repository: https://git.tartarus.org/simon/puzzles.git
On the web: https://git.tartarus.org/?p=simon/puzzles.git
Branch updated: main
Committer: Simon Tatham <anakin at pobox.com>
Date: 2023-04-20 18:49:03
commit 6c02b72d766fcb6a9598bdde80294a41e53cd02c
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=6c02b72d766fcb6a9598bdde80294a41e53cd02c;hp=0d86fe4b748e72fb8491a7e8bea7bb0a923b9f79
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 14:08:02 2023 +0100
Remove an unnecessary extern function declaration.
unfinished/separate.c had its own declaration of divvy_rectangle(),
duplicating the one in puzzles.h. Probably that was where the
declaration originally lived, before I moved it out into the main
header.
unfinished/separate.c | 1 -
1 file changed, 1 deletion(-)
commit 16f997d34c7b435d3fcf5774c700579e188b017f
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=16f997d34c7b435d3fcf5774c700579e188b017f;hp=6c02b72d766fcb6a9598bdde80294a41e53cd02c
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 13:13:47 2023 +0100
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.
divvy.c | 12 +++++++-----
dominosa.c | 14 +++++++++-----
map.c | 39 +++++++++++++++++++++++++--------------
tents.c | 5 +++--
4 files changed, 44 insertions(+), 26 deletions(-)
commit bb561ee3b18be69e52b17cedde50eac96ea409da
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=bb561ee3b18be69e52b17cedde50eac96ea409da;hp=16f997d34c7b435d3fcf5774c700579e188b017f
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 13:35:58 2023 +0100
Use a dedicated free function to free dsfs.
No functional change: currently, this just wraps the previous sfree
call.
auxiliary/divvy-test.c | 2 +-
bridges.c | 4 ++--
divvy.c | 2 +-
dominosa.c | 2 +-
dsf.c | 5 +++++
filling.c | 12 ++++++------
galaxies.c | 6 +++---
grid.c | 2 +-
keen.c | 16 ++++++++--------
loopy.c | 6 +++---
map.c | 2 +-
net.c | 2 +-
palisade.c | 14 +++++++-------
pearl.c | 6 +++---
puzzles.h | 1 +
range.c | 4 ++--
signpost.c | 2 +-
singles.c | 2 +-
slant.c | 6 +++---
solo.c | 22 +++++++++++-----------
tents.c | 2 +-
tracks.c | 6 +++---
unfinished/separate.c | 4 ++--
unfinished/slide.c | 4 ++--
24 files changed, 70 insertions(+), 64 deletions(-)
commit 11a8149d673d96bec17d6487b5fa95b5bf5ffd6b
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=11a8149d673d96bec17d6487b5fa95b5bf5ffd6b;hp=bb561ee3b18be69e52b17cedde50eac96ea409da
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 13:52:13 2023 +0100
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.
bridges.c | 8 ++++----
dsf.c | 5 +++++
loopy.c | 6 ++----
puzzles.h | 2 ++
signpost.c | 2 +-
5 files changed, 14 insertions(+), 9 deletions(-)
commit f21c7d27664bc43d3e5a9401756860c03055c3aa
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=f21c7d27664bc43d3e5a9401756860c03055c3aa;hp=11a8149d673d96bec17d6487b5fa95b5bf5ffd6b
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 13:56:44 2023 +0100
Consistently use snew_dsf to allocate dsfs.
All remaining cases where a dsf was allocated via snewn(foo, int) are
removed by this change.
bridges.c | 2 +-
filling.c | 2 +-
galaxies.c | 2 +-
loopy.c | 4 ++--
pearl.c | 2 +-
singles.c | 2 +-
slant.c | 4 ++--
tracks.c | 6 ++----
8 files changed, 11 insertions(+), 13 deletions(-)
commit 7abf85a9c6b460698994d9cfa538b7b26fed5e87
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=7abf85a9c6b460698994d9cfa538b7b26fed5e87;hp=f21c7d27664bc43d3e5a9401756860c03055c3aa
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 14:00:23 2023 +0100
Remove a direct use of dsf internals in Filling.
The expression 'dsf[foo] >> 2' already has a sensible wrapper
function, but Filling wasn't bothering to call it.
filling.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
commit 89c438e149a91fffa74b2669f7e0cd05abc3420f
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=89c438e149a91fffa74b2669f7e0cd05abc3420f;hp=7abf85a9c6b460698994d9cfa538b7b26fed5e87
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 14:06:43 2023 +0100
Declare all dsfs as a dedicated type name 'DSF'.
In this commit, 'DSF' is simply a typedef for 'int', so that the new
declaration form 'DSF *' translates to the same type 'int *' that dsfs
have always had. So all we're doing here is mechanically changing type
declarations throughout the code.
auxiliary/divvy-test.c | 2 +-
bridges.c | 21 +++++++++++++--------
divvy.c | 9 +++++----
dominosa.c | 3 ++-
dsf.c | 18 +++++++++---------
filling.c | 24 ++++++++++++++----------
galaxies.c | 9 +++++----
grid.c | 2 +-
keen.c | 15 ++++++++-------
loopy.c | 9 +++++----
map.c | 2 +-
net.c | 2 +-
palisade.c | 11 ++++++-----
pearl.c | 8 +++++---
puzzles.h | 25 +++++++++++++------------
range.c | 2 +-
signpost.c | 2 +-
singles.c | 6 +++---
slant.c | 11 ++++++-----
solo.c | 14 +++++++-------
tents.c | 3 ++-
tracks.c | 12 +++++++-----
unfinished/separate.c | 4 ++--
unfinished/slide.c | 8 ++++----
24 files changed, 122 insertions(+), 100 deletions(-)
commit 095224d5711f3482d6be0ffc01621143f25c7104
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=095224d5711f3482d6be0ffc01621143f25c7104;hp=89c438e149a91fffa74b2669f7e0cd05abc3420f
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 14:12:11 2023 +0100
Actually make DSF an opaque structure type.
This makes good on all the previous preparatory commits, which I did
separately so that each one individually has a reasonably readable
diff, and all the mechanical changes are separated out from the
rewrites that needed actual thought.
Still no functional change, however: the DSF type wraps nothing but
the same int pointer that 'DSF *' used to store directly.
dsf.c | 43 +++++++++++++++++++++++++------------------
puzzles.h | 2 +-
2 files changed, 26 insertions(+), 19 deletions(-)
commit dad2f35502c611dae758915cfb6dface4a303550
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=dad2f35502c611dae758915cfb6dface4a303550;hp=095224d5711f3482d6be0ffc01621143f25c7104
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 14:25:22 2023 +0100
Store a size field inside the DSF type.
This permits bounds-checking of all inputs to dsf_canonify and
dsf_merge, so that any out-of-range values will provoke assertion
failure instead of undefined behaviour.
dsf.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
commit 348aac4c85da21e09c29c58866d178df3204d73c
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=348aac4c85da21e09c29c58866d178df3204d73c;hp=dad2f35502c611dae758915cfb6dface4a303550
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 14:46:46 2023 +0100
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.
bridges.c | 13 ++++++-------
dominosa.c | 2 +-
dsf.c | 12 +++++++-----
filling.c | 6 +++---
galaxies.c | 4 ++--
keen.c | 5 ++---
loopy.c | 4 ++--
pearl.c | 2 +-
puzzles.h | 6 ++++--
signpost.c | 6 +++---
singles.c | 2 +-
slant.c | 4 ++--
tents.c | 2 +-
tracks.c | 2 +-
unfinished/separate.c | 2 +-
15 files changed, 37 insertions(+), 35 deletions(-)
commit 088fdeee38599b1711ba8766d36c652f1355e36e
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=088fdeee38599b1711ba8766d36c652f1355e36e;hp=348aac4c85da21e09c29c58866d178df3204d73c
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 14:57:42 2023 +0100
Remove conditioned-out dsf diagnostic code.
print_dsf was declared in puzzles.h, but never called, and its
definition was commented out. So it probably wouldn't still have
worked anyway. The other commented-out printfs in that file don't look
very useful either, and they just mean more stuff will need messing
about with as I continue to refactor.
dsf.c | 68 ---------------------------------------------------------------
puzzles.h | 2 --
2 files changed, 70 deletions(-)
commit 14e1e05510ac02a5502823bafe46d98c6fab3e5c
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=14e1e05510ac02a5502823bafe46d98c6fab3e5c;hp=088fdeee38599b1711ba8766d36c652f1355e36e
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 15:32:10 2023 +0100
Introduce a new dsf_equivalent() function.
Not very interesting, but the idiom for checking equivalence via two
calls to dsf_canonify is cumbersome enough to be worth abbreviating.
bridges.c | 6 +++---
divvy.c | 2 +-
dsf.c | 5 +++++
keen.c | 18 +++++++++---------
palisade.c | 8 ++++----
puzzles.h | 5 +++++
signpost.c | 2 +-
7 files changed, 28 insertions(+), 18 deletions(-)
commit c5e253a9f9d3d651227ccad56e2c7526ee1f3eba
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=c5e253a9f9d3d651227ccad56e2c7526ee1f3eba;hp=14e1e05510ac02a5502823bafe46d98c6fab3e5c
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 17:27:21 2023 +0100
Reorganise the dsf API into three kinds of dsf.
This is preparing to separate out the auxiliary functionality, and
perhaps leave space for making more of it in future.
The previous name 'edsf' was too vague: the 'e' stood for 'extended',
and didn't say anything about _how_ it was extended. It's now called a
'flip dsf', since it tracks whether elements in the same class are
flipped relative to each other. More importantly, clients that are
going to use the flip tracking must say so when they allocate the dsf.
And Keen's need to track the minimal element of an equivalence class
is going to become a non-default feature, so there needs to be a new
kind of dsf that specially tracks those, and Keen will have to call it.
While I'm here, I've renamed the three dsf creation functions so that
they start with 'dsf_' like all the rest of the dsf API.
bridges.c | 4 ++--
divvy.c | 4 ++--
dominosa.c | 12 +++++------
dsf.c | 26 ++++++++++++++--------
filling.c | 8 +++----
galaxies.c | 6 +++---
grid.c | 2 +-
keen.c | 44 ++++++++++++++++++-------------------
loopy.c | 60 +++++++++++++++++++++++++--------------------------
map.c | 2 +-
net.c | 2 +-
palisade.c | 6 +++---
pearl.c | 4 ++--
puzzles.h | 44 ++++++++++++++++++++-----------------
range.c | 2 +-
signpost.c | 2 +-
singles.c | 2 +-
slant.c | 6 +++---
solo.c | 2 +-
tents.c | 2 +-
tracks.c | 6 +++---
unfinished/separate.c | 2 +-
unfinished/slide.c | 6 +++---
23 files changed, 133 insertions(+), 121 deletions(-)
commit 68d242c5875ec1133429c656520b2d173c05e387
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=68d242c5875ec1133429c656520b2d173c05e387;hp=c5e253a9f9d3d651227ccad56e2c7526ee1f3eba
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 17:13:47 2023 +0100
Actually rewrite the dsf implementation.
This rewrite improves the core data structure implementation in two
ways. Firstly, when merging two equivalence classes, we check their
relative sizes, and choose the larger class's canonical element to be
the overall root of the new class tree. This minimises the number of
overlong paths to the root after the merge. Secondly, we defer path
compression until _after_ the two classes are merged, rather than do
it beforehand (via using edsf_canonify as a subroutine) and then have
to do it wastefully again afterwards.
The size-based root selection was what we _used_ to do, and delivers
the better asymptotic performance. I reverted it so that Keen could
track the min of each equivalence class. But since then I've realised
you can have the asymptotic goodness _and_ min-tracking if you store
the minima separately from the main data structure. So now Keen does
that, and other clients don't have to pay the cost.
Similarly, the flip tracking is now a cost that only users of flip
dsfs have to pay, because a normal one doesn't store that information
at all.
dsf.c | 356 ++++++++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 250 insertions(+), 106 deletions(-)
commit 9f08986cf1b5dd58fc618e54ba45b85e7ba10cc9
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=9f08986cf1b5dd58fc618e54ba45b85e7ba10cc9;hp=68d242c5875ec1133429c656520b2d173c05e387
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Apr 20 15:13:06 2023 +0100
Update the documentation for the dsf functions.
Easier to do this all in one go after I've finished messing about.
devel.but | 138 +++++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 87 insertions(+), 51 deletions(-)
More information about the tartarus-commits
mailing list