The API doesn't allow to apply logical operations to dynamic_bitsets of different size, while my application requires that if one of the bitsets is larger than the other, the result size is adjusted accordingly. I have to create a temporary copy to work the problem around:
using column_mask = boost::dynamic_bitset<uint64_t>;
void column_mask_union(column_mask& to, const column_mask& with) {
if (to.size() > with.size()) {
if (with.size()) {
column_mask tmp = with;
tmp.resize(to.size());
to |= tmp;
}
return;
}
if (to.size() < with.size()) {
to.resize(with.size());
}
to |= with;
}
I can see in the API there are functions to_block_range() and from_block_range() which could in theory be used to access the bitset, but they seem to be too limited to implement a logical OR of differently sized bitsets.
If you think about it, you can’t create a view at an arbitrary offset inside a bitset without some penalty, since if it doesn’t align to a byte boundary, every operation would need to shift all bits first, such that they properly align with the bits in the other operand.
Do you use this for reasons of performance, memory or because you (only) need the binary operations?
Because if it isn’t utterly performance critical, i suggest you use this instead and call it a day:
Alternatively you can overcommit all your sets to have the same size.
I don’t think
boost::dynamic_bitsetsupports only using existing memory. Maybe there is some other library that allows this.