CBMC
union_find_replace.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: util
4
5
Author: Romain Brenguier, romain.brenguier@diffblue.com
6
7
\*******************************************************************/
8
9
#include "
union_find_replace.h
"
10
15
exprt
union_find_replacet::make_union
(
const
exprt
&a,
const
exprt
&b)
16
{
17
const
exprt
&lhs_root =
find
(a);
18
const
exprt
&rhs_root =
find
(b);
19
if
(lhs_root != rhs_root)
20
map
[lhs_root] = rhs_root;
21
return
rhs_root;
22
}
23
28
bool
union_find_replacet::replace_expr
(
exprt
&expr)
const
29
{
30
bool
unchanged =
::replace_expr
(
map
, expr);
31
while
(!unchanged && !::
replace_expr
(
map
, expr))
32
continue
;
33
return
unchanged;
34
}
35
38
exprt
union_find_replacet::find
(
exprt
expr)
const
39
{
40
replace_expr
(expr);
41
return
expr;
42
}
43
46
std::vector<std::pair<exprt, exprt>>
union_find_replacet::to_vector
()
const
47
{
48
std::vector<std::pair<exprt, exprt>> equations;
49
for
(
const
auto
&pair :
map
)
50
equations.emplace_back(pair.first,
find
(pair.second));
51
return
equations;
52
}
union_find_replacet::to_vector
std::vector< std::pair< exprt, exprt > > to_vector() const
Definition:
union_find_replace.cpp:46
union_find_replace.h
union_find_replacet::replace_expr
bool replace_expr(exprt &expr) const
Replace subexpressions of expr by the representative element of the set they belong to.
Definition:
union_find_replace.cpp:28
exprt
Base class for all expressions.
Definition:
expr.h:55
union_find_replacet::map
replace_mapt map
Definition:
union_find_replace.h:28
union_find_replacet::make_union
exprt make_union(const exprt &a, const exprt &b)
Merge the set containing a and the set containing b.
Definition:
union_find_replace.cpp:15
union_find_replacet::find
exprt find(exprt expr) const
Definition:
union_find_replace.cpp:38
src
util
union_find_replace.cpp
Generated by
1.8.17