Class UnionFind<V>
java.lang.Object
tools.refinery.interpreter.matchers.algorithms.UnionFind<V>
- Type Parameters:
V
- the type parameter of the element's stored in the union-find data structure
Union-find data structure implementation. Note that the implementation relies on the correct implementation of the
equals method of the type parameter's class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Delete the set whose root is the given node.Find method with path compression.getPartition
(V element) Returns the partition in which the given element can be found, or null otherwise.Collection
<Set<V>> Returns all partitions.boolean
isSameUnion
(Set<V> elements) Returns if all given elements are in the same partition.makeSet
(Collection<V> nodes) Creates a new union set from a collection of elements.This method creates a single set containing the given node.Union by rank implementation of the two sets which contain x and y; x and/or y can be a single element from the universe.void
Places the given elements in to the same partition.
-
Constructor Details
-
UnionFind
public UnionFind()Instantiate a new union-find data structure. -
UnionFind
Instantiate a new union-find data structure with the given elements as separate sets.
-
-
Method Details
-
makeSet
Creates a new union set from a collection of elements.- Parameters:
nodes
- the collection of elements- Returns:
- the root element
-
makeSet
This method creates a single set containing the given node.- Parameters:
node
- the root node of the set- Returns:
- the root element
-
find
Find method with path compression.- Parameters:
node
- the node to find- Returns:
- the root node of the set in which the given node can be found
-
union
Union by rank implementation of the two sets which contain x and y; x and/or y can be a single element from the universe.- Parameters:
x
- set or single element of the universey
- set or single element of the universe- Returns:
- the new root of the two sets
-
unite
Places the given elements in to the same partition. -
deleteSet
Delete the set whose root is the given node.- Parameters:
root
- the root node
-
isSameUnion
Returns if all given elements are in the same partition. -
getPartition
Returns the partition in which the given element can be found, or null otherwise. -
getPartitions
Returns all partitions. -
getPartitionHeads
-