bitvect: add a is_subset_of method.
* src/misc/bitvect.hh: New method. * src/tgbatest/bitvect.cc, src/tgbatest/bitvect.test: Test it.
This commit is contained in:
parent
90a43db5a4
commit
9a097bb02e
3 changed files with 21 additions and 0 deletions
|
|
@ -298,6 +298,23 @@ namespace spot
|
|||
return *this;
|
||||
}
|
||||
|
||||
bool is_subset_of(const bitvect& other) const
|
||||
{
|
||||
assert(other.block_count_ >= block_count_);
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < block_count_ - 1; ++i)
|
||||
if ((storage_[i] & other.storage_[i]) != other.storage_[i])
|
||||
return false;
|
||||
|
||||
// The last block might not be fully used, compare only the
|
||||
// relevant portion.
|
||||
const size_t bpb = 8 * sizeof(bitvect::block_t);
|
||||
block_t mask = (1UL << (size() % bpb)) - 1;
|
||||
return ((storage_[i] & mask & other.storage_[i])
|
||||
== (other.storage_[i] & mask));
|
||||
}
|
||||
|
||||
bool operator==(const bitvect& other) const
|
||||
{
|
||||
if (other.size_ != size_)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue