Skip to content

Commit f2edbab

Browse files
committed
CHC solver: use hash set instead of linear search
This enables faster than linear lookup of conjuncts of the current invariant hypothesis.
1 parent 56da555 commit f2edbab

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

src/cprover/solver.cpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Author: Daniel Kroening, [email protected]
3535
#include <set>
3636

3737
bool is_subsumed(
38-
const std::vector<exprt> &a1,
39-
const std::vector<exprt> &a2,
38+
const std::unordered_set<exprt, irep_hash> &a1,
39+
const std::unordered_set<exprt, irep_hash> &a2,
4040
const exprt &b,
4141
const std::unordered_set<symbol_exprt, irep_hash> &address_taken,
4242
bool verbose,
@@ -45,13 +45,11 @@ bool is_subsumed(
4545
if(b.is_true())
4646
return true; // anything subsumes 'true'
4747

48-
for(auto &a_conjunct : a1)
49-
if(a_conjunct.is_false())
50-
return true; // 'false' subsumes anything
48+
if(a1.find(false_exprt()) != a1.end())
49+
return true; // 'false' subsumes anything
5150

52-
for(auto &a_conjunct : a1)
53-
if(a_conjunct == b)
54-
return true; // b is subsumed by a conjunct in a
51+
if(a1.find(b) != a1.end())
52+
return true; // b is subsumed by a conjunct in a
5553

5654
cout_message_handlert message_handler;
5755
#if 0
@@ -183,8 +181,8 @@ void solver(
183181
std::cout << "trivial\n";
184182
}
185183
else if(is_subsumed(
186-
f.invariants,
187-
f.auxiliaries,
184+
f.invariants_set,
185+
f.auxiliaries_set,
188186
invariant,
189187
address_taken,
190188
solver_options.verbose,

src/cprover/solver_types.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ void framet::add_invariant(exprt invariant)
2626
add_invariant(conjunct);
2727
}
2828
else
29+
{
30+
invariants_set.insert(invariant);
2931
invariants.push_back(std::move(invariant));
32+
}
3033
}
3134

3235
void framet::add_auxiliary(exprt invariant)
@@ -37,7 +40,10 @@ void framet::add_auxiliary(exprt invariant)
3740
add_auxiliary(conjunct);
3841
}
3942
else
43+
{
44+
auxiliaries_set.insert(invariant);
4045
auxiliaries.push_back(std::move(invariant));
46+
}
4147
}
4248

4349
frame_mapt build_frame_map(const std::vector<framet> &frames)

src/cprover/solver_types.h

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717

1818
#include <chrono>
1919
#include <unordered_map>
20+
#include <unordered_set>
2021

2122
class frame_reft
2223
{
@@ -53,9 +54,11 @@ class framet
5354

5455
// our current hypothesis invariant
5556
std::vector<exprt> invariants;
57+
std::unordered_set<exprt, irep_hash> invariants_set;
5658

5759
// auxiliary facts
5860
std::vector<exprt> auxiliaries;
61+
std::unordered_set<exprt, irep_hash> auxiliaries_set;
5962

6063
// formulas where this frame is on the rhs of ⇒
6164
struct implicationt
@@ -84,7 +87,9 @@ class framet
8487
void reset()
8588
{
8689
invariants.clear();
90+
invariants_set.clear();
8791
auxiliaries.clear();
92+
auxiliaries_set.clear();
8893
}
8994

9095
frame_reft ref;

0 commit comments

Comments
 (0)