41 static_assert(std::is_constructible_v<V>);
44 static_assert(std::is_trivially_constructible_v<V>);
45 static_assert(std::is_trivially_destructible_v<V>);
49 if constexpr (std::is_same_v<K, pkgCache::Version>)
50 size = cache.Head().VersionCount;
51 else if constexpr (std::is_same_v<K, pkgCache::Package>)
52 size = cache.Head().PackageCount;
56 data_ =
new V[size]{};
58 V &operator[](
const K *key) {
return data_[key->ID]; }
59 const V &operator[](
const K *key)
const {
return data_[key->ID]; }
81 enum class Decision : uint16_t;
82 enum class Hint : uint16_t;
95 enum class Group : uint8_t
134 using depth_type =
unsigned int;
137 template <
typename T>
138 using heap = std::vector<T>;
140 static_assert(
sizeof(depth_type) >=
sizeof(map_id_t));
147 std::unique_ptr<State> rootState;
174 inline const State &operator[](
Var r)
const;
179 bool Obsolete(pkgCache::PkgIterator pkg,
bool AllowManual=
false)
const;
180 bool ObsoletedByNewerSourceVersion(pkgCache::VerIterator cand)
const;
183 short GetPriority(pkgCache::VerIterator ver)
const
185 if (priorities[ver] == 0)
186 priorities[ver] = policy.GetPriority(ver);
187 return priorities[ver];
191 pkgCache::VerIterator GetCandidateVer(pkgCache::PkgIterator pkg)
const
193 if (candidates[pkg].end())
194 candidates[pkg] = policy.GetCandidateVer(pkg);
195 return candidates[pkg];
212 std::vector<Solved> solved{};
215 std::queue<Var> propQ;
217 std::queue<Var> discoverQ;
222 std::vector<depth_type> choices{};
229 std::string version{_config->Find(
"APT::Solver",
"3.0")};
231 int debug{_config->FindI(
"Debug::APT::Solver")};
233 bool KeepAuto{version ==
"3.0" || not _config->FindB(
"APT::Get::AutomaticRemove")};
235 bool IsUpgrade{_config->FindB(
"APT::Solver::Upgrade", requestFlags &EDSP::Request::UPGRADE_ALL)};
237 bool AllowRemove{_config->FindB(
"APT::Solver::Remove", not(requestFlags & EDSP::Request::FORBID_REMOVE))};
239 bool AllowRemoveManual{AllowRemove && _config->FindB(
"APT::Solver::RemoveManual",
false)};
241 bool AllowInstall{_config->FindB(
"APT::Solver::Install", not(requestFlags & EDSP::Request::FORBID_NEW_INSTALL))};
243 bool StrictPinning{_config->FindB(
"APT::Solver::Strict-Pinning",
true)};
245 bool FixPolicyBroken{_config->FindB(
"APT::Get::Fix-Policy-Broken")};
247 bool DeferVersionSelection{_config->FindB(
"APT::Solver::Defer-Version-Selection",
true)};
249 int Timeout{_config->FindI(
"APT::Solver::Timeout", 10)};
252 bool KeepRecommends{_config->FindB(
"APT::AutoRemove::RecommendsImportant",
true)};
254 bool KeepSuggests{_config->FindB(
"APT::AutoRemove::SuggestsImportant",
true)};
260 void Discover(
Var var);
264 void RegisterCommonDependencies(pkgCache::PkgIterator Pkg);
267 [[nodiscard]]
Clause TranslateOrGroup(pkgCache::DepIterator start, pkgCache::DepIterator end,
Var reason);
269 [[nodiscard]]
bool Propagate();
274 return static_cast<depth_type
>(choices.size());
276 inline Var bestReason(
Clause const *clause,
Var var)
const;
280 void Push(
Work work);
282 [[nodiscard]]
bool Pop();
286 [[nodiscard]]
bool AddWork(
Work &&work);
292 [[nodiscard]]
bool Assume(
Var var,
bool decision,
const Clause *reason =
nullptr);
294 [[nodiscard]]
bool Enqueue(
Var var,
bool decision,
const Clause *reason =
nullptr);
297 [[nodiscard]]
bool FromDepCache(
pkgDepCache &depcache);
299 [[nodiscard]]
bool ToDepCache(
pkgDepCache &depcache)
const;
302 [[nodiscard]]
bool Solve();
305 std::string WhyStr(
Var reason)
const;
318 std::string
LongWhyStr(
Var var,
bool decision,
const Clause *rclause, std::string prefix, std::unordered_set<Var> &seen)
const;
335 explicit constexpr Var(uint32_t value = 0) : value{value} {}
336 explicit Var(pkgCache::PkgIterator
const &Pkg) : value(uint32_t(Pkg.MapPointer()) << 1) {}
337 explicit Var(pkgCache::VerIterator
const &Ver) : value(uint32_t(Ver.MapPointer()) << 1 | 1) {}
339 inline constexpr bool isVersion()
const {
return value & 1; }
340 inline constexpr uint32_t mapPtr()
const {
return value >> 1; }
353 pkgCache::PkgIterator Pkg(
pkgCache &cache)
const
355 return isVersion() ? pkgCache::PkgIterator() : pkgCache::PkgIterator(cache, cache.PkgP + Pkg());
358 pkgCache::VerIterator Ver(
pkgCache &cache)
const
360 return isVersion() ? pkgCache::VerIterator(cache, cache.VerP + Ver()) : pkgCache::VerIterator();
363 pkgCache::PkgIterator CastPkg(
pkgCache &cache)
const
365 return isVersion() ? Ver(cache).ParentPkg() : Pkg(cache);
368 constexpr bool empty()
const {
return value == 0; }
369 constexpr bool operator!=(
Var const other)
const {
return value != other.value; }
370 constexpr bool operator==(
Var const other)
const {
return value == other.value; }
372 std::string toString(
pkgCache &cache)
const
374 if (
auto P = Pkg(cache); not P.end())
376 if (
auto V = Ver(cache); not V.end())
377 return V.ParentPkg().FullName() +
"=" + V.VerStr();
std::string LongWhyStr(Var var, bool decision, const Clause *rclause, std::string prefix, std::unordered_set< Var > &seen) const
Print a long reason string.
Definition solver3.cc:320