MCPcopy Create free account
hub / github.com/douchuan/algorithm / UF

Class UF

src/common/uf.rs:79–85  ·  view source on GitHub ↗

This implementation uses weighted quick union by rank with path compression by halving.

Source from the content-addressed store, hash-verified

77/// This implementation uses weighted quick union by rank
78/// with path compression by halving.
79pub struct UF {
80 parent: Vec<usize>, // parent[i] = parent of i
81 // rank[i] = rank of subtree rooted at i (never more than 31)
82 // rank == 31的话,将有 2 ^ 31 个节点, 一棵满二叉树的节点数量
83 rank: Vec<usize>,
84 count: usize, // number of components
85}
86
87impl QuickFindUF {
88 pub fn new(n: usize) -> Self {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected