Newer
Older

David Procházka
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package mhtree;
import messif.operations.Approximate;
public class ApproxState {
protected int limit;
protected int objectsChecked;
protected int bucketsVisited;
protected ApproxState() {
}
protected ApproxState(int limit) {
this.limit = limit;
}
public static ApproxState create(Approximate limits, MHTree mhTree) {
switch (limits.getLocalSearchType()) {
case PERCENTAGE:
return new ApproxStateObjects(Math.round((float) mhTree.getObjectCount() * (float) limits.getLocalSearchParam() / 100f));
case ABS_OBJ_COUNT:
return new ApproxStateObjects(limits.getLocalSearchParam());
case DATA_PARTITIONS:
return new ApproxStateBuckets(limits.getLocalSearchParam());
default:
return new ApproxState();
}
}
public void update(LeafNode node) {
objectsChecked += node.getObjectCount();
bucketsVisited++;
}
public boolean stop() {
return false;
}
private static class ApproxStateBuckets extends ApproxState {
private ApproxStateBuckets(int limit) {
super(limit);
}
@Override
public boolean stop() {
return bucketsVisited >= limit;
}
}
private static class ApproxStateObjects extends ApproxState {
private ApproxStateObjects(int limit) {
super(limit);
}
@Override
public boolean stop() {
return objectsChecked >= limit;
}
}
}