Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge partial solution impl blocks #292

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading