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 Summary
Constructors Constructor Description SplittableElementSet(Collection<E> c, gnu.trove.map.hash.TIntIntHashMap idx)
Make a new splittable set. -
Method Summary
Modifier and Type Method Description int
compare(E o1, E o2)
boolean
forEachPartition(IterateProcedure<E> p)
Execute a procedure on each partition.List<ElementSubSet<E>>
getPartitions()
Get all the partitions as subsets.gnu.trove.map.hash.TIntIntHashMap
getRespectiveIndex()
Get the index associated to each element.Set<E>
getSubSet(int k)
Get a subset for the given partition.List<E>
getValues()
Get the backend array of elements.static SplittableElementSet<Node>
newNodeIndex(Collection<Node> c, gnu.trove.map.hash.TIntIntHashMap idx)
Make a new splittable set from a collection of nodes.static SplittableElementSet<VM>
newVMIndex(Collection<VM> c, gnu.trove.map.hash.TIntIntHashMap idx)
Make a new splittable set from a collection of VM.int
size()
Get the size of the set.String
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
SplittableElementSet
Make a new splittable set.- Parameters:
c
- the elements, no duplicates are supposedidx
- the partition associated to each element. FormatElement.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 wrapidx
- 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 wrapidx
- the partition for each node- Returns:
- the resulting set
-
toString
-
forEachPartition
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
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
- Specified by:
compare
in interfaceComparator<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
Get the backend array of elements.- Returns:
- a non-empty array
-
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
-