Database Reference
In-Depth Information
public MinCount(int b) throws IOException {
this.b = b;
int m = (int) Math. pow (2, b);
this.M = new int[3*m];
out = new ObjectOutputStream(hash);
reset();
}
Implementing the add() method is straightforward. Simply hash the input
value and then update the three smallest values:
public boolean add(E arg0) {
try {
hash.reset();
out.writeObject(arg0);
out.flush();
int h = hash.hash();
int m = (h >>> (32-b));
int v = (h << b) >>> b;
if(M[m] > v) {
M[m+2] = M[m+1];
M[m] = v;
} else if(M[m+1] > v) {
M[m+2] = M[m+1];
M[m+1] = v;
} else if(M[m+2] > v) {
M[m+2] = v;
}
return true;
} catch(IOException e) {
return false;
}
}
The only thing that remains is to implement the size() method to produce
a cardinality estimate:
public int size() {
double range = Math. pow (2,32-b);
Search WWH ::




Custom Search