Skip to content

Commit d483c81

Browse files
Initialize sparse array from array_exprt
1 parent a914153 commit d483c81

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/solvers/refinement/string_refinement_util.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,24 @@ exprt interval_sparse_arrayt::to_if_expression(const exprt &index) const
140140
});
141141
}
142142

143+
interval_sparse_arrayt::interval_sparse_arrayt(
144+
const array_exprt &expr,
145+
const exprt &extra_value)
146+
: sparse_arrayt(extra_value)
147+
{
148+
const auto &operands = expr.operands();
149+
exprt last_added = extra_value;
150+
for(std::size_t i = 0; i < operands.size(); ++i)
151+
{
152+
const std::size_t index = operands.size() - 1 - i;
153+
if(operands[index].id() != ID_unknown && operands[index] != last_added)
154+
{
155+
entries[index] = operands[index];
156+
last_added = operands[index];
157+
}
158+
}
159+
}
160+
143161
void equation_symbol_mappingt::add(const std::size_t i, const exprt &expr)
144162
{
145163
equations_containing[expr].push_back(i);

src/solvers/refinement/string_refinement_util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ class interval_sparse_arrayt final : public sparse_arrayt
119119
{
120120
}
121121

122+
/// Initialize an array expression to sparse array representation, avoiding
123+
/// repetition of identical successive values and setting the default to
124+
/// `extra_value`.
125+
interval_sparse_arrayt(const array_exprt &expr, const exprt &extra_value);
126+
122127
exprt to_if_expression(const exprt &index) const override;
123128
};
124129

0 commit comments

Comments
 (0)