Skip to content

Commit a3ea4b2

Browse files
committed
Strata estimator working with cutoff
1 parent 83580ff commit a3ea4b2

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

bloom/src/bloom/Main.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package bloom;
22

3-
import java.util.HashSet;
43
import java.util.Set;
54

65
import bloom.dd.StrataEstimator;
@@ -162,9 +161,9 @@ public static void correctionOverhead(int num_keys, int num_strata, int num_hash
162161
}
163162

164163
public static void correctionOverheadFixedStrata(int num_keys, int num_strata, int num_hash_functions, int ibfsize){
165-
int trials = 100, difference;
166-
int[] deltas = {10, 100, 1000, 10000};
167-
int[] results = new int[deltas.length];
164+
int trials = 50, difference;
165+
int[] deltas = {10, 100, 1000, 10000, 100000};
166+
double[] results = new double[deltas.length];
168167
Hash hash;
169168
Set<String> keys1, keys2;
170169
StrataEstimator se1, se2;
@@ -176,6 +175,7 @@ public static void correctionOverheadFixedStrata(int num_keys, int num_strata, i
176175

177176
for (int i=0; i < deltas.length; ++i){
178177
for (int t=0; t < trials; ++t){
178+
System.out.print(t+", ");
179179

180180
keys1 = Utilities.createKeys(num_keys);
181181
keys2 = Utilities.createKeys(deltas[i], keys1);
@@ -191,9 +191,9 @@ public static void correctionOverheadFixedStrata(int num_keys, int num_strata, i
191191
System.out.println(deltas[i]+" - Strata estimator was unable to deocde");
192192
}
193193

194-
results[i] += (float) deltas[i] / (float) difference;
195-
194+
results[i] += (float) deltas[i] / (float) difference;
196195
}
196+
System.out.println("\n");
197197
}
198198

199199
System.out.println("-----Results----");

bloom/src/bloom/dd/StrataEstimator.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,18 @@ public int getHashCount(){
5959
return hashCount;
6060
}
6161

62+
public Hash getHash(){
63+
return hash;
64+
}
65+
6266
public InvertibleBloomFilter getIBF(int index){
63-
assert index <= strata; //TODO throw exception
67+
assert index < this.strata; //TODO throw exception
6468
return bloomfilters[index];
6569
}
6670

6771
public void insert(String key){
6872
int trailingZeros = getNumberOfTrailingZeros(key);
69-
if (trailingZeros < this.strata){
73+
if (trailingZeros < this.getStrata()){
7074
bloomfilters[trailingZeros].insert(key);
7175
}
7276
}
@@ -79,17 +83,19 @@ public void insert(Set<String> keys){
7983

8084
public void remove(String key){
8185
int trailingZeros = getNumberOfTrailingZeros(key);
82-
bloomfilters[trailingZeros].remove(key);
86+
if (trailingZeros < this.getStrata()){
87+
bloomfilters[trailingZeros].remove(key);
88+
}
8389
}
8490

8591
private int getNumberOfTrailingZeros(String key){
86-
int hashCode = this.hash.getHashCode(key);
87-
//int hashCode = (int) (HashFunction.fnv1Hash(key)%Math.pow(2,STRATA));
92+
int hashCode = this.getHash().getHashCode(key);
8893
int counter = STRATA-1;
8994
while (hashCode > 0){
9095
hashCode = hashCode/2;
9196
counter--;
9297
}
98+
9399
return counter;
94100
}
95101
/**
@@ -110,7 +116,7 @@ public int estimateDifference(Estimator estimator) throws Exception{
110116
InvertibleBloomFilter ibf;
111117
int difference = 0;
112118

113-
for(int i = this.strata-1; i >= 0; i--){
119+
for(int i = this.getStrata()-1; i >= 0; i--){
114120
ibf = this.getIBF(i).subtract(se.getIBF(i));
115121
keys = ibf.getPureKeys();
116122

bloom/test/DifferenceDigestTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import static org.junit.Assert.*;
22

3-
import java.util.HashSet;
43
import java.util.Set;
54

65
import org.junit.Test;

results.xlsx

-22 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)