Skip to content

Commit

Permalink
when priorities are equal do breadth first search
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Dec 18, 2024
1 parent d49bf5f commit a9ba742
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/internal/partial_solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! A Memory acts like a structured partial solution
//! where terms are regrouped by package in a [Map](crate::type_aliases::Map).
use std::cmp::Reverse;
use std::fmt::{Debug, Display};
use std::hash::BuildHasherDefault;

Expand Down Expand Up @@ -67,7 +68,7 @@ pub(crate) struct PartialSolution<DP: DependencyProvider> {
///
/// The max heap allows quickly `pop`ing the highest priority package.
prioritized_potential_packages:
PriorityQueue<Id<DP::P>, DP::Priority, BuildHasherDefault<FxHasher>>,
PriorityQueue<Id<DP::P>, (DP::Priority, Reverse<u32>), BuildHasherDefault<FxHasher>>,
/// Whether we have never backtracked, to enable fast path optimizations.
has_ever_backtracked: bool,
}
Expand Down Expand Up @@ -330,7 +331,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
.filter_map(|(&p, pa)| pa.assignments_intersection.potential_package_filter(p))
.for_each(|(p, r)| {
let priority = prioritizer(p, r);
prioritized_potential_packages.push(p, priority);
prioritized_potential_packages.push(p, (priority, Reverse(p.into_raw() as u32)));
});
self.prioritize_decision_level = self.package_assignments.len();
prioritized_potential_packages.pop().map(|(p, _)| p)
Expand Down
5 changes: 5 additions & 0 deletions src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ pub trait DependencyProvider {
/// > since these packages will run out of versions to try more quickly.
/// > But there's likely room for improvement in these heuristics.
///
/// The `package_conflicts_counts` argument provides access to some other heuristics that
/// are production users have found useful. Although the exact meaning/efficacy of those arguments may change.
///
/// If two packages have the same priority, PubGrub will biased toward a breadth first search.
///
/// Note: the resolver may call this even when the range has not changed,
/// if it is more efficient for the resolvers internal data structures.
fn prioritize(
Expand Down

0 comments on commit a9ba742

Please sign in to comment.