This commit is contained in:
Daniel Lubarov 2021-09-29 12:07:27 -07:00
parent 3f22663296
commit ac97412667
3 changed files with 11 additions and 14 deletions

View File

@ -62,7 +62,7 @@ pub(crate) fn generate_partial_witness<'a, F: RichField + Extendable<D>, const D
let new_target_reps = buffer
.target_values
.drain(..)
.flat_map(|(t, v)| witness.set_target_returning_parent(t, v));
.flat_map(|(t, v)| witness.set_target_returning_rep(t, v));
// Enqueue unfinished generators that were watching one of the newly populated targets.
for watch in new_target_reps {

View File

@ -212,14 +212,10 @@ impl<'a, F: Field> PartitionWitness<'a, F> {
/// Set a `Target`. On success, returns the representative index of the newly-set target. If the
/// target was already set, returns `None`.
pub(crate) fn set_target_returning_parent(
&mut self,
target: Target,
value: F,
) -> Option<usize> {
let parent_index = self.representative_map[self.target_index(target)];
let parent_value = &mut self.values[parent_index];
if let Some(old_value) = *parent_value {
pub(crate) fn set_target_returning_rep(&mut self, target: Target, value: F) -> Option<usize> {
let rep_index = self.representative_map[self.target_index(target)];
let rep_value = &mut self.values[rep_index];
if let Some(old_value) = *rep_value {
assert_eq!(
value, old_value,
"Partition containing {:?} was set twice with different values",
@ -227,8 +223,8 @@ impl<'a, F: Field> PartitionWitness<'a, F> {
);
None
} else {
*parent_value = Some(value);
Some(parent_index)
*rep_value = Some(value);
Some(rep_index)
}
}
@ -253,11 +249,11 @@ impl<'a, F: Field> PartitionWitness<'a, F> {
impl<'a, F: Field> Witness<F> for PartitionWitness<'a, F> {
fn try_get_target(&self, target: Target) -> Option<F> {
let parent_index = self.representative_map[self.target_index(target)];
self.values[parent_index]
let rep_index = self.representative_map[self.target_index(target)];
self.values[rep_index]
}
fn set_target(&mut self, target: Target, value: F) {
self.set_target_returning_parent(target, value);
self.set_target_returning_rep(target, value);
}
}

View File

@ -76,6 +76,7 @@ impl Forest {
}
}
/// Assumes `compress_paths` has already been called.
pub fn wire_partition(&mut self) -> WirePartition {
let mut partition = HashMap::<_, Vec<_>>::new();