Skip to content

Commit dfc584a

Browse files
Add concretize function for interval_sparse_array
1 parent cb10550 commit dfc584a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/solvers/refinement/string_refinement_util.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@ exprt interval_sparse_arrayt::at(const std::size_t index) const
201201
return it != entries.end() ? it->second : default_value;
202202
}
203203

204+
array_exprt interval_sparse_arrayt::concretize(
205+
std::size_t size,
206+
const typet &index_type) const
207+
{
208+
const array_typet array_type(
209+
default_value.type(), from_integer(size, index_type));
210+
array_exprt array(array_type);
211+
212+
std::size_t current_index = 0;
213+
for(const auto &pair : entries)
214+
{
215+
for(; current_index <= pair.first && current_index < size; ++current_index)
216+
array.operands().push_back(pair.second);
217+
}
218+
for(; current_index < size; ++current_index)
219+
array.operands().push_back(default_value);
220+
return array;
221+
}
204222
void equation_symbol_mappingt::add(const std::size_t i, const exprt &expr)
205223
{
206224
equations_containing[expr].push_back(i);

src/solvers/refinement/string_refinement_util.h

+3
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ class interval_sparse_arrayt final : public sparse_arrayt
141141
static optionalt<interval_sparse_arrayt>
142142
of_expr(const exprt &expr, const exprt &extra_value);
143143

144+
/// Convert to an array representation, ignores elements at index >= size
145+
array_exprt concretize(std::size_t size, const typet &index_type) const;
146+
144147
/// Get the value at the specified index.
145148
/// Complexity is linear in the number of entries.
146149
exprt at(std::size_t index) const override;

0 commit comments

Comments
 (0)