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.
This commit is contained in:
Simon Tatham
2023-04-20 17:27:21 +01:00
parent 14e1e05510
commit c5e253a9f9
23 changed files with 131 additions and 119 deletions

View File

@ -409,7 +409,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 = snew_dsf(sz);
dsf = dsf_new(sz);
retry:
dsf_reinit(dsf);
shuffle(board, sz, sizeof (int), rs);
@ -1089,12 +1089,12 @@ static bool solver(const int *orig, int w, int h, char **solution) {
struct solver_state ss;
ss.board = memdup(orig, sz, sizeof (int));
ss.dsf = snew_dsf(sz); /* eqv classes: connected components */
ss.dsf = dsf_new(sz); /* eqv classes: connected components */
ss.connected = snewn(sz, int); /* connected[n] := n.next; */
/* cyclic disjoint singly linked lists, same partitioning as dsf.
* The lists lets you iterate over a partition given any member */
ss.bm = snewn(sz, int);
ss.bmdsf = snew_dsf(sz);
ss.bmdsf = dsf_new(sz);
ss.bmminsize = snewn(sz, int);
printv("trying to solve this:\n");
@ -1135,7 +1135,7 @@ static DSF *make_dsf(DSF *dsf, int *board, const int w, const int h) {
int i;
if (!dsf)
dsf = snew_dsf(w * h);
dsf = dsf_new(w * h);
else
dsf_reinit(dsf);