Package org.apache.calcite.util
Class EquivalenceSet<E extends Comparable<E>>
java.lang.Object
org.apache.calcite.util.EquivalenceSet<E>
- Type Parameters:
E- Element type
Set of elements organized into equivalence classes.
Elements are equivalent by the rules of a mathematical equivalence relation:
- Reflexive
- Every element
eis equivalent to itself - Symmetric
- If
eis equivalent tof, thenfis equivalent toe - Transitive
- If
eis equivalent tof, andfis equivalent tog, theneis equivalent tog
For any given pair of elements, answers in O(log N) (two hash-table lookups) whether they are equivalent to each other.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds an element, and returns the element (which is its own parent).booleanareEquivalent(E e, E f) Returns whether two elements are in the same equivalence class.intReturns the number of equivalence classes in this equivalence set.voidclear()Removes all elements in this equivalence set.Marks two elements as equivalent.map()Returns a map of the canonical element in each equivalence class to the set of elements in that class.intsize()Returns the number of elements in this equivalence set.
-
Constructor Details
-
EquivalenceSet
public EquivalenceSet()
-
-
Method Details
-
add
Adds an element, and returns the element (which is its own parent). If already present, returns the element's parent. -
equiv
Marks two elements as equivalent. They may or may not be registered, and they may or may not be equal. -
areEquivalent
Returns whether two elements are in the same equivalence class. Returns false if either or both of the elements are not registered. -
map
Returns a map of the canonical element in each equivalence class to the set of elements in that class. The keys are sorted in natural order, as are the elements within each key. -
clear
public void clear()Removes all elements in this equivalence set. -
size
public int size()Returns the number of elements in this equivalence set. -
classCount
public int classCount()Returns the number of equivalence classes in this equivalence set.
-