From 656f36f3fb0bbca81de84873dbe75efe7446c931 Mon Sep 17 00:00:00 2001 From: jjenista Date: Tue, 17 Nov 2009 00:14:04 +0000 Subject: [PATCH] inlined a getKey and get op in sendFeedback --- .../SpamFilter/DistributedHashMap.java | 24 ++++++------ .../Distributed/SpamFilter/HashEntry.java | 2 + .../Distributed/SpamFilter/SpamFilter.java | 37 ++++++++++++++++++- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/Robust/src/Benchmarks/Distributed/SpamFilter/DistributedHashMap.java b/Robust/src/Benchmarks/Distributed/SpamFilter/DistributedHashMap.java index 8ea2010a..b018bfc5 100644 --- a/Robust/src/Benchmarks/Distributed/SpamFilter/DistributedHashMap.java +++ b/Robust/src/Benchmarks/Distributed/SpamFilter/DistributedHashMap.java @@ -1,6 +1,6 @@ public class DistributedHashMap { - DistributedHashEntry[] table; - float loadFactor; + public DistributedHashEntry[] table; + public float loadFactor; public DistributedHashMap(int initialCapacity, float loadFactor) { init(initialCapacity, loadFactor); @@ -19,13 +19,14 @@ public class DistributedHashMap { return value; } + /* Object remove(Object key) { int hashcode=key.hashCode(); int index1=hash1(hashcode, table.length); DistributedHashEntry dhe=table[index1]; if (dhe==null) return null; - DHashEntry ptr=dhe.array; + HashEntry ptr=dhe.array; if (ptr!=null) { if (ptr.hashval==hashcode&&ptr.key.equals(key)) { @@ -54,7 +55,7 @@ public class DistributedHashMap { if (dhe==null) return null; - DHashEntry ptr=dhe.array; + HashEntry ptr=dhe.array; while(ptr!=null) { if (ptr.hashval==hashcode @@ -75,7 +76,7 @@ public class DistributedHashMap { if (dhe==null) return null; - DHashEntry ptr=dhe.array; + HashEntry ptr=dhe.array; while(ptr!=null) { if (ptr.hashval==hashcode @@ -94,7 +95,7 @@ public class DistributedHashMap { if (dhe==null) return false; - DHashEntry ptr=dhe.array; + HashEntry ptr=dhe.array; while(ptr!=null) { if (ptr.hashval==hashcode @@ -114,7 +115,7 @@ public class DistributedHashMap { dhe=global new DistributedHashEntry(); table[index1]=dhe; } - DHashEntry ptr=dhe.array; + HashEntry ptr=dhe.array; while(ptr!=null) { if (ptr.hashval==hashcode&&ptr.key.equals(key)) { @@ -125,7 +126,7 @@ public class DistributedHashMap { ptr=ptr.next; } - DHashEntry he=global new DHashEntry(); + HashEntry he=global new HashEntry(); he.value=value; he.key=key; he.hashval=hashcode; @@ -136,6 +137,7 @@ public class DistributedHashMap { return null; } + */ } class DistributedHashEntry { @@ -147,10 +149,10 @@ class DistributedHashEntry { class DHashEntry { - public DHashEntry() { + public HashEntry() { } int hashval; - Object key; - Object value; + HashEntry key; + FilterStatistic value; DHashEntry next; } diff --git a/Robust/src/Benchmarks/Distributed/SpamFilter/HashEntry.java b/Robust/src/Benchmarks/Distributed/SpamFilter/HashEntry.java index 2021a691..7b391f8c 100644 --- a/Robust/src/Benchmarks/Distributed/SpamFilter/HashEntry.java +++ b/Robust/src/Benchmarks/Distributed/SpamFilter/HashEntry.java @@ -2,7 +2,9 @@ public class HashEntry { GString engine; GString signature; HashStat stats; + public HashEntry() { + } /** diff --git a/Robust/src/Benchmarks/Distributed/SpamFilter/SpamFilter.java b/Robust/src/Benchmarks/Distributed/SpamFilter/SpamFilter.java index 1b248686..7c485620 100644 --- a/Robust/src/Benchmarks/Distributed/SpamFilter/SpamFilter.java +++ b/Robust/src/Benchmarks/Distributed/SpamFilter/SpamFilter.java @@ -299,14 +299,47 @@ public class SpamFilter extends Thread { myhe.setengine(engine); myhe.setsig(signature); + + // ----- now connect to global data structure and update stats ----- - HashEntry tmphe = (HashEntry)(mydhmap.getKey(myhe)); + //HashEntry tmphe = (HashEntry)(mydhmap.getKey(myhe)); + HashEntry tmphe; + FilterStatistic fs; + int hashCode = myhe.hashCode(); + int index1 = mydhmap.hash1(hashCode, mydhmap.table.length); + DistributedHashEntry testhe = mydhmap.table[index1]; + if(testhe==null) { + tmphe=null; + fs=null; + } else { + DHashEntry ptr=testhe.array; + int point=0; + while(ptr !=null) { + if(ptr.hashval==hashcode&&ptr.key.equals(key)) { + tmphe=ptr.key; + fs=ptr.value; + point=1; + break; + } + ptr=ptr.next; + } + if(point != 1) { + tmphe=null; + fs=null; + } + } + //tmphe has the key at the end + //fs has the value at the end + + if(tmphe.stats.userid[id] != 1) { tmphe.stats.setuserid(id); } + //---- get value from distributed hash and update spam count - FilterStatistic fs = (FilterStatistic) (mydhmap.get(myhe)); + //FilterStatistic fs = (FilterStatistic) (mydhmap.get(myhe)); + //System.out.println(fs.toString()); -- 2.34.1