|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectN08_Part2_DataStructureAccess.TaskAbstract
protected abstract static class N08_Part2_DataStructureAccess.TaskAbstract
Abstract base class for Tasks which measure the access time of "array-like" data structures: arrays, array-like Lists (e.g. ArrayList and Vector), and associative arrays (i.e. Maps).
Subclasses must obey all the rules below.
Rule #1: a dedicated subclass must written for each type of data structure.
Rule #2: each subclass must implement its run
method like:
public void run() {
for (int i = 0; i < size
; i++) {
index
= [the value of the element at the current value of index in the data structure];
}
}
Rule #3: all subclass data structures must be isomorphic to the result of makeIntegers
,
namely, their (index/key, value) pairs must be identical to makeIntegers
.
This requirement is automatically satisfied by N08_Part2_DataStructureAccess.ArrayAccess
and its subclasses.
Those subclasses which are Lists should clear themselves and then add all the elements of makeIntegers
.
Those subclasses which are Maps should clear themselves
and then in a loop over the elements of makeIntegers
do map.put( integer, integer );
.
The reason for these rules is that the values of makeIntegers
are cleverly choosen
so that the loop in run
accesses the data structure's elements
in a specific pattern (either sequential or random).
To see how this works for the sequential case,
suppose that the data structure is the result of makeIntegers
, so that the code is
public void run() {
for (int i = 0; i < integers.length; i++) {
index = integers[index.intValue()];
}
}
(This is how N08_Part2_DataStructureAccess.ArrayAccess
is implemented.)
If all (but the last) elements of integers
satisfy integers[i] equals i + 1
,
then the loop in run
accesses the elements of integers
sequentially
(assuming that index is initialized to 0, and that the last element of integers
also is 0).
The other functionality defined in this base class is DCE prevention, given that subclasses will be Runnable task classes.
Field Summary | |
---|---|
protected Integer |
index
Index/key of the next element of the data structure that will be accessed. |
protected N08_Part2_DataStructureAccess.Mode |
mode
Access pattern mode of the data structure. |
protected int |
size
Size of the data structure. |
Constructor Summary | |
---|---|
protected |
N08_Part2_DataStructureAccess.TaskAbstract(int size,
N08_Part2_DataStructureAccess.Mode mode)
Constructor. |
Method Summary | |
---|---|
protected void |
checkIntegers(Integer[] integers,
Integer[] indices)
Checks that integers is suitable for use in the run method described in the class javadocs (i.e. every element is accessed in an iteration identical to the run loop in the order specified by indices). |
protected Integer[] |
makeIndices()
Returns an Integer[] that specifies the sequence of indices of the relevant data structure that will be accessed by the loop in {kink #run run}. |
protected Integer[] |
makeIntegers()
Returns an Integer[] that always contains the numbers [0, size - 1]. |
protected void |
postBenchmarkCheck()
|
String |
toString()
Returns the String representation of index
to prevent DCE. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.lang.Runnable |
---|
run |
Field Detail |
---|
protected final N08_Part2_DataStructureAccess.Mode mode
protected final int size
protected Integer index
Additionally, since the instances that will be benchmarked are Runnables,
this field stores the value of some computation done in run
to prevent DCE.
Constructor Detail |
---|
protected N08_Part2_DataStructureAccess.TaskAbstract(int size, N08_Part2_DataStructureAccess.Mode mode) throws IllegalArgumentException
size
- specifies the number of elements in the data structuremode
- specifies the data structure access pattern:
IllegalArgumentException
- if size < 1; mode is nullMethod Detail |
---|
protected Integer[] makeIntegers()
mode
.
Side effect: assigns index
to the 0th element of the result.
protected Integer[] makeIndices()
protected void checkIntegers(Integer[] integers, Integer[] indices) throws IllegalStateException
IllegalStateException
public String toString()
index
to prevent DCE.
toString
in class Object
protected void postBenchmarkCheck() throws IllegalStateException
IllegalStateException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |