pub struct WeightedUnionFind<G: Abel> { /* private fields */ }
Expand description
重み付きUnionFind
Implementations§
source§impl<G: Abel> WeightedUnionFind<G>where
G::Val: Eq,
impl<G: Abel> WeightedUnionFind<G>where G::Val: Eq,
sourcepub fn unite(
&mut self,
x: usize,
y: usize,
weight: G::Val
) -> Result<bool, &str>
pub fn unite( &mut self, x: usize, y: usize, weight: G::Val ) -> Result<bool, &str>
集合x,y
をself.diff(x, y) = weight
となるように併合する.
戻り値
- すでに
x,y
が併合済みだった場合self.diff(x, y) == weight
の場合 →Some(false)
self.diff(x, y) != weight
の場合 →Err(())
x,y
が併合済みでない場合 →Ok(true)
sourcepub fn group_count(&self) -> usize
pub fn group_count(&self) -> usize
全体の要素数を求める