mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use enumerate.
This commit is contained in:
parent
f163f9b7ce
commit
72ae0f6a1a
@ -489,7 +489,7 @@ optional<LinearExpression> BooleanLPSolver::parseFactor(smtutil::Expression cons
|
||||
|
||||
bool BooleanLPSolver::tryAddDirectBounds(Constraint const& _constraint)
|
||||
{
|
||||
auto nonzero = _constraint.data | ranges::views::enumerate | ranges::views::tail | ranges::views::filter(
|
||||
auto nonzero = _constraint.data.enumerateTail() | ranges::views::filter(
|
||||
[](std::pair<size_t, rational> const& _x) { return !!_x.second; }
|
||||
);
|
||||
// TODO we can exit early on in the loop above.
|
||||
@ -650,7 +650,7 @@ string BooleanLPSolver::toString(Clause const& _clause) const
|
||||
string BooleanLPSolver::toString(Constraint const& _constraint) const
|
||||
{
|
||||
vector<string> line;
|
||||
for (auto&& [index, multiplier]: _constraint.data | ranges::views::enumerate)
|
||||
for (auto&& [index, multiplier]: _constraint.data.enumerate())
|
||||
if (index > 0 && multiplier != 0)
|
||||
{
|
||||
string mult =
|
||||
|
@ -148,7 +148,7 @@ pair<vector<LinearExpression>, bool> toEquationalForm(vector<Constraint> _constr
|
||||
optional<size_t> findPivotColumn(Tableau const& _tableau)
|
||||
{
|
||||
auto&& [maxColumn, maxValue] = ranges::max(
|
||||
_tableau.objective | ranges::views::enumerate | ranges::views::tail,
|
||||
_tableau.objective.enumerateTail(),
|
||||
{},
|
||||
[](std::pair<size_t, rational> const& _x) { return _x.second; }
|
||||
);
|
||||
@ -468,7 +468,7 @@ pair<vector<bool>, vector<bool>> connectedComponent(SolvingState const& _state,
|
||||
if (includedRows[row])
|
||||
continue;
|
||||
includedRows[row] = true;
|
||||
for (auto const& [index, entry]: _state.constraints[row].data | ranges::views::enumerate | ranges::views::tail)
|
||||
for (auto const& [index, entry]: _state.constraints[row].data.enumerateTail())
|
||||
if (entry && !seenColumns[index])
|
||||
{
|
||||
seenColumns[index] = true;
|
||||
@ -536,7 +536,7 @@ string SolvingState::toString() const
|
||||
for (Constraint const& constraint: constraints)
|
||||
{
|
||||
vector<string> line;
|
||||
for (auto&& [index, multiplier]: constraint.data | ranges::views::enumerate)
|
||||
for (auto&& [index, multiplier]: constraint.data.enumerate())
|
||||
if (index > 0 && multiplier != 0)
|
||||
{
|
||||
string mult =
|
||||
@ -631,7 +631,7 @@ optional<ReasonSet> SolvingStateSimplifier::extractDirectConstraints()
|
||||
bool needsRemoval = false;
|
||||
for (auto const& [index, constraint]: m_state.constraints | ranges::views::enumerate)
|
||||
{
|
||||
auto nonzeroCoefficients = constraint.data | ranges::views::enumerate | ranges::views::tail | ranges::views::filter(
|
||||
auto nonzeroCoefficients = constraint.data.enumerateTail() | ranges::views::filter(
|
||||
[](std::pair<size_t, rational> const& _x) { return !!_x.second; }
|
||||
);
|
||||
// TODO we can exit early on in the loop above since we only care about zero, one or more than one nonzero entries.
|
||||
@ -687,7 +687,7 @@ void SolvingStateSimplifier::removeEmptyColumns()
|
||||
vector<bool> variablesSeen(m_state.bounds.size(), false);
|
||||
for (auto const& constraint: m_state.constraints)
|
||||
{
|
||||
for (auto&& [index, factor]: constraint.data | ranges::views::enumerate | ranges::views::tail)
|
||||
for (auto&& [index, factor]: constraint.data.enumerateTail())
|
||||
if (factor)
|
||||
variablesSeen[index] = true;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <boost/rational.hpp>
|
||||
|
||||
#include <range/v3/view/tail.hpp>
|
||||
#include <range/v3/view/enumerate.hpp>
|
||||
#include <range/v3/algorithm/all_of.hpp>
|
||||
|
||||
#include <optional>
|
||||
@ -79,11 +80,9 @@ public:
|
||||
return factors[_index];
|
||||
}
|
||||
|
||||
auto begin() { return factors.begin(); }
|
||||
auto end() { return factors.end(); }
|
||||
|
||||
auto begin() const { return factors.begin(); }
|
||||
auto end() const { return factors.end(); }
|
||||
auto enumerate() const { return factors | ranges::view::enumerate; }
|
||||
// leave out the zero if exists
|
||||
auto enumerateTail() const { return factors | ranges::view::enumerate | ranges::view::tail; }
|
||||
|
||||
rational const& front() const { return factors.front(); }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user