Skip to content

Bug in bvector::flip()? #73

@fanejonda

Description

@fanejonda

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.

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