[infinispan-commits] Infinispan SVN: r1732 - trunk/core/src/test/java/org/infinispan/distribution.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Thu Apr 29 12:34:12 EDT 2010
Author: manik.surtani at jboss.com
Date: 2010-04-29 12:34:12 -0400 (Thu, 29 Apr 2010)
New Revision: 1732
Modified:
trunk/core/src/test/java/org/infinispan/distribution/HashFunctionComparisonTest.java
Log:
Implement a better hash function to deal with specific types (byte arrays, addresses, Strings). Also allows for portable key location for HotRod clients.
Modified: trunk/core/src/test/java/org/infinispan/distribution/HashFunctionComparisonTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/HashFunctionComparisonTest.java 2010-04-29 16:28:38 UTC (rev 1731)
+++ trunk/core/src/test/java/org/infinispan/distribution/HashFunctionComparisonTest.java 2010-04-29 16:34:12 UTC (rev 1732)
@@ -62,28 +62,51 @@
private String greatestDist(SortedMap<Integer, Address> pos, int hashSpace) {
// calc distances between entries 0 and n - 1 first.
int largest = 0;
- int lastPos = 0;
+ int lastPos = lastEntry(pos).getKey();
int firstPos = -1;
for (int currentPos: pos.keySet()) {
if (firstPos == -1) firstPos = currentPos;
- largest = Math.max(largest, currentPos - lastPos);
+ largest = Math.max(largest, Math.abs(currentPos - lastPos));
lastPos = currentPos;
}
- // now for the difference between the last and first entries
- largest = Math.max(largest, hashSpace - lastPos + firstPos);
return String.valueOf(largest);
}
private String smallestDist(SortedMap<Integer, Address> pos, int hashSpace) {
- return null; // TODO
+ // calc distances between entries 0 and n - 1 first.
+ int smallest = Integer.MAX_VALUE;
+ int lastPos = lastEntry(pos).getKey();
+ int firstPos = -1;
+ for (int currentPos: pos.keySet()) {
+ if (firstPos == -1) firstPos = currentPos;
+ smallest = Math.min(smallest, Math.abs(currentPos - lastPos));
+ lastPos = currentPos;
+ }
+ return String.valueOf(smallest);
}
private String meanDist(SortedMap<Integer, Address> pos, int hashSpace) {
- return null; // TODO
+ // calc distances between entries 0 and n - 1 first.
+ int totalDist = 0;
+ int lastPos = lastEntry(pos).getKey();
+ int firstPos = -1;
+ for (int currentPos: pos.keySet()) {
+ if (firstPos == -1) firstPos = currentPos;
+ totalDist += Math.abs(currentPos - lastPos);
+ lastPos = currentPos;
+ }
+
+ return String.valueOf(totalDist / pos.size());
}
+ private Map.Entry<Integer, Address> lastEntry(SortedMap<Integer, Address> m) {
+ Map.Entry<Integer, Address> last = null;
+ for (Map.Entry<Integer, Address> e: m.entrySet()) last = e;
+ return last;
+ }
+
public void testHashFunctions() {
Set<HashFunction> functions = new HashSet<HashFunction>();
More information about the infinispan-commits
mailing list