Skip to content

Commit 3bef331

Browse files
Eh2406konstin
andauthored
when priorities are equal do breadth first search (#299)
* when priorities are equal do breadth first search * Lints and docs --------- Co-authored-by: konstin <konstin@mailbox.org>
1 parent d49bf5f commit 3bef331

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/internal/partial_solution.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! A Memory acts like a structured partial solution
44
//! where terms are regrouped by package in a [Map](crate::type_aliases::Map).
55
6+
use std::cmp::Reverse;
67
use std::fmt::{Debug, Display};
78
use std::hash::BuildHasherDefault;
89

@@ -66,8 +67,12 @@ pub(crate) struct PartialSolution<DP: DependencyProvider> {
6667
/// The undecided packages order by their `Priority`.
6768
///
6869
/// The max heap allows quickly `pop`ing the highest priority package.
70+
///
71+
/// The `Reverse<u32>` is the discovery order of packages used as tiebreaker. Its order is that
72+
/// of a breadth-first search.
73+
#[allow(clippy::type_complexity)]
6974
prioritized_potential_packages:
70-
PriorityQueue<Id<DP::P>, DP::Priority, BuildHasherDefault<FxHasher>>,
75+
PriorityQueue<Id<DP::P>, (DP::Priority, Reverse<u32>), BuildHasherDefault<FxHasher>>,
7176
/// Whether we have never backtracked, to enable fast path optimizations.
7277
has_ever_backtracked: bool,
7378
}
@@ -330,7 +335,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
330335
.filter_map(|(&p, pa)| pa.assignments_intersection.potential_package_filter(p))
331336
.for_each(|(p, r)| {
332337
let priority = prioritizer(p, r);
333-
prioritized_potential_packages.push(p, priority);
338+
prioritized_potential_packages.push(p, (priority, Reverse(p.into_raw() as u32)));
334339
});
335340
self.prioritize_decision_level = self.package_assignments.len();
336341
prioritized_potential_packages.pop().map(|(p, _)| p)

src/solver.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ pub trait DependencyProvider {
323323
/// > since these packages will run out of versions to try more quickly.
324324
/// > But there's likely room for improvement in these heuristics.
325325
///
326+
/// The `package_conflicts_counts` argument provides access to some other heuristics that
327+
/// are production users have found useful. Although the exact meaning/efficacy of those arguments may change.
328+
///
329+
/// If two packages have the same priority, PubGrub will biased toward a breadth first search.
330+
///
326331
/// Note: the resolver may call this even when the range has not changed,
327332
/// if it is more efficient for the resolvers internal data structures.
328333
fn prioritize(

0 commit comments

Comments
 (0)