From d93cf693ba2c04c2bbbaf4c00fe543ed45b78491 Mon Sep 17 00:00:00 2001 From: wborgeaud Date: Fri, 2 Jul 2021 14:26:49 +0200 Subject: [PATCH] Minor --- src/permutation_argument.rs | 75 ++++++------------------------------- 1 file changed, 11 insertions(+), 64 deletions(-) diff --git a/src/permutation_argument.rs b/src/permutation_argument.rs index 003400de..6a1838a6 100644 --- a/src/permutation_argument.rs +++ b/src/permutation_argument.rs @@ -17,17 +17,6 @@ pub struct ForestNode { index: usize, } -impl ForestNode { - pub fn new(t: T, parent: usize, size: usize, index: usize) -> Self { - Self { - t, - parent, - size, - index, - } - } -} - #[derive(Debug, Clone)] pub struct TargetPartition { forest: Vec>, @@ -44,21 +33,15 @@ impl Default for TargetPartition { } impl TargetPartition { - pub fn get(&self, t: T) -> ForestNode { - self.forest[self.indices[&t]] - } - - pub fn get_mut(&mut self, t: T) -> &mut ForestNode { - &mut self.forest[self.indices[&t]] - } - // pub fn get_partition(&self, target: Target) -> &[Target] { - // &self.partitions[self.indices[&target]] - // } - /// Add a new partition with a single member. pub fn add(&mut self, t: T) { let index = self.forest.len(); - self.forest.push(ForestNode::new(t, index, 1, index)); + self.forest.push(ForestNode { + t, + parent: index, + size: 1, + index, + }); self.indices.insert(t, index); } @@ -75,10 +58,10 @@ impl TargetPartition { /// Merge the two partitions containing the two given targets. Does nothing if the targets are /// already members of the same partition. pub fn merge(&mut self, tx: T, ty: T) { - let mut x = self.get(tx); - let mut y = self.get(ty); - let index_x = x.index; - let index_y = y.index; + let index_x = self.indices[&tx]; + let index_y = self.indices[&ty]; + let mut x = self.forest[index_x]; + let mut y = self.forest[index_y]; x = self.forest[x.parent]; y = self.forest[y.parent]; @@ -108,6 +91,7 @@ impl TargetPartition { } let mut indices = HashMap::new(); + // // Here we keep just the Wire targets, filtering out everything else. let partition = partition .into_values() .map(|v| { @@ -126,31 +110,6 @@ impl TargetPartition { }); WirePartitions { partition, indices } - - // // Here we keep just the Wire targets, filtering out everything else. - // let mut partitions = Vec::new(); - // let mut indices = HashMap::new(); - // - // for old_partition in &self.partitions { - // let mut new_partition = Vec::new(); - // for target in old_partition { - // if let Target::Wire(w) = *target { - // new_partition.push(w); - // } - // } - // partitions.push(new_partition); - // } - // - // for (&target, &index) in &self.indices { - // if let Target::Wire(gi) = target { - // indices.insert(gi, index); - // } - // } - // - // WirePartitions { - // partitions, - // indices, - // } } } @@ -214,15 +173,3 @@ impl WirePartitions { sigma } } - -#[test] -fn test_part() { - let mut part = TargetPartition::default(); - part.add(1); - part.add(2); - part.add(3); - - part.merge(1, 3); - - dbg!(part); -}