Skip to content

Commit 5eeaa9b

Browse files
committed
More buggy implementations to test directory
1 parent 10c7275 commit 5eeaa9b

File tree

12 files changed

+217
-89
lines changed

12 files changed

+217
-89
lines changed

fastfilter/src/main/java/org/fastfilter/FilterType.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import org.fastfilter.cuckoo.CuckooPlus16;
99
import org.fastfilter.cuckoo.CuckooPlus8;
1010
import org.fastfilter.gcs.GolombCompressedSet;
11-
import org.fastfilter.gcs.GolombCompressedSet2;
12-
import org.fastfilter.mphf.MPHFilter;
1311
import org.fastfilter.xor.Xor16;
1412
import org.fastfilter.xor.Xor8;
1513
import org.fastfilter.xor.XorSimple;
@@ -121,18 +119,6 @@ public Filter construct(long[] keys, int setting) {
121119
public Filter construct(long[] keys, int setting) {
122120
return GolombCompressedSet.construct(keys, setting);
123121
}
124-
},
125-
GCS2 {
126-
@Override
127-
public Filter construct(long[] keys, int setting) {
128-
return GolombCompressedSet2.construct(keys, setting);
129-
}
130-
},
131-
MPHF {
132-
@Override
133-
public Filter construct(long[] keys, int setting) {
134-
return MPHFilter.construct(keys, setting);
135-
}
136122
};
137123

