Use `HashMap` to count cell assignment in `dev::Region`

This commit is contained in:
Brechtpd 2022-07-06 16:42:41 +08:00 committed by han0110
parent 5eac2ad543
commit f9923c8dd6
1 changed files with 14 additions and 6 deletions

View File

@ -49,9 +49,9 @@ struct Region {
/// The selectors that have been enabled in this region. All other selectors are by
/// construction not enabled.
enabled_selectors: HashMap<Selector, Vec<usize>>,
/// The cells assigned in this region. We store this as a `Vec` so that if any cells
/// The cells assigned in this region. We store this as a `HashMap` with count so that if any cells
/// are double-assigned, they will be visibly darker.
cells: Vec<(Column<Any>, usize)>,
cells: HashMap<(Column<Any>, usize), usize>,
}
impl Region {
@ -307,7 +307,7 @@ impl<F: Field + Group> Assignment<F> for MockProver<F> {
columns: HashSet::default(),
rows: None,
enabled_selectors: HashMap::default(),
cells: vec![],
cells: HashMap::default(),
});
}
@ -374,7 +374,11 @@ impl<F: Field + Group> Assignment<F> for MockProver<F> {
if let Some(region) = self.current_region.as_mut() {
region.update_extent(column.into(), row);
region.cells.push((column.into(), row));
region
.cells
.entry((column.into(), row))
.and_modify(|count| *count += 1)
.or_default();
}
*self
@ -406,7 +410,11 @@ impl<F: Field + Group> Assignment<F> for MockProver<F> {
if let Some(region) = self.current_region.as_mut() {
region.update_extent(column.into(), row);
region.cells.push((column.into(), row));
region
.cells
.entry((column.into(), row))
.and_modify(|count| *count += 1)
.or_default();
}
*self
@ -579,7 +587,7 @@ impl<F: FieldExt> MockProver<F> {
let cell_row = ((gate_row + n + cell.rotation.0) % n) as usize;
// Check that it was assigned!
if r.cells.contains(&(cell.column, cell_row)) {
if r.cells.contains_key(&(cell.column, cell_row)) {
None
} else {
Some(VerifyFailure::CellNotAssigned {