CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
union_find_replace.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: util
4
5Author: Romain Brenguier, romain.brenguier@diffblue.com
6
7\*******************************************************************/
8
10
16{
17 const exprt &lhs_root = find(a);
18 const exprt &rhs_root = find(b);
19 if(lhs_root != rhs_root)
21 return rhs_root;
22}
23
29{
30 bool unchanged = ::replace_expr(map, expr);
31 while(!unchanged && !::replace_expr(map, expr))
32 continue;
33 return unchanged;
34}
35
39{
40 replace_expr(expr);
41 return expr;
42}
43
46std::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}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
Base class for all expressions.
Definition expr.h:56
exprt find(exprt expr) const
std::vector< std::pair< exprt, exprt > > to_vector() const
exprt make_union(const exprt &a, const exprt &b)
Merge the set containing a and the set containing b.
bool replace_expr(exprt &expr) const
Replace subexpressions of expr by the representative element of the set they belong to.