Struct UnionFind

Source
pub struct UnionFind<'a, T = ()> { /* private fields */ }
Expand description

素集合の統合と所属の判定ができるデータ構造。

Implementations§

Source§

impl UnionFind<'_, ()>

Source

pub fn new(n: usize) -> Self

大きさ1の集合をn個用意する。

Source§

impl<'a, T> UnionFind<'a, T>

Source

pub fn with_values(values: Vec<T>, merge: Box<impl 'a + Fn(T, T) -> T>) -> Self

大きさ1の集合を|values|個用意する。このとき、各集合ivalue[i]を割り当てる。

mergeは、集合を統合する際に、新しい集合に割り当てる値を返す。

Source

pub fn root_of(&self, i: usize) -> usize

iの属する集合の根を返す。

Source

pub fn is_same(&self, i: usize, j: usize) -> bool

ijが同じ集合に属するならばtrueを返す。

Source

pub fn merge(&mut self, i: usize, j: usize) -> usize

iの属する集合とjの属する集合を統合する。

Source

pub fn size_of(&self, i: usize) -> usize

iの属する集合の大きさを返す。

Source

pub fn count_groups(&self) -> usize

素集合の個数を返す。

Source

pub fn value_of(&self, i: usize) -> Option<&T>

iの属する集合のもつ値を返す。

Source

pub fn get_groups(&self) -> Vec<Vec<usize>>

素集合をすべて列挙する。

Auto Trait Implementations§

§

impl<'a, T> Freeze for UnionFind<'a, T>

§

impl<'a, T = ()> !RefUnwindSafe for UnionFind<'a, T>

§

impl<'a, T = ()> !Send for UnionFind<'a, T>

§

impl<'a, T = ()> !Sync for UnionFind<'a, T>

§

impl<'a, T> Unpin for UnionFind<'a, T>
where T: Unpin,

§

impl<'a, T = ()> !UnwindSafe for UnionFind<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.