Class SplittableElementSet<E extends Element>

java.lang.Object
org.btrplace.scheduler.runner.disjoint.model.SplittableElementSet<E>
All Implemented Interfaces:
Comparator<E>

public class SplittableElementSet<E extends Element>
extends Object
implements Comparator<E>
A collection of supposed unique Element that can be split into multiple sub-sets.

The partitioning is provided by an index that indicate, at instantiation, the right partition for each element.

The backend is a simple array of elements. Elements belonging to the same partition are contiguous for efficiency.

Author:
Fabien Hermenier
  • Constructor Details

    • SplittableElementSet

      public SplittableElementSet​(Collection<E> c, gnu.trove.map.hash.TIntIntHashMap idx)
      Make a new splittable set.
      Parameters:
      c - the elements, no duplicates are supposed
      idx - the partition associated to each element. Format Element.id() to key
  • Method Details

    • newVMIndex

      public static SplittableElementSet<VM> newVMIndex​(Collection<VM> c, gnu.trove.map.hash.TIntIntHashMap idx)
      Make a new splittable set from a collection of VM. We consider the collection does not have duplicated elements.
      Parameters:
      c - the collection to wrap
      idx - the partition for each VM
      Returns:
      the resulting set
    • newNodeIndex

      public static SplittableElementSet<Node> newNodeIndex​(Collection<Node> c, gnu.trove.map.hash.TIntIntHashMap idx)
      Make a new splittable set from a collection of nodes. We consider the collection does not have duplicated elements.
      Parameters:
      c - the collection to wrap
      idx - the partition for each node
      Returns:
      the resulting set
    • toString

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

      public boolean forEachPartition​(IterateProcedure<E> p)
      Execute a procedure on each partition. The partition is indicated by its bounds on the backend array.
      Parameters:
      p - the procedure to execute
      Returns:
      true if we visited every element
    • getSubSet

      public Set<E> getSubSet​(int k)
      Get a subset for the given partition.
      Parameters:
      k - the partition key
      Returns:
      the resulting subset. Empty if no elements belong to the given partition.
    • compare

      public int compare​(E o1, E o2)
      Specified by:
      compare in interface Comparator<E extends Element>
    • getRespectiveIndex

      public gnu.trove.map.hash.TIntIntHashMap getRespectiveIndex()
      Get the index associated to each element.
      Returns:
      a map of Element.id() to index value
    • getValues

      public List<E> getValues()
      Get the backend array of elements.
      Returns:
      a non-empty array
    • getPartitions

      public List<ElementSubSet<E>> getPartitions()
      Get all the partitions as subsets.
      Returns:
      a collection of ElementSubSet.
    • size

      public int size()
      Get the size of the set.
      Returns:
      a positive integer