From 762d12f0ac9dd10325cae09816e5e918b7e5b039 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 4 Feb 2025 10:18:32 +0100 Subject: solver3: Extract Clause out of Work Extract clause into a separate struct and embed a copy of it in our Work class. --- apt-pkg/solver3.h | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'apt-pkg/solver3.h') diff --git a/apt-pkg/solver3.h b/apt-pkg/solver3.h index 2e5c5ca13..bf8647921 100644 --- a/apt-pkg/solver3.h +++ b/apt-pkg/solver3.h @@ -37,6 +37,7 @@ class Solver struct Var; struct CompareProviders3; struct State; + struct Clause; struct Work; struct Solved; @@ -289,6 +290,29 @@ struct APT::Solver::Var } }; +/** + * \brief A single clause + * + * A clause is a normalized, expanded dependency, translated into an implication + * in terms of Var objects, that is, `reason -> solutions[0] | ... | solutions[n]` + */ +struct APT::Solver::Clause +{ + // \brief Var for the work + Var reason; + // \brief The group we are in + Group group; + // \brief Possible solutions to this task, ordered in order of preference. + std::vector solutions{}; + // \brief An optional clause does not need to be satisfied + bool optional; + + inline Clause(Var reason, Group group, bool optional = false) : reason(reason), group(group), optional(optional) {} + + // \brief Dump the clause to std::cerr + void Dump(pkgCache &cache); +}; + /** * \brief A single work item * @@ -301,14 +325,10 @@ struct APT::Solver::Var */ struct APT::Solver::Work { - // \brief Var for the work - Var reason; + Clause clause; + // \brief The depth at which the item has been added depth_type depth; - // \brief The group we are in - Group group; - // \brief Possible solutions to this task, ordered in order of preference. - std::vector solutions{}; // This is a union because we only need to store the choice we made when adding // to the choice vector, and we don't need the size of valid choices in there. @@ -317,19 +337,16 @@ struct APT::Solver::Work // The choice we took Var choice; // Number of valid choices - size_t size; + size_t size{0}; }; - // \brief Whether this is an optional work item, they will be processed last - bool optional; // \brief This item should be removed from the queue. - bool erased; + bool erased{false}; bool operator<(APT::Solver::Work const &b) const; // \brief Dump the work item to std::cerr void Dump(pkgCache &cache); - - inline Work(Var reason, depth_type depth, Group group, bool optional = false) : reason(reason), depth(depth), group(group), size(0), optional(optional), erased(false) {} + inline Work(Clause clause, depth_type depth) : clause(std::move(clause)), depth(depth) {} }; // \brief This essentially describes the install state in RFC2119 terms. -- cgit v1.2.3-70-g09d2