mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-10 09:43:09 +00:00
Minor
This commit is contained in:
parent
fc0f8a78ce
commit
d93cf693ba
@ -17,17 +17,6 @@ pub struct ForestNode<T: Debug + Copy + Eq + PartialEq> {
|
||||
index: usize,
|
||||
}
|
||||
|
||||
impl<T: Debug + Copy + Eq + PartialEq> ForestNode<T> {
|
||||
pub fn new(t: T, parent: usize, size: usize, index: usize) -> Self {
|
||||
Self {
|
||||
t,
|
||||
parent,
|
||||
size,
|
||||
index,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TargetPartition<T: Debug + Copy + Eq + PartialEq + Hash> {
|
||||
forest: Vec<ForestNode<T>>,
|
||||
@ -44,21 +33,15 @@ impl<T: Debug + Copy + Eq + PartialEq + Hash> Default for TargetPartition<T> {
|
||||
}
|
||||
|
||||
impl<T: Debug + Copy + Eq + PartialEq + Hash> TargetPartition<T> {
|
||||
pub fn get(&self, t: T) -> ForestNode<T> {
|
||||
self.forest[self.indices[&t]]
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, t: T) -> &mut ForestNode<T> {
|
||||
&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<T: Debug + Copy + Eq + PartialEq + Hash> TargetPartition<T> {
|
||||
/// 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<Target> {
|
||||
}
|
||||
|
||||
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<Target> {
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user