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
e
is equivalent to itself - Symmetric
- If
e
is equivalent tof
, thenf
is equivalent toe
- Transitive
- If
e
is equivalent tof
, andf
is equivalent tog
, thene
is 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
-
Method Summary
Modifier and TypeMethodDescriptionAdds 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
Returns the number of equivalence classes in this equivalence set.void
clear()
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.int
size()
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.
-