Skip to content

Commit

Permalink
Merge partial solution impl blocks (#292)
Browse files Browse the repository at this point in the history
There were two identical impl block for `impl<DP: DependencyProvider> PartialSolution<DP>`, so I merged them. I've also reduced the visibility since `PartialSolution` is also `pub(crate)`.
  • Loading branch information
konstin authored Dec 12, 2024
1 parent 3741e3b commit ea28e95
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions src/internal/partial_solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,6 @@ pub(crate) struct PartialSolution<DP: DependencyProvider> {
has_ever_backtracked: bool,
}

impl<DP: DependencyProvider> PartialSolution<DP> {
pub fn display<'a>(&'a self, package_store: &'a HashArena<DP::P>) -> impl Display + 'a {
struct PSDisplay<'a, DP: DependencyProvider>(&'a PartialSolution<DP>, &'a HashArena<DP::P>);

impl<DP: DependencyProvider> Display for PSDisplay<'_, DP> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut assignments: Vec<_> = self
.0
.package_assignments
.iter()
.map(|(p, pa)| format!("{:?} = '{}': {}", p, self.1[*p], pa))
.collect();
assignments.sort();
write!(
f,
"next_global_index: {}\ncurrent_decision_level: {:?}\npackage_assignments:\n{}",
self.0.next_global_index,
self.0.current_decision_level,
assignments.join("\t\n")
)
}
}

PSDisplay(self, package_store)
}
}

/// Package assignments contain the potential decision and derivations
/// that have already been made for a given package,
/// as well as the intersection of terms by all of these.
Expand Down Expand Up @@ -167,6 +140,31 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
}
}

pub(crate) fn display<'a>(&'a self, package_store: &'a HashArena<DP::P>) -> impl Display + 'a {
struct PSDisplay<'a, DP: DependencyProvider>(&'a PartialSolution<DP>, &'a HashArena<DP::P>);

impl<DP: DependencyProvider> Display for PSDisplay<'_, DP> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut assignments: Vec<_> = self
.0
.package_assignments
.iter()
.map(|(p, pa)| format!("{:?} = '{}': {}", p, self.1[*p], pa))
.collect();
assignments.sort();
write!(
f,
"next_global_index: {}\ncurrent_decision_level: {:?}\npackage_assignments:\n{}",
self.0.next_global_index,
self.0.current_decision_level,
assignments.join("\t\n")
)
}
}

PSDisplay(self, package_store)
}

/// Add a decision.
pub(crate) fn add_decision(&mut self, package: Id<DP::P>, version: DP::V) {
// Check that add_decision is never used in the wrong context.
Expand Down

0 comments on commit ea28e95

Please sign in to comment.