Class AllocationTable<T>
- java.lang.Object
-
- ru.ispras.microtesk.test.engine.allocator.AllocationTable<T>
-
- Type Parameters:
T
- type of objects.
public final class AllocationTable<T> extends java.lang.Object
AllocationTable
implements a resource allocation table, which is a finite set of objects (registers, pages, etc.) in couple with allocation / deallocation methods.
-
-
Constructor Summary
Constructors Constructor Description AllocationTable(AllocationData<T> allocationData, java.util.Collection<T> objects)
Constructs a resource allocation table.AllocationTable(AllocationData<T> allocationData, Supplier<T> supplier)
Constructs a resource allocation table.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
allocate(ResourceOperation operation, java.util.Collection<T> retain, java.util.Collection<T> exclude, java.util.Map<ResourceOperation,java.lang.Integer> rate)
Allocates an object and marks it as being in use.boolean
exists(T object)
Checks whether the object exists in the allocation table.void
free(T object)
Frees (deallocates) the object.AllocationData<T>
getAllocationData()
Returns the default allocation data.Supplier<T>
getSupplier()
Returns the object generator.T
peek(java.util.Collection<T> retain, java.util.Collection<T> exclude, java.util.Map<ResourceOperation,java.lang.Integer> rate)
Peeks an object.void
reset()
Resets the resource allocation table.void
setAllocationData(AllocationData<T> allocationData)
Replaces the default allocation data.java.lang.String
toString()
void
use(ResourceOperation operation, T object)
Marks the object as being in use.
-
-
-
Constructor Detail
-
AllocationTable
public AllocationTable(AllocationData<T> allocationData, java.util.Collection<T> objects)
Constructs a resource allocation table.- Parameters:
allocationData
- the allocation data.objects
- the available objects.
-
AllocationTable
public AllocationTable(AllocationData<T> allocationData, Supplier<T> supplier)
Constructs a resource allocation table.- Parameters:
allocationData
- the allocation data.supplier
- the object generator.
-
-
Method Detail
-
getAllocationData
public AllocationData<T> getAllocationData()
Returns the default allocation data.- Returns:
- the default allocation data.
-
setAllocationData
public void setAllocationData(AllocationData<T> allocationData)
Replaces the default allocation data.- Parameters:
allocationData
- new allocation data.
-
reset
public void reset()
Resets the resource allocation table.
-
exists
public boolean exists(T object)
Checks whether the object exists in the allocation table.- Parameters:
object
- the object to be checked.- Returns:
true
if the object exists;false
otherwise.
-
free
public void free(T object)
Frees (deallocates) the object.- Parameters:
object
- the object to be freed.
-
use
public void use(ResourceOperation operation, T object)
Marks the object as being in use.- Parameters:
operation
- the operation on the object.object
- the object to be used.
-
peek
public T peek(java.util.Collection<T> retain, java.util.Collection<T> exclude, java.util.Map<ResourceOperation,java.lang.Integer> rate)
Peeks an object.- Parameters:
retain
- the objects that should be used for allocation.exclude
- the objects that should not be peeked.rate
- the dependencies biases.- Returns:
- the peeked object.
-
allocate
public T allocate(ResourceOperation operation, java.util.Collection<T> retain, java.util.Collection<T> exclude, java.util.Map<ResourceOperation,java.lang.Integer> rate)
Allocates an object and marks it as being in use.- Parameters:
operation
- the operation.retain
- the objects that should be used for allocation.exclude
- the objects that should not be allocated.rate
- the dependencies biases.- Returns:
- an allocated object.
-
getSupplier
public Supplier<T> getSupplier()
Returns the object generator.- Returns:
- the object generator.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-