billhongs / compressedbitset

Automatically exported from code.google.com/p/compressedbitset
0 stars 0 forks source link

andSize() method fails when both bits sets have large number of contiguous one bits set #8

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
To reproduce this bug, run this simple test case . . . 

import junit.framework.TestCase;

import org.devbrat.util.WAHBitSet;

public class WahBitSetTest extends TestCase {

    public void testIt() {

        int maxSize = 10000;
        int bitsToSet = 100;

        WAHBitSet allOnes = new WAHBitSet();
        for (int i = 0; i < maxSize; i++) {
            allOnes.set(i);
        }

        WAHBitSet partialOnes = new WAHBitSet();
        for (int j = maxSize - bitsToSet; j < maxSize; j++) {
            partialOnes.set(j);
        }

        assertEquals(maxSize - (maxSize - bitsToSet), allOnes.andSize(partialOnes));
    }
}

The expected result of the andSize() call should be 100, but it is 38.  If you 
play around with the numbers, this will start working again when you set the 
bitsToSet variable to 69 (i.e., it breaks at 70, but works fine at 69 and 
lower.)

I realize that this project is mostly dormant, but any thoughts from the author 
or other users would be appreciated.  This is a major bug.

Original issue reported on code.google.com by jasonl...@gmail.com on 24 Jul 2010 at 1:34