Fairly sure it's working now

This commit is contained in:
Miguel M 2023-06-05 21:08:32 +01:00
parent ef6f80aaaf
commit 1209fd27ec
1 changed files with 21 additions and 20 deletions

View File

@ -28,19 +28,21 @@ static _Bool ReadArguments(char *from, size_t *into, const char *varname) {
}
static inline void AdvanceConditionalPermutations(
permutation_generator_t *generators, size_t count) {
PermutationNext(generators);
permutation_generator_t *generators, const size_t count) {
PermutationNext(generators + 0);
for (size_t i = 0; i < count - 1; i++) {
if (generators[i].exhausted) {
PermutationReset(generators + i);
PermutationNext(generators + i + 1);
} else {
break;
}
}
// If generators[-1] is exhausted, the conditional permutations are exhausted.
}
static inline void ResetConditionalPermutations(
permutation_generator_t *generators, size_t count) {
permutation_generator_t *generators, const size_t count) {
for (size_t i = 0; i < count; i++) {
PermutationReset(generators + i);
}
@ -203,10 +205,10 @@ static void UniqueInBlock(const size_t a_in, const size_t b_in,
while (!a_in_perm->exhausted) {
PermutationReset(b_in_perm);
while (!b_in_perm->exhausted) {
ResetConditionalPermutations(a_out_perms, a_out);
while (!a_out_perms[a_out - 1].exhausted) {
ResetConditionalPermutations(b_out_perms, b_out);
while (!b_out_perms[b_out - 1].exhausted) {
ResetConditionalPermutations(a_out_perms, a_in);
while (!a_out_perms[a_in - 1].exhausted) {
ResetConditionalPermutations(b_out_perms, b_in);
while (!b_out_perms[b_in - 1].exhausted) {
// Compare the two rows
// TODO: Figure out why both A==B and B==A need to be checked.
// Of note is that the pathological case I found occurs under a
@ -255,10 +257,10 @@ static void UniqueInBlock(const size_t a_in, const size_t b_in,
goto skip_permutations;
}
}
AdvanceConditionalPermutations(b_out_perms, b_out);
AdvanceConditionalPermutations(b_out_perms, b_in);
}
AdvanceConditionalPermutations(a_out_perms, a_out);
AdvanceConditionalPermutations(a_out_perms, a_in);
}
PermutationNext(b_in_perm);
@ -342,10 +344,10 @@ static void UniqueInSubsetPair(
while (!a_in_perm->exhausted) {
PermutationReset(b_in_perm);
while (!b_in_perm->exhausted) {
ResetConditionalPermutations(a_out_perms, a_out);
while (!a_out_perms[a_out - 1].exhausted) {
ResetConditionalPermutations(b_out_perms, b_out);
while (!b_out_perms[b_out - 1].exhausted) {
ResetConditionalPermutations(a_out_perms, a_in);
while (!a_out_perms[a_in - 1].exhausted) {
ResetConditionalPermutations(b_out_perms, b_in);
while (!b_out_perms[b_in - 1].exhausted) {
// TODO: Figure out why both A==B and B==A need to be checked.
// Of note is that the pathological case I found occurs under a
// party swap.
@ -394,10 +396,10 @@ static void UniqueInSubsetPair(
}
}
AdvanceConditionalPermutations(b_out_perms, b_out);
AdvanceConditionalPermutations(b_out_perms, b_in);
}
AdvanceConditionalPermutations(a_out_perms, a_out);
AdvanceConditionalPermutations(a_out_perms, a_in);
}
PermutationNext(b_in_perm);
@ -500,11 +502,9 @@ int main(int argc, char *argv[]) {
for (size_t i = 0; i < a_in; i++) {
a_out_perms[i] = PermutationNewGenerator(a_out);
PermutationReset(a_out_perms + i);
}
for (size_t i = 0; i < b_in; i++) {
b_out_perms[i] = PermutationNewGenerator(b_out);
PermutationReset(b_out_perms + i);
}
// Base round
@ -542,6 +542,7 @@ int main(int argc, char *argv[]) {
} // End of omp for
// Implicit barrier
/*
#pragma omp single
{
printf("Base round results:\n");
@ -564,7 +565,7 @@ int main(int argc, char *argv[]) {
printf("]\n");
}
printf("\nReduction rounds:\n");
}
}*/
// Reductions round
@ -642,7 +643,7 @@ int main(int argc, char *argv[]) {
stbds_arrput(ends_swap, last_end + odd_block_len);
}
// ---
/*
size_t count = stbds_arrlen(ends_swap);
for (size_t i = 0; i < count; i++) {
size_t *block;
@ -662,7 +663,7 @@ int main(int argc, char *argv[]) {
printf("] ");
}
printf("\n");
// ---
*/
stbds_arrfree(unique);
stbds_arrfree(ends);