Package com.pnfsoftware.jeb.util.collect
Class DisjointSets<T>
java.lang.Object
com.pnfsoftware.jeb.util.collect.DisjointSets<T>
- Type Parameters:
T
-
This type represents disjoint sets.
The following operations define what a disjoint set is:
- The
add1
operation creates a new set with that value, unless an existing set containing that value already exists. - The
add2
operation adds two "connected elements": they must reside in the same set. If those two elements currently reside in two separate sets, those sets are merged.
This class does not override hashCode/equals
. Internally, HashSet
objects are
used. Therefore, there is no guarantee provided on elements ordering.
Objects of this class are serializable at the condition that T is serializable.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Create a set and add the provided value, unless a set with the value already exists.boolean
Add two linked values to the same set, potentially merging two existing sets into one.void
clear()
Clear all sets.int
Retrieve the count of elements existing in all the sets managed by this object.Collection<Set<T>>
getSets()
Retrieve a read-only view of the current disjoint sets managed by this object.Retrieve the values stored in all the sets managed by this object.boolean
isEmpty()
Determine whether this object contains at least one set.int
size()
Retrieve the count of sets.toString()
-
Constructor Details
-
DisjointSets
public DisjointSets()Create a new "disjoint sets" object
-
-
Method Details
-
clear
public void clear()Clear all sets. -
isEmpty
public boolean isEmpty()Determine whether this object contains at least one set.- Returns:
-
size
public int size()Retrieve the count of sets.- Returns:
-
getCountOfValues
public int getCountOfValues()Retrieve the count of elements existing in all the sets managed by this object.- Returns:
-
getValues
Retrieve the values stored in all the sets managed by this object.- Returns:
-
getSets
Retrieve a read-only view of the current disjoint sets managed by this object.- Returns:
-
add
Create a set and add the provided value, unless a set with the value already exists.- Parameters:
v
- a value- Returns:
- true if a new set was created to accommodate the provided value; false if the provided value was already present in an existing set
-
add
Add two linked values to the same set, potentially merging two existing sets into one.- Parameters:
a
- first valueb
- second value- Returns:
- true if the sets were modified; false if nothing changed
-
toString
-