From 99e3b71770bd2e3fabf25a4f5a98a687a1ce91c4 Mon Sep 17 00:00:00 2001 From: adash Date: Fri, 13 Feb 2009 06:14:30 +0000 Subject: [PATCH] New changes --- .../LookUpService/dsm/DistributedHashMap.java | 196 ++++++++++++++++++ .../LookUpService/dsm/LookUpService.java | 20 +- .../Distributed/LookUpService/dsm/makefile | 6 +- 3 files changed, 202 insertions(+), 20 deletions(-) create mode 100644 Robust/src/Benchmarks/Distributed/LookUpService/dsm/DistributedHashMap.java diff --git a/Robust/src/Benchmarks/Distributed/LookUpService/dsm/DistributedHashMap.java b/Robust/src/Benchmarks/Distributed/LookUpService/dsm/DistributedHashMap.java new file mode 100644 index 00000000..b3e6c9e8 --- /dev/null +++ b/Robust/src/Benchmarks/Distributed/LookUpService/dsm/DistributedHashMap.java @@ -0,0 +1,196 @@ +public class DistributedHashMap { + DistributedHashEntry[] table; + float loadFactor; + int secondcapacity; + + public DistributedHashMap(int initialCapacity, int secondcapacity, float loadFactor) { + init(initialCapacity, secondcapacity, loadFactor); + } + + private void init(int initialCapacity, int secondcapacity, float loadFactor) { + table=global new DistributedHashEntry[initialCapacity]; + this.loadFactor=loadFactor; + this.secondcapacity=secondcapacity; + } + + private static int hash1(int hashcode, int length) { + int value=hashcode%length; + if (value<0) + return -value; + else + return value; + } + + private static int hash2(int hashcode, int length1, int length2) { + int value=(hashcode*31)%length2; + if (value<0) + return -value; + else + return value; + } + + void resize(int index) { + DHashEntry[] oldtable=table[index].array; + int newCapacity=oldtable.length*2+1; + DHashEntry [] newtable=global new DHashEntry[newCapacity]; + table[index].array=newtable; + + for(int i=0; i(loadFactor*dhe.array.length)) { + //Resize the table + resize(index1); + } + return null; + } +} + + +class DistributedHashEntry { + public DistributedHashEntry(int capacity) { + array=global new DHashEntry[capacity]; + } + int count; + DHashEntry[] array; +} + + +class DHashEntry { + public DHashEntry() { + } + int hashval; + Object key; + Object value; + DHashEntry next; +} diff --git a/Robust/src/Benchmarks/Distributed/LookUpService/dsm/LookUpService.java b/Robust/src/Benchmarks/Distributed/LookUpService/dsm/LookUpService.java index 850f6e40..c324e5d4 100644 --- a/Robust/src/Benchmarks/Distributed/LookUpService/dsm/LookUpService.java +++ b/Robust/src/Benchmarks/Distributed/LookUpService/dsm/LookUpService.java @@ -57,13 +57,11 @@ public class LookUpService extends Thread { int rdwr = rand.nextInt(100); int rwkey = rand.nextInt(nobjs); Integer key = global new Integer(rwkey); - Object o1 = key; if (rdwr < rdprob) { - Object o3 = mydhmap.get(o1); //Read + Object o3 = mydhmap.get(key); //Read } else { Integer val = global new Integer(j); - Object o2 = val; - mydhmap.put(o1, o2); //Modify + mydhmap.put(key, val); //Modify } } } @@ -90,6 +88,7 @@ public class LookUpService extends Thread { atomic { dhmap = global new DistributedHashMap(100, 100, 0.75f); + //Add to the hash map for(int i = 0; i < ls.nobjs; i++) { Integer key = global new Integer(i); Integer val = global new Integer(i*i); @@ -103,19 +102,6 @@ public class LookUpService extends Thread { } } - //Add to the hash map - /* - atomic { - for(int i = 0; i < ls.nobjs; i++) { - Integer key = global new Integer(i); - Integer val = global new Integer(i*i); - Object o1 = key; - Object o2 = val; - dhmap.put(o1, o2); - } - } - */ - LookUpService tmp; /* Start threads */ for(int i = 0; i