Skip to content

Commit 8c3b036

Browse files
committed
(interval_)sparse_arrayt: Remove unnecessary use of "virtual" and further cleanup
1 parent c749b8f commit 8c3b036

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

src/solvers/refinement/string_refinement.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ static exprt substitute_array_access(
10831083
const bool left_propagate)
10841084
{
10851085
return left_propagate ? interval_sparse_arrayt(expr).to_if_expression(index)
1086-
: sparse_arrayt(expr).to_if_expression(index);
1086+
: sparse_arrayt::to_if_expression(expr, index);
10871087
}
10881088

10891089
/// 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)

0 commit comments

Comments
 (0)