fixing bloom filter - counting from the right not from the left !!!
This commit is contained in:
parent
282657f41d
commit
18eeb587a9
|
@ -311,9 +311,9 @@ public class ByteUtil {
|
|||
if ( (data.length * 8) - 1 < pos )
|
||||
throw new Error("outside byte array limit, pos: " + pos);
|
||||
|
||||
int posByte = (pos) / 8;
|
||||
int posByte = data.length - 1 - (pos) / 8;
|
||||
int posBit = (pos) % 8;
|
||||
byte setter = (byte)(1 << (7 - posBit));
|
||||
byte setter = (byte)(1 << (posBit));
|
||||
byte toBeSet = data[posByte];
|
||||
byte result;
|
||||
if(val == 1)
|
||||
|
@ -330,9 +330,9 @@ public class ByteUtil {
|
|||
if ((data.length * 8) - 1 < pos )
|
||||
throw new Error("outside byte array limit, pos: " + pos);
|
||||
|
||||
int posByte = pos / 8;
|
||||
int posByte = data.length - 1 - pos / 8;
|
||||
int posBit = pos % 8;
|
||||
byte dataByte = data[posByte];
|
||||
return Math.min(1, (dataByte & (1 << (7 - posBit))));
|
||||
return Math.min(1, (dataByte & (1 << (posBit))));
|
||||
}
|
||||
}
|
|
@ -246,20 +246,20 @@ public class ByteUtilTest {
|
|||
*/
|
||||
byte[] data = ByteBuffer.allocate(4).putInt(0).array();
|
||||
int posBit = 24;
|
||||
int expected = 128;
|
||||
int expected = 16777216;
|
||||
int result = -1;
|
||||
byte[] ret = ByteUtil.setBit(data, posBit, 1);
|
||||
result = ByteUtil.byteArrayToInt(ret);
|
||||
assertTrue(expected == result);
|
||||
|
||||
posBit = 25;
|
||||
expected = 192;
|
||||
expected = 50331648;
|
||||
ret = ByteUtil.setBit(data, posBit, 1);
|
||||
result = ByteUtil.byteArrayToInt(ret);
|
||||
assertTrue(expected == result);
|
||||
|
||||
posBit = 2;
|
||||
expected = 536871104;
|
||||
expected = 50331652;
|
||||
ret = ByteUtil.setBit(data, posBit, 1);
|
||||
result = ByteUtil.byteArrayToInt(ret);
|
||||
assertTrue(expected == result);
|
||||
|
@ -268,13 +268,13 @@ public class ByteUtilTest {
|
|||
Set off
|
||||
*/
|
||||
posBit = 24;
|
||||
expected = 536870976;
|
||||
expected = 33554436;
|
||||
ret = ByteUtil.setBit(data, posBit, 0);
|
||||
result = ByteUtil.byteArrayToInt(ret);
|
||||
assertTrue(expected == result);
|
||||
|
||||
posBit = 25;
|
||||
expected = 536870912;
|
||||
expected = 4;
|
||||
ret = ByteUtil.setBit(data, posBit, 0);
|
||||
result = ByteUtil.byteArrayToInt(ret);
|
||||
assertTrue(expected == result);
|
||||
|
|
Loading…
Reference in New Issue