Find the root of the set containing `x` with path compression.
(&mut self, mut x: usize)
| 69 | |
| 70 | /// Find the root of the set containing `x` with path compression. |
| 71 | fn find(&mut self, mut x: usize) -> usize { |
| 72 | while self.parent[x] != x { |
| 73 | // Path halving: point to grandparent. |
| 74 | self.parent[x] = self.parent[self.parent[x]]; |
| 75 | x = self.parent[x]; |
| 76 | } |
| 77 | x |
| 78 | } |
| 79 | |
| 80 | /// Union the sets containing `a` and `b` by rank. |
| 81 | fn union(&mut self, a: usize, b: usize) { |
no outgoing calls