From: adash Date: Fri, 30 Oct 2009 00:30:17 +0000 (+0000) Subject: initial checkin X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a174c3177eba6f7685f8be548a502c67ed2a269a;p=IRC.git initial checkin --- diff --git a/Robust/src/Benchmarks/Distributed/SpamFilter/DistributedHashMap.java b/Robust/src/Benchmarks/Distributed/SpamFilter/DistributedHashMap.java new file mode 100644 index 00000000..f8601118 --- /dev/null +++ b/Robust/src/Benchmarks/Distributed/SpamFilter/DistributedHashMap.java @@ -0,0 +1,169 @@ +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 { + int hashval; + Object key; + Object value; + DHashEntry next; + public DHashEntry() { + } +} diff --git a/Robust/src/Benchmarks/Distributed/SpamFilter/HashEntry.java b/Robust/src/Benchmarks/Distributed/SpamFilter/HashEntry.java new file mode 100644 index 00000000..31d60aad --- /dev/null +++ b/Robust/src/Benchmarks/Distributed/SpamFilter/HashEntry.java @@ -0,0 +1,45 @@ +public class HashEntry { + String engine; + String signature; + HashStat stats; + public HashEntry() { + } + + /** + * hashCode that combines two strings using xor. + * @return a hash code value on the entire object. + */ + public int hashCode() { + int result=0; + // this will not work well if some of the strings are equal. + result = engine.hashCode(); + result ^= signature.hashCode(); + result ^= stats.hashCode(); + return result; + } + + public String getEngine() { + return engine; + } + + public String getSignature() { + return signature; + } + + public Stat getStats() { + return stats; + } + + public boolean equals(Object o) { + if(o.getType()!=getType()) + return false; + HashEntry he = (HashEntry)o; + if(!(he.getEngine().equals(Engine))) + return false; + if(!(he.getSignature().equals(Signature))) + return false; + if(!(he.getStats().equals(stats))) + return false; + return true; + } +} diff --git a/Robust/src/Benchmarks/Distributed/SpamFilter/HashStat.java b/Robust/src/Benchmarks/Distributed/SpamFilter/HashStat.java new file mode 100644 index 00000000..68b3ebf5 --- /dev/null +++ b/Robust/src/Benchmarks/Distributed/SpamFilter/HashStat.java @@ -0,0 +1,27 @@ +public class HashStat { + int[] userid; + FilterStatistic[] userstat; + public HashStat() { + userid = new int[8]; //max users for our system=8 + userstat = new FilterStatistic[8]; + for(int i=0; i<8; i++) { + userstat[i] = new FilterStatistic(); + } + } + + public int getuser(int id) { + return userid[id]; + } + + public int getspamcount(int userid) { + return userstat[userid].getSpam(); + } + + public int gethamcount(int userid) { + return userstat[userid].getham(); + } + + public int getunknowncount(int userid) { + return userstat[userid].getUnknown(); + } +}