pub struct DisjointSetStruct<NI: Idx>(/* private fields */);
Expand description

A thread-safe Disjoint Set Struct implementation, that can be safely shared and accessed across threads.

The implementation is based on the Java implementation [1] which in turn is based on a C++ implementation and some input from a Rust implementation [3].

This implementation is tailored for the graph crate as it needs to support the Idx trait.

[1] Java [2] C++ [3] Rust

Implementations§

source§

impl<NI: Idx> DisjointSetStruct<NI>

source

pub fn new(size: usize) -> Self

Creates a new disjoint-set struct of size elements.

Examples
use graph::prelude::*;

let dss = DisjointSetStruct::new(3);
dss.union(0, 1);
let set0 = dss.find(0);
let set1 = dss.find(1);
assert_eq!(set0, set1);

Trait Implementations§

source§

impl<NI: Idx> Components<NI> for DisjointSetStruct<NI>

source§

fn component(&self, node: NI) -> NI

source§

fn to_vec(self) -> Vec<NI>

source§

impl<NI: Idx> UnionFind<NI> for DisjointSetStruct<NI>

source§

fn union(&self, id1: NI, id2: NI)

Joins the set of id1 with the set of id2.

Examples
use graph::prelude::*;

let dss = DisjointSetStruct::new(10);
dss.union(2, 4);
assert_eq!(dss.find(2), 2);
assert_eq!(dss.find(4), 2);
source§

fn find(&self, id: NI) -> NI

Find the set of id.

Examples
use graph::prelude::*;

let dss = DisjointSetStruct::new(10);
assert_eq!(dss.find(4), 4);
dss.union(4, 2);
assert_eq!(dss.find(4), 2);
source§

fn len(&self) -> usize

Returns the number of elements in the dss, also referred to as its ‘length’.

Examples
use graph::prelude::*;

let dss = DisjointSetStruct::<usize>::new(3);
assert_eq!(dss.len(), 3);
source§

fn compress(&self)

Compresses the DSS so that each id stores its root set id.

source§

impl<NI: Idx> Send for DisjointSetStruct<NI>

source§

impl<NI: Idx> Sync for DisjointSetStruct<NI>

Auto Trait Implementations§

§

impl<NI> !RefUnwindSafe for DisjointSetStruct<NI>

§

impl<NI> Unpin for DisjointSetStruct<NI>

§

impl<NI> UnwindSafe for DisjointSetStruct<NI>where NI: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.