Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in bvector::flip()? #73

Open
fanejonda opened this issue Oct 19, 2023 · 1 comment
Open

Bug in bvector::flip()? #73

fanejonda opened this issue Oct 19, 2023 · 1 comment

Comments

@fanejonda
Copy link

Hi,

It appears that there is a bug in the implementation of the flip function (full vector flip). The flipping seems to assume that there is a large tail of zeroes at the end of every bvector and flipping causes that implicit tail to become real.

To reproduce:

#include <iostream>
#include "bm.h"

int main() {
  bm::bvector<> bv;
  bv.set_range(10, 11);
  std::cout << "Count pre flip=" << bv.count() << std::endl;
  bv.flip();
  std::cout << "Count post flip=" << bv.count() << std::endl;
}

The output

Count pre flip=2
Count post flip=4294967293

I would have expected that a flipping operation would not change the size of the vector and the post flip count to be 9.

This also affects other APIs, because the rest of the code now believes there is a big set of 1s at the end of the vector.

@tlk00
Copy link
Owner

tlk00 commented Nov 20, 2023

It is indeed the case, bvector<> is actually size-less and technically it contains a whole tail of zeroes at the end.
It is possible to use keep_range() to clip the vector.
I guess the API really needs flip_range() method...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants