java.lang.Object
org.bzdev.util.DisjointSetsUnion<E>
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Set<E>
Set implementation backed by a collection of disjoint sets.
The set is immutable in that elements cannot be added explicitly -
only the sets it backs can be modified . These sets must be
disjoint for the iterator to not contain duplicate entries and for
size() and hashCode() to return the correct values.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.DisjointSetsUnion(Set<E> set1, Set<E> set2) Constructor for two sets. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends E> c) voidAdd a set to the union.voidclear()booleanbooleancontainsAll(Collection<?> c) booleaninthashCode()booleanisEmpty()iterator()booleanbooleanremoveAll(Collection<?> c) voidRemove a set to the union.booleanretainAll(Collection<?> c) setView()Create a view of this object as an unmodifiable set, with DisjointSetUnion-specific methods hidden.intsize()Object[]toArray()<T> T[]toArray(T[] a) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
spliterator
-
Constructor Details
-
DisjointSetsUnion
public DisjointSetsUnion()Constructor. -
DisjointSetsUnion
Constructor for two sets. This is provided to avoid having to add sets for a common case.- Parameters:
set1- the first setset2- the second set
-
-
Method Details
-
addSet
Add a set to the union. This set must be disjoint from any other set in the union, and the union is partially backed by this set.- Parameters:
set- the set to add
-
removeSet
Remove a set to the union. A set that can be successfully removed must be one that was added to the union, either by calling addSet or by a constructor.- Parameters:
set- the set to remove
-
setView
Create a view of this object as an unmodifiable set, with DisjointSetUnion-specific methods hidden. Logically equivalent to using Collections.unmodifiableSet but with some performance advantages when using the iterator.- Returns:
- an unmodifiable set backed by a DisjointSetsUnion
-
add
-
addAll
-
clear
public void clear() -
equals
-
contains
-
containsAll
- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceSet<E>
-
hashCode
public int hashCode() -
isEmpty
public boolean isEmpty() -
iterator
-
remove
-
removeAll
-
retainAll
-
size
public int size() -
toArray
-
toArray
- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Throws:
ArrayStoreExceptionNullPointerException
-