Database Reference
In-Depth Information
outputs[i] = new ObjectOutputStream(hashes[i]);
}
}
public CountMinSketch(int width,int[] seeds) throws
IOException {
this.width = width;
this.depth = seeds.length;
m = new byte[width*depth];
initialize(m.length,seeds);
}
The update step simply needs to increment the appropriate register
locations and report the smallest to provide an estimate of the frequency.
The following code implements this update with a specific increment
amount, which is useful for merging two sketches. It also simplifies the
lookup process as shown in the following code:
public Long increment(Object arg0,long amount) {
int min = Integer. MAX_VALUE ;
for(int i=0;i<outputs.length;i++) {
hashes[i].reset();
try {
outputs[i].writeObject(arg0);
outputs[i].flush();
int h = hashes[i].hash() % width;
m[i*width + h] += amount;
if(m[i*width + h] < min) min = m[i*width + h];
} catch(IOException e) {
}
}
return (long) min;
}
public Long increment(Object arg0) { return
increment(arg0,1); }
public Long get(Object arg0) {
return increment(arg0,0);
}
Search WWH ::




Custom Search