Skip to content

Commit 7b4758a

Browse files
committed
Fix BitBufferDirect
1 parent e395da4 commit 7b4758a

File tree

3 files changed

+13
-54
lines changed

3 files changed

+13
-54
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.fastfilter.cuckoo.CuckooPlus16;
1010
import org.fastfilter.cuckoo.CuckooPlus8;
1111
import org.fastfilter.gcs.GolombCompressedSet;
12+
import org.fastfilter.gcs.GolombCompressedSet2;
1213
import org.fastfilter.mphf.MPHFilter;
1314
import org.fastfilter.xor.Xor16;
1415
import org.fastfilter.xor.Xor8;
@@ -104,6 +105,12 @@ public Filter construct(long[] keys, int setting) {
104105
return GolombCompressedSet.construct(keys, setting);
105106
}
106107
},
108+
GCS2 {
109+
@Override
110+
public Filter construct(long[] keys, int setting) {
111+
return GolombCompressedSet2.construct(keys, setting);
112+
}
113+
},
107114
MPHF {
108115
@Override
109116
public Filter construct(long[] keys, int setting) {

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

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

33
import java.nio.ByteBuffer;
4-
import java.nio.ByteOrder;
54

65
public class BitBufferDirect {
76

@@ -11,14 +10,14 @@ public class BitBufferDirect {
1110

1211
public BitBufferDirect(long bits) {
1312
this.data = ByteBuffer.allocateDirect((int)((bits + 7) / 8));
14-
this.data.order(ByteOrder.nativeOrder());
13+
// this.data.order(ByteOrder.nativeOrder());
1514
}
1615

1716
public BitBufferDirect(byte[] byteArray) {
1817
this.data = ByteBuffer.allocateDirect(byteArray.length);
1918
data.put(byteArray);
2019
data.flip();
21-
this.data.order(ByteOrder.nativeOrder());
20+
// this.data.order(ByteOrder.nativeOrder());
2221
}
2322

2423
public int position() {
@@ -124,26 +123,6 @@ public int readUntilZero(int pos) {
124123
long current = data.getLong((int) (pos >>> 3));
125124
long x = ~current << ((pos & 7));
126125
return Long.numberOfLeadingZeros(x);
127-
128-
// int remainingBits = 64 - (pos & 63);
129-
// int index = pos >>> 6;
130-
// long x = data.getLong(index << 3) << (64 - remainingBits);
131-
// int count = Long.numberOfLeadingZeros(~x);
132-
// if (count < remainingBits) {
133-
// return count;
134-
// }
135-
// return readUntilZeroMore(count, index);
136-
}
137-
138-
private int readUntilZeroMore(int count, int index) {
139-
while (true) {
140-
long x = data.getLong(++index << 3);
141-
if (x == -1L) {
142-
count += 64;
143-
continue;
144-
}
145-
return count + Long.numberOfLeadingZeros(~x);
146-
}
147126
}
148127

149128
public void write(BitBufferDirect bits) {

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

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,13 @@ public void testEliasDeltaRoundtrip() {
137137

138138
@Test
139139
public void testNumberRoundtrip() {
140+
// with regular BitBuffer, the max bit count is 65 (that is, 0..64)
141+
int maxBitCount = 58;
140142
Random r = new Random(1);
141143
BitBufferDirect buff = new BitBufferDirect(8 * 1024 * 1024);
142144
for (int i = 0; i < 1000; i++) {
143145
long val = r.nextLong();
144-
int bitCount = r.nextInt(65);
146+
int bitCount = r.nextInt(maxBitCount);
145147
if (bitCount < 64) {
146148
val &= ((1L << bitCount) - 1);
147149
}
@@ -151,7 +153,7 @@ public void testNumberRoundtrip() {
151153
r = new Random(1);
152154
for (int i = 0; i < 1000; i++) {
153155
long val = r.nextLong();
154-
int bitCount = r.nextInt(65);
156+
int bitCount = r.nextInt(maxBitCount);
155157
if (bitCount < 64) {
156158
val &= ((1L << bitCount) - 1);
157159
}
@@ -208,35 +210,6 @@ public void testWriteBuffer() {
208210
}
209211
}
210212

211-
@Test
212-
public void testWriteBuffer2() {
213-
BitBufferDirect buff = new BitBufferDirect(8000);
214-
for (int i = 1; i < 100; i++) {
215-
BitBufferDirect b = new BitBufferDirect(100);
216-
// b.writeEliasDelta(i);
217-
// assertEquals(b.position(), BitBufferDirect.getEliasDeltaSize(i));
218-
for (int j = 0; j < i; j++) {
219-
b.writeBit(1);
220-
}
221-
b.writeBit(0);
222-
buff.write(b);
223-
}
224-
buff.seek(0);
225-
for (int i = 1; i < 100; i++) {
226-
// if (i != buff.readEliasDelta()) {
227-
// System.out.println("??");
228-
// }
229-
// assertEquals(i, buff.readEliasDelta());
230-
for (int j = 0; j < i; j++) {
231-
if (1 != buff.readBit()) {
232-
System.out.println("??");
233-
}
234-
// assertEquals(1, buff.readBit());
235-
}
236-
assertEquals(0, buff.readBit());
237-
}
238-
}
239-
240213
@Test
241214
public void testSeek() {
242215
BitBufferDirect buff = new BitBufferDirect(8000);

0 commit comments

Comments
 (0)