Skip to content

Rank returns wrong results #1

Open

Description

@rob-p

Hi,

I've been looking at some different rank and select implementations, and during testing I've noticed that the current implementation here returns incorrect results for the rank operation (compared to Vinga's rank9b --- which I verified to be correct). Is this a known issue? I haven't dug into the code to determine exactly why the bug is happening, but it seems to happen in both large and small-scale bit vectors, so it might even be related to the popcountLinear implementation.

Activity

  1. dave-andersen commented on Apr 26, 2017

    @dave-andersen
    Member

    Hi, Rob - we don't have any known issues. Could you help provide a test case we can use to reproduce this? Thanks!

  2. rob-p commented on Apr 26, 2017

    @rob-p
    Author

    Hi Dave,

    Thanks for the reply! I've been looking into this, and the issue seems to derive from how the underlying bit-array is stored. Specifically, the assumed order of the bytes within each word. I'm using this bit array library, and the native storage is directly compatible with Vinga's implementation. However, to get efficient/rankselect to return the correct results, I have to reverse the bytes of each word (e.g. via repeated calls to the bit_array_reverse_region() function on word-sized chunks of the bit array). Thus, I'm thinking that this is not a bug in rankselect, but rather a difference in the assumed endian-ness of the underlying word-packed representation of the bitvector. I think I was just taken by surprise that passing exactly the same memory to the Vinga rank9b implementation and rankselect resulted in completely different behavior. In case you're interested, the code I was testing with is here --- though, the tests should now work with the re-arrangement of the bit array for rankselect.

    Please let me know if I'm mistaken about my interpretation here. Otherwise, please feel free to close this issue! Of course, I think a brief mention about the assumed memory layout of the bitvector somewhere in the readme might help future users of rankselect avoid the confusions I had ;).

    Best,
    Rob

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions