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 TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends E> c) void
Add a set to the union.void
clear()
boolean
boolean
containsAll
(Collection<?> c) boolean
int
hashCode()
boolean
isEmpty()
iterator()
boolean
boolean
removeAll
(Collection<?> c) void
Remove a set to the union.boolean
retainAll
(Collection<?> c) setView()
Create a view of this object as an unmodifiable set, with DisjointSetUnion-specific methods hidden.int
size()
Object[]
toArray()
<T> T[]
toArray
(T[] a) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods 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:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceSet<E>
-
hashCode
public int hashCode() -
isEmpty
public boolean isEmpty() -
iterator
-
remove
-
removeAll
-
retainAll
-
size
public int size() -
toArray
-
toArray
- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceSet<E>
- Throws:
ArrayStoreException
NullPointerException
-