Struct librualg::dsu::DSURef[][src]

pub struct DSURef<'a, T> where
    T: Eq + Ord
{ /* fields omitted */ }
Expand description

DSU

use librualg::dsu::{DSURef, DSU, DSUNum};

let mut dsu = DSURef::new();
let v = (0..10).collect::<Vec<u32>>();
for i in &v {
    dsu.make_set(i);
}
dsu.union_sets(&v[1], &v[2]);
dsu.union_sets(&v[2], &v[3]);
dsu.union_sets(&v[2], &v[7]);

assert_eq!(dsu.find_set(&v[2]), dsu.find_set(&v[7]));
assert_ne!(dsu.find_set(&v[2]), dsu.find_set(&v[8]));
assert_eq!(dsu.find_set(&v[1]), dsu.find_set(&v[3]));

let mut dsu = DSU::new();
for i in 0..10 {
    dsu.make_set(i);
}
dsu.union_sets(1, 2);
dsu.union_sets(2, 3);
dsu.union_sets(2, 7);

assert_eq!(dsu.find_set(2), dsu.find_set(7));
assert_ne!(dsu.find_set(2), dsu.find_set(8));
assert_eq!(dsu.find_set(1), dsu.find_set(3));

let mut dsu = DSUNum::new(10);
for i in 1..=10 {
    dsu.make_set(i);
}
dsu.union_sets(1, 2);
dsu.union_sets(2, 3);
dsu.union_sets(2, 7);

assert_eq!(dsu.find_set(2), dsu.find_set(7));
assert_ne!(dsu.find_set(2), dsu.find_set(8));
assert_eq!(dsu.find_set(1), dsu.find_set(3));
assert_ne!(dsu.find_set(1), dsu.find_set(9));

Implementations

impl<'a, T> DSURef<'a, T> where
    T: Eq + Ord
[src]

pub fn new() -> Self[src]

pub fn make_set(&mut self, value: &'a T)[src]

pub fn find_set(&mut self, value: &'a T) -> Option<&'a T>[src]

pub fn union_sets(&mut self, first: &'a T, second: &'a T)[src]

Auto Trait Implementations

impl<'a, T> RefUnwindSafe for DSURef<'a, T> where
    T: RefUnwindSafe

impl<'a, T> Send for DSURef<'a, T> where
    T: Sync

impl<'a, T> Sync for DSURef<'a, T> where
    T: Sync

impl<'a, T> Unpin for DSURef<'a, T>

impl<'a, T> UnwindSafe for DSURef<'a, T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.