Class Partition<E>

java.lang.Object
fr.inria.rules.integraal.model.partition.Partition<E>
Type Parameters:
E - the type of elements of the partition
Direct Known Subclasses:
TermPartition

public class Partition<E> extends Object
Partition of a set of elements maintained with a union-find structure.
Author:
Guillaume Pérution-Kihli
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new empty Partition
    Creates a new Partition copying the given one
    Partition(Partition<E> toCopy, Comparator<E> comparator)
    Creates a new Partition copying the given one but overriding its comparator
    Partition(Collection<Set<E>> partition)
    Creates a new Partition with the given classes
    Partition(Collection<Set<E>> partition, Comparator<E> comparator)
    Creates a new Partition with the given classes and comparator
    Partition(Comparator<E> comparator)
    Creates a new empty Partition with the given comparator
    Partition(Set<E> initialElements)
    Creates a new Partition with the given elements, each in its own class
    Partition(Set<E> initialElements, Comparator<E> comparator)
    Creates a new Partition with the given elements and comparator
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add a class to the partition If there are some common elements with existing classes, the class will be merged with these existing classes
    boolean
     
    protected void
    Erase the memoized values
    Returns an immutable Set containing all the class' elements of x
    Return all the classes of the partition
    Return all the elements contained in the partition
    Returns a class' representative of x If x is not in the partition, the method returns an empty optional The returned representative is always the same if the partition is not modified
    int
     
    boolean
    Indicates whether this partition contains no elements.
    void
    join(Partition<E> other)
    Join the class of another partition This operation consists of merge the classes of this partition and the other one when they share a common element
     
    void
    union(E x, E y)
    Merge the classes of x and y If x or y are not yet in the partition, they are be added to it

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Partition

      public Partition()
      Creates a new empty Partition
    • Partition

      public Partition(Comparator<E> comparator)
      Creates a new empty Partition with the given comparator
      Parameters:
      comparator - the comparator to choose the representative of a class
    • Partition

      public Partition(Set<E> initialElements)
      Creates a new Partition with the given elements, each in its own class
      Parameters:
      initialElements - the initial elements of this partition
    • Partition

      public Partition(Set<E> initialElements, Comparator<E> comparator)
      Creates a new Partition with the given elements and comparator
      Parameters:
      initialElements - the initial elements of this partition
      comparator - the comparator to choose the representative of a class
    • Partition

      public Partition(Collection<Set<E>> partition)
      Creates a new Partition with the given classes
      Parameters:
      partition - the initial elements represented as multiple partitions
    • Partition

      public Partition(Collection<Set<E>> partition, Comparator<E> comparator)
      Creates a new Partition with the given classes and comparator
      Parameters:
      partition - the initial elements represented as multiple partitions
      comparator - the comparator to choose the representative of a class
    • Partition

      public Partition(Partition<E> toCopy)
      Creates a new Partition copying the given one
      Parameters:
      toCopy - partition to copy
    • Partition

      public Partition(Partition<E> toCopy, Comparator<E> comparator)
      Creates a new Partition copying the given one but overriding its comparator
      Parameters:
      toCopy - partition to copy
      comparator - the comparator to choose the representative of a class
  • Method Details

    • addClass

      public void addClass(Set<E> c)
      Add a class to the partition If there are some common elements with existing classes, the class will be merged with these existing classes
      Parameters:
      c - : the class to add
    • getRepresentative

      public Optional<E> getRepresentative(E x)
      Returns a class' representative of x If x is not in the partition, the method returns an empty optional The returned representative is always the same if the partition is not modified
      Parameters:
      x - : the element from which we want the class' representative
      Returns:
      a class' representative of x or an empty optional if x is not in the partition
    • getClass

      public Optional<Set<E>> getClass(E x)
      Returns an immutable Set containing all the class' elements of x
      Parameters:
      x - : the element from which we want the class
      Returns:
      a set that is the class' elements of x or an empty optional if x is not in the partition
    • union

      public void union(E x, E y)
      Merge the classes of x and y If x or y are not yet in the partition, they are be added to it
      Parameters:
      x - : the first element of the couple
      y - : the second element of the couple
    • join

      public void join(Partition<E> other)
      Join the class of another partition This operation consists of merge the classes of this partition and the other one when they share a common element
      Parameters:
      other - : the partition we want to join
    • getClasses

      public List<Set<E>> getClasses()
      Return all the classes of the partition
      Returns:
      a list of immutable sets that is the list of all classes
    • getElements

      public Set<E> getElements()
      Return all the elements contained in the partition
      Returns:
      an immutable set containing all the elements of the partition
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • eraseMemoizedValues

      protected void eraseMemoizedValues()
      Erase the memoized values
    • isEmpty

      public boolean isEmpty()
      Indicates whether this partition contains no elements.
      Returns:
      true if the partition is empty