pub struct DisjointHashSet<K> { /* private fields */ }Implementations§
Source§impl<K: Eq + Hash> DisjointHashSet<K>
impl<K: Eq + Hash> DisjointHashSet<K>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty DisjointHashSet.
§Example
use disjoint_hash_set ::DisjointHashSet;
let mut djhs: DisjointHashSet<&str> = DisjointHashSet::new();Sourcepub fn contains<T: Borrow<K>>(&self, val: T) -> bool
pub fn contains<T: Borrow<K>>(&self, val: T) -> bool
Check if the value has already been inserted.
§Example
use disjoint_hash_set::DisjointHashSet;
let mut djhs = DisjointHashSet::new();
assert!(!djhs.contains(&"a"));
djhs.insert(&"a");
assert!(djhs.contains(&"a"));Sourcepub fn insert(&mut self, val: K) -> bool
pub fn insert(&mut self, val: K) -> bool
Insert the value as a new disjoint set with a single member. Returns true if the value was not already present.
use disjoint_hash_set::DisjointHashSet;
let mut djhs = DisjointHashSet::new();
assert!(djhs.insert(&"a"));
assert!(!djhs.insert(&"a"));Sourcepub fn is_linked<T: Borrow<K>>(&mut self, val1: T, val2: T) -> bool
pub fn is_linked<T: Borrow<K>>(&mut self, val1: T, val2: T) -> bool
Checks if the two keys are members of the same set. This will not implicitly add values that were not already present.
use disjoint_hash_set::DisjointHashSet;
let mut djhs = DisjointHashSet::new();
djhs.link("a", "b");
djhs.link("a", "c");
assert!(djhs.is_linked("b", "c"));
assert!(!djhs.is_linked("a", "d"));Sourcepub fn link(&mut self, val1: K, val2: K)
pub fn link(&mut self, val1: K, val2: K)
Link the respective sets of the two provided values. This will insert non-existent values in the process.
use disjoint_hash_set::DisjointHashSet;
let mut djhs = DisjointHashSet::new();
djhs.link("a", "b");
assert!(djhs.contains("a"));
assert!(djhs.contains("b"));
assert!(djhs.is_linked("a", "b"));Sourcepub fn sets(self) -> impl Iterator<Item = HashSet<K>>
pub fn sets(self) -> impl Iterator<Item = HashSet<K>>
Consumes the DisjointHashSet and returns an iterator of HashSets for each disjoint set.
use disjoint_hash_set::DisjointHashSet;
use std::{collections::HashSet, iter::FromIterator};
let edges = vec![("a", "a"), ("b", "c"), ("d", "e"), ("e", "f")];
let mut sets = DisjointHashSet::from_iter(edges).sets().collect::<Vec<_>>();
sets.sort_by(|set_a, set_b| set_a.len().cmp(&set_b.len()));
let expected_sets: Vec<HashSet<&str>> = vec![
HashSet::from_iter(vec!["a"]),
HashSet::from_iter(vec!["b", "c"]),
HashSet::from_iter(vec!["d", "e", "f"]),
];
assert_eq!(sets, expected_sets);Trait Implementations§
Source§impl<K: Clone> Clone for DisjointHashSet<K>
impl<K: Clone> Clone for DisjointHashSet<K>
Source§fn clone(&self) -> DisjointHashSet<K>
fn clone(&self) -> DisjointHashSet<K>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<K: Debug> Debug for DisjointHashSet<K>
impl<K: Debug> Debug for DisjointHashSet<K>
Source§impl<V: Eq + Hash> FromIterator<(V, V)> for DisjointHashSet<V>
impl<V: Eq + Hash> FromIterator<(V, V)> for DisjointHashSet<V>
Auto Trait Implementations§
impl<K> Freeze for DisjointHashSet<K>
impl<K> RefUnwindSafe for DisjointHashSet<K>where
K: RefUnwindSafe,
impl<K> Send for DisjointHashSet<K>where
K: Send,
impl<K> Sync for DisjointHashSet<K>where
K: Sync,
impl<K> Unpin for DisjointHashSet<K>where
K: Unpin,
impl<K> UnwindSafe for DisjointHashSet<K>where
K: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more