3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-15 05:18:44 +00:00

DoC: fix slow path of filter_by_negation when columns are repeated in tgt relation

Signed-off-by: Nuno Lopes <a-nlopes@microsoft.com>
This commit is contained in:
Nuno Lopes 2014-10-02 09:56:06 +01:00
parent bb15ddbf15
commit 9828b26379
3 changed files with 53 additions and 8 deletions

View file

@ -661,7 +661,7 @@ namespace datalog {
expr_ref_vector eqs(m);
dst.to_formula(dstf);
std::cout << mk_pp(dstf, m) << "\n";
dst.to_formula(negf);
neg.to_formula(negf);
std::cout << mk_pp(negf, m) << "\n";
eqs.push_back(negf);
for (unsigned i = 0; i < cols1.size(); ++i) {

View file

@ -1110,11 +1110,16 @@ namespace datalog {
for (unsigned i = 0; i < neg.size(); ++i) {
doc& neg_i = neg[i];
doc_ref newD(dmt, dmt.allocateX());
copy_columns(newD->pos(), neg_i.pos(), t, n);
if (!copy_columns(newD->pos(), neg_i.pos(), t, n))
continue;
bool is_empty = false;
for (unsigned j = 0; !is_empty && j < neg_i.neg().size(); ++j) {
tbv_ref newT(dmt.tbvm(), dmt.tbvm().allocateX());
copy_columns(*newT, neg_i.neg()[j], t, n);
if (!copy_columns(*newT, neg_i.neg()[j], t, n) ||
!dmt.tbvm().set_and(*newT, newD->pos())) {
continue;
}
if (dmt.tbvm().equals(newD->pos(), *newT)) {
is_empty = true;
}
@ -1139,17 +1144,19 @@ namespace datalog {
renamed_neg.reset(dmt);
IF_VERBOSE(3, tb.display(verbose_stream() << "slow case:"););
}
void copy_columns(
bool copy_columns(
tbv& dst, tbv const& src,
udoc_relation const& dstt,
udoc_relation const& srct)
{
unsigned num_cols = m_t_cols.size();
for (unsigned i = 0; i < num_cols; ++i) {
copy_column(dst, src, m_t_cols[i], m_neg_cols[i], dstt, srct);
if (!copy_column(dst, src, m_t_cols[i], m_neg_cols[i], dstt, srct))
return false;
}
return true;
}
void copy_column(
bool copy_column(
tbv& dst, tbv const& src,
unsigned col_dst, unsigned col_src,
udoc_relation const& dstt,
@ -1162,8 +1169,12 @@ namespace datalog {
IF_VERBOSE(3, verbose_stream() << "copy column " << idx_src
<< " to " << idx_dst << " " << num_tbits << "\n";);
for (unsigned i = 0; i < num_tbits; ++i) {
dm.set(dst, idx_dst + i, src[idx_src + i]);
}
tbit bit = (tbit)(dst[idx_dst + i] & src[idx_src + i]);
if (bit == BIT_z)
return false;
dm.set(dst, idx_dst + i, bit);
}
return true;
}
};

View file

@ -149,6 +149,7 @@ public:
test_rename();
test_filter_neg();
test_filter_neg2();
test_filter_neg3();
// empty
@ -601,6 +602,39 @@ public:
t2->deallocate();
}
void test_filter_neg3() {
// filter_by_negation
relation_signature sig;
sig.push_back(bv.mk_sort(1));
sig.push_back(bv.mk_sort(1));
sig.push_back(bv.mk_sort(1));
unsigned_vector cols1, cols2;
cols1.push_back(0);
cols1.push_back(0);
cols2.push_back(0);
cols2.push_back(1);
/// 1xx
udoc_relation* t1 = mk_full(sig);
{
doc& d = t1->get_udoc()[0];
t1->get_dm().set(d, 0, BIT_1);
}
/// 10x
udoc_relation* t2 = mk_full(sig);
{
doc& d = t2->get_udoc()[0];
t1->get_dm().set(d, 0, BIT_1);
t1->get_dm().set(d, 1, BIT_0);
}
apply_filter_neg(*t1, *t2, cols1, cols2);
t1->deallocate();
t2->deallocate();
}
void set_random(udoc_relation& r, unsigned num_vals) {
unsigned num_bits = r.get_dm().num_tbits();
udoc_relation* full = mk_full(r.get_signature());