Skip to content

nextClearBit returns incorrect values in certain cases #29

Description

@heikitu

We ran in to an issue that was caused by SparseBitSet#nextClearBit returning incorrect values, illustrated by the following JUnit test

    @Test
    public void testNextClearBit() {
	final SparseBitSet set = new SparseBitSet();
        // The last word in the first level3 block covers bits 1984-2047, set those + the last bit from second
        // to last word
        for (int i = 1983; i < 2047; i++) {
            set.set(i);
        }

        // Test nextClearBit from the end of the previous word
        Assert.assertEquals(2047, set.nextClearBit(1983));

        // set the last bit, after this all bits in bits[0][0][31] are set
        set.set(2047);
        Assert.assertEquals(2048, set.nextClearBit(1983));
    }

The above test fails in the last assert with Expected 2048, Actual 2112

The conditions needed for this to happen are

  • Last word in the set is the last word of a level3 block
  • All bits in the last word are set
  • Search for nextClearBit starts from some other word, and there are no clear bits after the start index.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions