E - Element typepublic class EquivalenceSet<E extends Comparable<E>> extends Object
Elements are equivalent by the rules of a mathematical equivalence relation:
e is equivalent to itself
e is equivalent to f,
then f is equivalent to e
e is equivalent to f,
and f is equivalent to g,
then e is equivalent to g
For any given pair of elements, answers in O(log N) (two hash-table lookups) whether they are equivalent to each other.
| Constructor and Description |
|---|
EquivalenceSet() |
| Modifier and Type | Method and Description |
|---|---|
E |
add(E e)
Adds an element, and returns the element (which is its own parent).
|
boolean |
areEquivalent(E e,
E f)
Returns whether two elements are in the same equivalence class.
|
int |
classCount()
Returns the number of equivalence classes in this equivalence set.
|
void |
clear()
Removes all elements in this equivalence set.
|
E |
equiv(E e,
E f)
Marks two elements as equivalent.
|
NavigableMap<E,SortedSet<E>> |
map()
Returns a map of the canonical element in each equivalence class to the
set of elements in that class.
|
int |
size()
Returns the number of elements in this equivalence set.
|
public E add(E e)
public E equiv(E e, E f)
public boolean areEquivalent(E e, E f)
public NavigableMap<E,SortedSet<E>> map()
public void clear()
public int size()
public int classCount()
Copyright © 2012-2022 Apache Software Foundation. All Rights Reserved.