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;
|
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
|
bool operator==(const bitvect& other) const
|
||||||
{
|
{
|
||||||
if (other.size_ != size_)
|
if (other.size_ != size_)
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,9 @@ int main()
|
||||||
*x |= *w;
|
*x |= *w;
|
||||||
ECHO(x);
|
ECHO(x);
|
||||||
|
|
||||||
|
std::cout << "subset? " << w->is_subset_of(*x)
|
||||||
|
<< ' ' << w->is_subset_of(*v) << '\n';
|
||||||
|
|
||||||
for (size_t i = 0; i < 30; ++i)
|
for (size_t i = 0; i < 30; ++i)
|
||||||
w->push_back((i & 3) == 0);
|
w->push_back((i & 3) == 0);
|
||||||
ECHO(w);
|
ECHO(w);
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ w: 000000000010110000000000000000100000000001
|
||||||
|
|
||||||
x: 000000000000000000000000000000000000000000000000000000000000100000000010000
|
x: 000000000000000000000000000000000000000000000000000000000000100000000010000
|
||||||
x: 000000000010110000000000000000100000000001000000000000000000100000000010000
|
x: 000000000010110000000000000000100000000001000000000000000000100000000010000
|
||||||
|
subset? 1 0
|
||||||
w: 000000000010110000000000000000100000000001100010001000100010001000100010
|
w: 000000000010110000000000000000100000000001100010001000100010001000100010
|
||||||
x: 000000000010110000000000000000100000000001000000000000000000000000000010000
|
x: 000000000010110000000000000000100000000001000000000000000000000000000010000
|
||||||
x: 111111111111111111111111111111111111111111111111111111111111111111111111111
|
x: 111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue