Struct cranelift_egraph::UnionFind
source · pub struct UnionFind { /* private fields */ }
Expand description
A union-find data structure. The data structure can allocate
Id
s, indicating eclasses, and can merge eclasses together.
Implementations§
source§impl UnionFind
impl UnionFind
sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Create a new UnionFind
with the given capacity.
sourcepub fn add(&mut self, id: Id)
pub fn add(&mut self, id: Id)
Add an Id
to the UnionFind
, with its own equivalence class
initially. All Id
s must be added before being queried or
unioned.
sourcepub fn find_and_update(&mut self, node: Id) -> Id
pub fn find_and_update(&mut self, node: Id) -> Id
Find the canonical Id
of a given Id
, updating the data
structure in the process so that future queries for this Id
(and others in its chain up to the root of the equivalence
class) will be faster.
sourcepub fn equiv_id_mut(&mut self, a: Id, b: Id) -> bool
pub fn equiv_id_mut(&mut self, a: Id, b: Id) -> bool
Determine if two Id
s are equivalent, after
canonicalizing. Update union-find data structure during our
canonicalization to make future lookups faster.
sourcepub fn hash_id_mut<H: Hasher>(&mut self, hash: &mut H, id: Id)
pub fn hash_id_mut<H: Hasher>(&mut self, hash: &mut H, id: Id)
Hash an Id
after canonicalizing it. Update union-find data
structure to make future lookups/hashing faster.