Gitlab service upgraded. Please report any problems to dl_gitadmin@cs.lth.se

Commit c2f16d30 authored by Noric Couderc's avatar Noric Couderc

Fixed index generation for Maps

Index generation for maps generated uniform random values on a massive range
that meant that Map applications would almost never call get() and get a result.
We generate index on twice the size of the map, so some get() calls find a
result, and some do not, which is slightly more realistic.
parent 04cdf092
......@@ -73,6 +73,8 @@ public abstract class Application<T> {
}
}
abstract public int generateIndex();
public T getDataStructure() { return dataStructure; }
public String getDataStructureName() { return dataStructure.getClass().getCanonicalName(); }
......
......@@ -12,7 +12,7 @@ public class CollectionApplication<T extends Collection> extends Application<T>
randomGenerator.ints(100).forEach((i) -> argument.add(i));
}
protected int generateIndex() {
public int generateIndex() {
return randomGenerator.nextInt(dataStructure.size());
}
......
package se.lth.cs;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
public class ListApplication extends CollectionApplication<List<Integer>> {
......
......@@ -11,7 +11,7 @@ public class MapApplication extends Application<Map<Integer, Integer>> {
public void runClear() { dataStructure.clear(); }
public void runContainsKey() { dataStructure.containsKey(randomGenerator.nextInt()); }
public void runContainsKey() { dataStructure.containsKey(generateIndex()); }
public void runContainsValue() { dataStructure.containsValue(randomGenerator.nextInt()); }
......@@ -19,7 +19,7 @@ public class MapApplication extends Application<Map<Integer, Integer>> {
public void runEquals() { dataStructure.equals(argument); }
public void runGet() { dataStructure.get(randomGenerator.nextInt()); }
public void runGet() { dataStructure.get(generateIndex()); }
public void runHashCode() { dataStructure.hashCode(); }
......@@ -29,7 +29,7 @@ public class MapApplication extends Application<Map<Integer, Integer>> {
public void runPut() {
dataStructure.put(
randomGenerator.nextInt(),
generateIndex(),
randomGenerator.nextInt());
}
......@@ -37,7 +37,7 @@ public class MapApplication extends Application<Map<Integer, Integer>> {
dataStructure.putAll(argument);
}
public void runRemove() { dataStructure.remove(randomGenerator.nextInt()); }
public void runRemove() { dataStructure.remove(generateIndex()); }
public void runSize() { dataStructure.size(); }
......@@ -48,4 +48,9 @@ public class MapApplication extends Application<Map<Integer, Integer>> {
super.benchmark();
dataStructure = dataStructure.getClass().newInstance();
}
@Override
public int generateIndex() {
return randomGenerator.nextInt(2 * dataStructure.size() + 1);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment