Skip to content

Commit 7eac146

Browse files
committed
XorBinaryFuse8 failed to construct on some data #31
1 parent 81f33f9 commit 7eac146

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse8.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,9 @@ public long getBitCount() {
4242
static int calculateSegmentLength(int arity, int size) {
4343
int segmentLength;
4444
if (arity == 3) {
45-
segmentLength = 2 << (int) (0.831 * Math.log(size) + 0.75 + 0.5);
46-
// max 16 bit
47-
// segmentLength = 1L << (int) (2.2 + 0.76 * log(size));
48-
// max 18 bit
49-
// segmentLength = 1L << (int) (2.0 + 0.95 * log(size));
45+
segmentLength = 1 << (int) Math.floor(Math.log(size) / Math.log(3.33) + 2.25);
5046
} else if (arity == 4) {
51-
segmentLength = 1 << (int) (0.936 * Math.log(size) - 1 + 0.5);
47+
return 1 << (int) Math.floor(Math.log(size) / Math.log(2.91) - 0.5);
5248
} else {
5349
// not supported
5450
segmentLength = 65536;
@@ -59,10 +55,9 @@ static int calculateSegmentLength(int arity, int size) {
5955
static double calculateSizeFactor(int arity, int size) {
6056
double sizeFactor;
6157
if (arity == 3) {
62-
sizeFactor = Math.max(1.125, 0.4 + 9.3 / Math.log(size));
63-
// sizeFactor = fmax(1.14, 0.14 + log(2000000) / log(size));
58+
sizeFactor = Math.max(1.125, 0.875 + 0.25 * Math.log(1000000) / Math.log(size));
6459
} else if (arity == 4) {
65-
sizeFactor = Math.max(1.075, 0.77 + 4.06 / Math.log(size));
60+
sizeFactor = Math.max(1.075, 0.77 + 0.305 * Math.log(600000) / Math.log(size));
6661
} else {
6762
// not supported
6863
sizeFactor = 2.0;
@@ -99,7 +94,6 @@ public static XorBinaryFuse8 construct(long[] keys) {
9994
private void addAll(long[] keys) {
10095
int size = keys.length;
10196
long[] reverseOrder = new long[size + 1];
102-
reverseOrder[size] = 1;
10397
byte[] reverseH = new byte[size];
10498
int reverseOrderPos = 0;
10599

@@ -118,6 +112,7 @@ private void addAll(long[] keys) {
118112
}
119113
int block = 1 << blockBits;
120114
while (true) {
115+
reverseOrder[size] = 1;
121116
int[] startPos = new int[block];
122117
for (int i = 0; i < 1 << blockBits; i++) {
123118
startPos[i] = (int) ((long) i * size / block);

0 commit comments

Comments
 (0)