138124
/**

fastfilter/src/main/java/org/fastfilter/gcs/BitBuffer.java

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,66 @@ public void seek(int pos) {
3535
this.pos = pos;
3636
}
3737

38-
public void clear() {
39-
Arrays.fill(data, 0);
38+
public long readBit() {
39+
return (data[pos >>> 6] >>> (63 - (pos++ & 63))) & 1;
4040
}
4141

42-
public void skipGolombRice(int shift) {
43-
pos = skipGolombRice(pos, shift);
42+
public void writeBit(long x) {
43+
if (x == 1) {
44+
data[pos >>> 6] |= 1L << (63 - (pos & 63));
45+
}
46+
pos++;
4447
}
4548

46-
public int skipGolombRice(int pos, int shift) {
47-
int q = readUntilZero(pos);
48-
return pos + q + 1 + shift;
49+
public void writeGolombRice(int shift, long value) {
50+
writeGolombRiceFast(shift, value);
51+
}
52+
53+
public void writeGolombRiceFast(int shift, long value) {
54+
long q = value >>> shift;
55+
if (q < 63) {
56+
long m = (2L << q) - 2;
57+
writeNumber(m, (int) (q + 1));
58+
} else {
59+
for (int i = 0; i < q; i++) {
60+
writeBit(1);
61+
}
62+
writeBit(0);
63+
}
64+
writeNumber(value & ((1L << shift) - 1), shift);
65+
}
66+
67+
public void writeEliasDelta(long value) {
68+
if (value <= 0) {
69+
throw new IllegalArgumentException();
70+
}
71+
int q = 64 - Long.numberOfLeadingZeros(value);
72+
int qq = 31 - Integer.numberOfLeadingZeros(q);
73+
for (int i = 0; i < qq; i++) {
74+
writeBit(0);
75+
}
76+
for (int i = qq; i >= 0; i--) {
77+
writeBit((q >>> i) & 1);
78+
}
79+
for (int i = q - 2; i >= 0; i--) {
80+
writeBit((value >>> i) & 1);
81+
}
82+
}
83+
84+
public long readEliasDelta() {
85+
int qq = 0;
86+
while (readBit() == 0) {
87+
qq++;
88+
}
89+
long q = 1;
90+
for (int i = qq; i > 0; i--) {
91+
q = (q << 1) | readBit();
92+
}
93+
long x = 1;
94+
for (long i = q - 2; i >= 0; i--) {
95+
x = (x << 1) | readBit();
96+
}
97+
return x;
4998
}
5099

51100
/**
@@ -105,17 +154,6 @@ public static long unfoldSigned(long x) {
105154
return ((x & 1) == 1) ? (x + 1) / 2 : -(x / 2);
106155
}
107156

108-
public void writeBit(long x) {
109-
if (x == 1) {
110-
data[pos >>> 6] |= 1L << (63 - (pos & 63));
111-
}
112-
pos++;
113-
}
114-
115-
public long readBit() {
116-
return (data[pos >>> 6] >>> (63 - (pos++ & 63))) & 1;
117-
}
118-
119157
public int readUntilZero(int pos) {
120158
int remainingBits = 64 - (pos & 63);
121159
int index = pos >>> 6;
@@ -138,57 +176,6 @@ private int readUntilZeroMore(int count, int index) {
138176
}
139177
}
140178

141-
public void writeGolombRice(int shift, long value) {
142-
writeGolombRiceFast(shift, value);
143-
}
144-
145-
public void writeGolombRiceFast(int shift, long value) {
146-
long q = value >>> shift;
147-
if (q < 63) {
148-
long m = (2L << q) - 2;
149-
writeNumber(m, (int) (q + 1));
150-
} else {
151-
for (int i = 0; i < q; i++) {
152-
writeBit(1);
153-
}
154-
writeBit(0);
155-
}
156-
writeNumber(value & ((1L << shift) - 1), shift);
157-
}
158-
159-
public void writeEliasDelta(long value) {
160-
if (value <= 0) {
161-
throw new IllegalArgumentException();
162-
}
163-
int q = 64 - Long.numberOfLeadingZeros(value);
164-
int qq = 31 - Integer.numberOfLeadingZeros(q);
165-
for (int i = 0; i < qq; i++) {
166-
writeBit(0);
167-
}
168-
for (int i = qq; i >= 0; i--) {
169-
writeBit((q >>> i) & 1);
170-
}
171-
for (int i = q - 2; i >= 0; i--) {
172-
writeBit((value >>> i) & 1);
173-
}
174-
}
175-
176-
public long readEliasDelta() {
177-
int qq = 0;
178-
while (readBit() == 0) {
179-
qq++;
180-
}
181-
long q = 1;
182-
for (int i = qq; i > 0; i--) {
183-
q = (q << 1) | readBit();
184-
}
185-
long x = 1;
186-
for (long i = q - 2; i >= 0; i--) {
187-
x = (x << 1) | readBit();
188-
}
189-
return x;
190-
}
191-
192179
/**
193180
* Write a number of bits. The most significant bit is written first.
194181
*
@@ -210,6 +197,19 @@ public void writeNumber(long x, int bitCount) {
210197
pos += bitCount;
211198
}
212199

200+
public void skipGolombRice(int shift) {
201+
pos = skipGolombRice(pos, shift);
202+
}
203+
204+
public int skipGolombRice(int pos, int shift) {
205+
int q = readUntilZero(pos);
206+
return pos + q + 1 + shift;
207+
}
208+
209+
public void clear() {
210+
Arrays.fill(data, 0);
211+
}
212+
213213
public static int getEliasDeltaSize(long value) {
214214
if (value <= 0) {
215215
throw new IllegalArgumentException();
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package org.fastfilter;
2+
3+
import org.fastfilter.bloom.BlockedBloom;
4+
import org.fastfilter.bloom.Bloom;
5+
import org.fastfilter.bloom.count.*;
6+
import org.fastfilter.cuckoo.Cuckoo16;
7+
import org.fastfilter.cuckoo.Cuckoo8;
8+
import org.fastfilter.cuckoo.CuckooPlus16;
9+
import org.fastfilter.cuckoo.CuckooPlus8;
10+
import org.fastfilter.gcs.GolombCompressedSet;
11+
import org.fastfilter.gcs.GolombCompressedSet2;
12+
import org.fastfilter.mphf.MPHFilter;
13+
import org.fastfilter.xor.Xor16;
14+
import org.fastfilter.xor.Xor8;
15+
import org.fastfilter.xor.XorSimple;
16+
import org.fastfilter.xor.XorSimple2;
17+
import org.fastfilter.xorplus.XorPlus8;
18+
19+
/**
20+
* The list of supported approximate membership implementations.
21+
*/
22+
public enum FilterType {
23+
BLOOM {
24+
@Override
25+
public Filter construct(long[] keys, int setting) {
26+
return Bloom.construct(keys, setting);
27+
}
28+
},
29+
COUNTING_BLOOM {
30+
@Override
31+
public Filter construct(long[] keys, int setting) {
32+
return CountingBloom.construct(keys, setting);
33+
}
34+
},
35+
SUCCINCT_COUNTING_BLOOM {
36+
@Override
37+
public Filter construct(long[] keys, int setting) {
38+
return SuccinctCountingBloom.construct(keys, setting);
39+
}
40+
},
41+
SUCCINCT_COUNTING_BLOOM_RANKED {
42+
@Override
43+
public Filter construct(long[] keys, int setting) {
44+
return SuccinctCountingBloomRanked.construct(keys, setting);
45+
}
46+
},
47+
BLOCKED_BLOOM {
48+
@Override
49+
public Filter construct(long[] keys, int setting) {
50+
return BlockedBloom.construct(keys, setting);
51+
}
52+
},
53+
SUCCINCT_COUNTING_BLOCKED_BLOOM {
54+
@Override
55+
public Filter construct(long[] keys, int setting) {
56+
return SuccinctCountingBlockedBloom.construct(keys, setting);
57+
}
58+
},
59+
SUCCINCT_COUNTING_BLOCKED_BLOOM_RANKED {
60+
@Override
61+
public Filter construct(long[] keys, int setting) {
62+
return SuccinctCountingBlockedBloomRanked.construct(keys, setting);
63+
}
64+
},
65+
XOR_SIMPLE {
66+
@Override
67+
public Filter construct(long[] keys, int setting) {
68+
return XorSimple.construct(keys);
69+
}
70+
},
71+
XOR_SIMPLE_2 {
72+
@Override
73+
public Filter construct(long[] keys, int setting) {
74+
return XorSimple2.construct(keys);
75+
}
76+
},
77+
XOR_8 {
78+
@Override
79+
public Filter construct(long[] keys, int setting) {
80+
return Xor8.construct(keys);
81+
}
82+
},
83+
XOR_16 {
84+
@Override
85+
public Filter construct(long[] keys, int setting) {
86+
return Xor16.construct(keys);
87+
}
88+
},
89+
XOR_PLUS_8 {
90+
@Override
91+
public Filter construct(long[] keys, int setting) {
92+
return XorPlus8.construct(keys);
93+
}
94+
},
95+
CUCKOO_8 {
96+
@Override
97+
public Filter construct(long[] keys, int setting) {
98+
return Cuckoo8.construct(keys);
99+
}
100+
},
101+
CUCKOO_16 {
102+
@Override
103+
public Filter construct(long[] keys, int setting) {
104+
return Cuckoo16.construct(keys);
105+
}
106+
},
107+
CUCKOO_PLUS_8 {
108+
@Override
109+
public Filter construct(long[] keys, int setting) {
110+
return CuckooPlus8.construct(keys);
111+
}
112+
},
113+
CUCKOO_PLUS_16 {
114+
@Override
115+
public Filter construct(long[] keys, int setting) {
116+
return CuckooPlus16.construct(keys);
117+
}
118+
},
119+
GCS {
120+
@Override
121+
public Filter construct(long[] keys, int setting) {
122+
return GolombCompressedSet.construct(keys, setting);
123+
}
124+
},
125+
GCS2 {
126+
@Override
127+
public Filter construct(long[] keys, int setting) {
128+
return GolombCompressedSet2.construct(keys, setting);
129+
}
130+
},
131+
MPHF {
132+
@Override
133+
public Filter construct(long[] keys, int setting) {
134+
return MPHFilter.construct(keys, setting);
135+
}
136+
};
137+
138+
/**
139+
* Construct the filter with the given keys and the setting.
140+
*
141+
* @param keys the keys
142+
* @param setting the setting (roughly bits per fingerprint)
143+
* @return the constructed filter
144+
*/
145+
public abstract Filter construct(long[] keys, int setting);
146+
147+
}

