Skip to content

Commit 86d057d

Browse files
committed
(interval_)sparse_arrayt: Remove unnecessary use of "virtual" and further cleanup
1 parent 0d7a943 commit 86d057d

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

src/solvers/refinement/string_refinement.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ static exprt substitute_array_access(
10671067
const bool left_propagate)
10681068
{
10691069
return left_propagate ? interval_sparse_arrayt(expr).to_if_expression(index)
1070-
: sparse_arrayt(expr).to_if_expression(index);
1070+
: sparse_arrayt::to_if_expression(expr, index);
10711071
}
10721072

10731073
/// Create an equivalent expression where array accesses are replaced by 'if'

src/solvers/refinement/string_refinement_util.cpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,16 @@ sparse_arrayt::sparse_arrayt(const with_exprt &expr)
7373
default_value = expr_dynamic_cast<array_of_exprt>(ref.get()).what();
7474
}
7575

76-
exprt sparse_arrayt::to_if_expression(const exprt &index) const
76+
exprt sparse_arrayt::to_if_expression(
77+
const with_exprt &expr,
78+
const exprt &index)
7779
{
80+
sparse_arrayt sparse_array(expr);
81+
7882
return std::accumulate(
79-
entries.begin(),
80-
entries.end(),
81-
default_value,
83+
sparse_array.entries.begin(),
84+
sparse_array.entries.end(),
85+
sparse_array.default_value,
8286
[&](
8387
const exprt if_expr,
8488
const std::pair<std::size_t, exprt> &entry) { // NOLINT
@@ -90,12 +94,6 @@ exprt sparse_arrayt::to_if_expression(const exprt &index) const
9094
});
9195
}
9296

93-
exprt sparse_arrayt::at(const std::size_t index) const
94-
{
95-
const auto it = entries.find(index);
96-
return it != entries.end() ? it->second : default_value;
97-
}
98-
9997
exprt interval_sparse_arrayt::to_if_expression(const exprt &index) const
10098
{
10199
return std::accumulate(

src/solvers/refinement/string_refinement_util.h

+4-8
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ class sparse_arrayt
7373

7474
/// Creates an if_expr corresponding to the result of accessing the array
7575
/// at the given index
76-
virtual exprt to_if_expression(const exprt &index) const;
77-
78-
/// Get the value at the specified index.
79-
/// Complexity is linear in the number of entries.
80-
virtual exprt at(std::size_t index) const;
76+
static exprt to_if_expression(const with_exprt &expr, const exprt &index);
8177

8278
protected:
8379
exprt default_value;
@@ -114,7 +110,7 @@ class interval_sparse_arrayt final : public sparse_arrayt
114110
const array_list_exprt &expr,
115111
const exprt &extra_value);
116112

117-
exprt to_if_expression(const exprt &index) const override;
113+
exprt to_if_expression(const exprt &index) const;
118114

119115
/// If the expression is an array_exprt or a with_exprt uses the appropriate
120116
/// constructor, otherwise returns empty optional.
@@ -125,8 +121,8 @@ class interval_sparse_arrayt final : public sparse_arrayt
125121
array_exprt concretize(std::size_t size, const typet &index_type) const;
126122

127123
/// Get the value at the specified index.
128-
/// Complexity is linear in the number of entries.
129-
exprt at(std::size_t index) const override;
124+
/// Complexity is logarithmic in the number of entries.
125+
exprt at(std::size_t index) const;
130126

131127
/// Array containing the same value at each index.
132128
explicit interval_sparse_arrayt(exprt default_value)

unit/solvers/refinement/string_refinement/sparse_array.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ SCENARIO("sparse_array", "[core][solvers][refinement][string_refinement]")
4545

4646
WHEN("It is converted to a sparse array")
4747
{
48-
const sparse_arrayt sparse_array(input_expr);
4948
THEN("The resulting if expression is index=100?z:index=4?x:index=1?y:0")
5049
{
5150
const symbol_exprt index("index", int_type);
@@ -57,7 +56,7 @@ SCENARIO("sparse_array", "[core][solvers][refinement][string_refinement]")
5756
charx,
5857
if_exprt(
5958
equal_exprt(index, index1), chary, from_integer(0, char_type))));
60-
REQUIRE(sparse_array.to_if_expression(index) == expected);
59+
REQUIRE(sparse_arrayt::to_if_expression(input_expr, index) == expected);
6160
}
6261
}
6362

0 commit comments

Comments
 (0)