UnionFind<T> class
Union-Find / Disjoint Set data structure implementation
Provides efficient union and find operations for managing disjoint sets. Uses path compression and union by rank for optimal performance.
- Implementers
Constructors
- UnionFind()
- Creates a new Union-Find data structure
-
UnionFind.fromElements(Iterable<
T> elements) - Creates a Union-Find from an existing collection of elements
Properties
- averageSetSize → double
-
Gets the average set size
no setter
- elementCount → int
-
Gets the total number of elements
no setter
-
elements
→ Set<
T> -
Gets all elements in the Union-Find
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- largestSetSize → int
-
Gets the largest set size
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- setCount → int
-
Gets the number of disjoint sets
no setter
Methods
-
clear(
) → void - Removes all elements and sets
-
contains(
T element) → bool - Checks if the given element exists in any set
-
find(
T element) → T? - Finds the representative (root) of the set containing the given element
-
getAllSets(
) → List< Set< T> > - Gets all sets as a list of sets
-
getSetElements(
T element) → Set< T> - Gets all elements in the same set as the given element
-
getSetSize(
T element) → int - Gets the size of the set containing the given element
-
isConnected(
T element1, T element2) → bool - Checks if two elements are in the same set
-
makeSet(
T element) → void - Creates a new set containing the given element
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reset(
Iterable< T> elements) → void - Resets the Union-Find to contain only the given elements
-
toString(
) → String -
A string representation of this object.
override
-
union(
T element1, T element2) → void - Unions the sets containing the two given elements
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited