Skip to content

Commit

Permalink
fixed bug in bitset operations
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Apr 20, 2024
1 parent bb1e95e commit 8673dc2
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions include/flatmemory/details/types/bitset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,9 +943,13 @@ class Builder<Bitset<Block>> : public IBuilder<Builder<Bitset<Block>>>

// Update blocks
resize_to_fit(other);
// Other blocks might still be smaller which is fine
assert(other_blocks.size() <= m_blocks.size());

auto it = m_blocks.begin();
auto other_it = other_blocks.begin();
while (it != m_blocks.end())
// Since other is potentially smaller, it acts as termination conditions
while (other_it != other_blocks.end())
{
*it |= *other_it;
++it;
Expand All @@ -967,14 +971,19 @@ class Builder<Bitset<Block>> : public IBuilder<Builder<Bitset<Block>>>

// Update blocks
resize_to_fit(other);
// Other blocks might still be smaller which is fine
assert(other_blocks.size() <= m_blocks.size());

auto it = m_blocks.begin();
auto other_it = other_blocks.begin();
while (it != m_blocks.end())
while (other_it != other_blocks.end())
{
*it &= *other_it;
++it;
++other_it;
}
// Shrink to size of other since those bits should become default valued
m_blocks.resize(other_blocks.size());

return *this;
}
Expand All @@ -991,14 +1000,18 @@ class Builder<Bitset<Block>> : public IBuilder<Builder<Bitset<Block>>>

// Update blocks
resize_to_fit(other);
// Other blocks might still be smaller which is fine
assert(other_blocks.size() <= m_blocks.size());

auto it = m_blocks.begin();
auto other_it = other_blocks.begin();
while (it != m_blocks.end())
while (other_it != other_blocks.end())
{
*it &= ~(*other_it);
++it;
++other_it;
}
// The remaining blocks stay the same.

return *this;
}
Expand Down

0 comments on commit 8673dc2

Please sign in to comment.