Add a few comments to the permutation construction code

We mainly point at the design document that describes the algorithm.
This commit is contained in:
Jack Grigg 2020-12-22 20:20:58 +00:00
parent 1ba246f7d9
commit 62cace289b

View file

@ -30,6 +30,9 @@ impl Assembly {
columns.push((0..params.n).map(|j| (i, j as usize)).collect());
}
// Before any equality constraints are applied, every cell in the permutation is
// in a 1-cycle; therefore mapping and aux are identical, because every cell is
// its own distinguished element.
Assembly {
mapping: columns.clone(),
aux: columns,
@ -53,9 +56,12 @@ impl Assembly {
return Err(Error::BoundsFailure);
}
// See book/src/design/permutation.md for a description of this algorithm.
let mut left_cycle = self.aux[left_column][left_row];
let mut right_cycle = self.aux[right_column][right_row];
// If left and right are in the same cycle, do nothing.
if left_cycle == right_cycle {
return Ok(());
}
@ -64,6 +70,7 @@ impl Assembly {
std::mem::swap(&mut left_cycle, &mut right_cycle);
}
// Merge the right cycle into the left one.
self.sizes[left_cycle.0][left_cycle.1] += self.sizes[right_cycle.0][right_cycle.1];
let mut i = right_cycle;
loop {