Skip to content

Commit

Permalink
fix issue #41
Browse files Browse the repository at this point in the history
  • Loading branch information
takawitter committed Oct 2, 2023
1 parent a88c5de commit 3db3c90
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public int select0(int count) {
if(count <= c){
for(int j = 0; j < BITS_IN_BLOCK; j++){
if(i * BITS_IN_BLOCK + j >= size) return -1;
if((v & 0x8000000000000000L) != 1){
if((v & 0x8000000000000000L) == 0){
count--;
if(count == 0){
return i * BITS_IN_BLOCK + j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public int select0(int count) {
if(count <= c){
for(int j = 0; j < BITS_IN_BLOCK; j++){
if(i * BITS_IN_BLOCK + j >= size) return -1;
if((v & 0x8000000000000000L) != 1){
if((v & 0x8000000000000000L) == 0){
count--;
if(count == 0){
return i * BITS_IN_BLOCK + j;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright Takao Nakaguchi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.trie4j.bv;

import org.junit.Assert;
import org.junit.Test;

public class LongsRank0OnlySuccinctBitVectorTest
extends AbstractSuccinctBitVectorTest {
protected SuccinctBitVector create() {
return new LongsRank0OnlySuccinctBitVector(1);
}
protected SuccinctBitVector create(int initialCapacity) {
return new LongsRank0OnlySuccinctBitVector(initialCapacity);
}
protected SuccinctBitVector create(byte[] bytes, int bitsSize) {
return new LongsRank0OnlySuccinctBitVector(bytes, bitsSize);
}

@Test
public void test() throws Exception{
SuccinctBitVector bv = new LongsRank0OnlySuccinctBitVector(1);
bv.append0();
bv.append1();
Assert.assertEquals(1, bv.rank0(0));
Assert.assertEquals(1, bv.rank0(1));
Assert.assertEquals(2, bv.rank0(2));
Assert.assertEquals(3, bv.rank0(3));
Assert.assertEquals(4, bv.rank0(4));
Assert.assertEquals(5, bv.rank0(5));
Assert.assertEquals(6, bv.rank0(6));
Assert.assertEquals(7, bv.rank0(7));
try{
bv.rank0(64);
Assert.fail();
} catch(ArrayIndexOutOfBoundsException e){
}
}

@Test
public void test2() throws Exception{
SuccinctBitVector bv = new LongsRank0OnlySuccinctBitVector(
new byte[]{0x2d, 0x3f}, 16);
Assert.assertEquals(1, bv.rank0(0));
Assert.assertEquals(2, bv.rank0(1));
Assert.assertEquals(2, bv.rank0(2));
Assert.assertEquals(3, bv.rank0(3));
Assert.assertEquals(3, bv.rank0(4));
Assert.assertEquals(3, bv.rank0(5));
Assert.assertEquals(4, bv.rank0(6));
Assert.assertEquals(4, bv.rank0(7));
Assert.assertEquals(5, bv.rank0(8));
Assert.assertEquals(6, bv.rank0(9));
Assert.assertEquals(6, bv.rank0(10));
Assert.assertEquals(6, bv.rank0(11));
Assert.assertEquals(6, bv.rank0(12));
Assert.assertEquals(6, bv.rank0(13));
Assert.assertEquals(6, bv.rank0(14));
Assert.assertEquals(6, bv.rank0(15));
try{
bv.rank0(64);
Assert.fail();
} catch(ArrayIndexOutOfBoundsException e){
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
import org.junit.Test;
import org.trie4j.util.FastBitSet;

public class LongsRank1OnlySuccinctBitVectorTest {//extends AbstractSuccinctBitVectorTest{
public class LongsRank1OnlySuccinctBitVectorTest
extends AbstractSuccinctBitVectorTest {
protected SuccinctBitVector create(){
return new LongsRank0OnlySuccinctBitVector();
return new LongsRank1OnlySuccinctBitVector();
}

protected SuccinctBitVector create(int initialCapacity){
return new LongsRank0OnlySuccinctBitVector(initialCapacity);
return new LongsRank1OnlySuccinctBitVector(initialCapacity);
}

protected SuccinctBitVector create(byte[] bytes, int bitsSize){
return new LongsRank0OnlySuccinctBitVector(bytes, bitsSize);
return new LongsRank1OnlySuccinctBitVector(bytes, bitsSize);
}

@Test
Expand All @@ -40,7 +41,7 @@ public void test_1() throws Exception{
bs.set(28);
bs.set(34);
bs.set(67);
LongsRank0OnlySuccinctBitVector bv = new LongsRank0OnlySuccinctBitVector(
SuccinctBitVector bv = new LongsRank1OnlySuccinctBitVector(
bs.getBytes(), bs.size());
Assert.assertEquals(1, bv.rank1(11));
Assert.assertEquals(2, bv.rank1(22));
Expand All @@ -51,7 +52,7 @@ public void test_1() throws Exception{

@Test
public void test_2() throws Exception{
LongsRank0OnlySuccinctBitVector bv = new LongsRank0OnlySuccinctBitVector(
SuccinctBitVector bv = new LongsRank1OnlySuccinctBitVector(
new byte[]{127, -12, -102, -1, -6, 95, -1, -33, -128},
65
);
Expand All @@ -60,7 +61,7 @@ public void test_2() throws Exception{

@Test
public void test_3() throws Exception{
LongsRank0OnlySuccinctBitVector bv = new LongsRank0OnlySuccinctBitVector();
SuccinctBitVector bv = new LongsRank0OnlySuccinctBitVector();
for(int i = 0; i < 9; i++){
bv.append1();
}
Expand Down

0 comments on commit 3db3c90

Please sign in to comment.