fastfilter/src/test/java/org/fastfilter/gcs/BitArrayTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package org.fastfilter.gcs;
22

3-
import java.util.Random;
4-
53
import org.fastfilter.gcs.BitBuffer;
64
import org.fastfilter.utils.RandomGenerator;
7-
import org.junit.Test;
85

96
public class BitArrayTest {
107

fastfilter/src/main/java/org/fastfilter/gcs/BitBufferDirect.java renamed to fastfilter/src/test/java/org/fastfilter/gcs/BitBufferDirect.java

File renamed without changes.

fastfilter/src/main/java/org/fastfilter/gcs/GolombCompressedSet2.java renamed to fastfilter/src/test/java/org/fastfilter/gcs/GolombCompressedSet2.java

File renamed without changes.

fastfilter/src/main/java/org/fastfilter/gcs/MonotoneList2.java renamed to fastfilter/src/test/java/org/fastfilter/gcs/MonotoneList2.java

File renamed without changes.

fastfilter/src/main/java/org/fastfilter/mphf/Builder.java renamed to fastfilter/src/test/java/org/fastfilter/mphf/Builder.java

File renamed without changes.

fastfilter/src/main/java/org/fastfilter/mphf/FastEvaluator.java renamed to fastfilter/src/test/java/org/fastfilter/mphf/FastEvaluator.java

File renamed without changes.

fastfilter/src/main/java/org/fastfilter/mphf/FastGenerator.java renamed to fastfilter/src/test/java/org/fastfilter/mphf/FastGenerator.java

File renamed without changes.

0 commit comments

Comments
 (0)