mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 00:03:10 +00:00
Path halving -> Path compression
This commit is contained in:
parent
b7561c31a2
commit
083d841397
@ -45,14 +45,15 @@ impl<T: Debug + Copy + Eq + PartialEq + Hash, F: Fn(T) -> usize> TargetPartition
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Path halving method, see https://en.wikipedia.org/wiki/Disjoint-set_data_structure#Finding_set_representatives.
|
/// Path compression method, see https://en.wikipedia.org/wiki/Disjoint-set_data_structure#Finding_set_representatives.
|
||||||
pub fn find(&mut self, mut x: ForestNode<T>) -> ForestNode<T> {
|
pub fn find(&mut self, mut x: ForestNode<T>) -> ForestNode<T> {
|
||||||
while x.parent != x.index {
|
if x.parent != x.index {
|
||||||
let grandparent = self.forest[x.parent].parent;
|
let root = self.find(self.forest[x.parent]);
|
||||||
self.forest[x.index].parent = grandparent;
|
self.forest[x.index].parent = root.index;
|
||||||
x = self.forest[grandparent];
|
root
|
||||||
|
} else {
|
||||||
|
x
|
||||||
}
|
}
|
||||||
x
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Merge two sets.
|
/// Merge two sets.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user