Skip to content

Commit

Permalink
make things dry again
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Dec 21, 2023
1 parent 28a7c6e commit 5430296
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/internal/partial_solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,24 +208,27 @@ impl<P: Package, VS: VersionSet, Priority: Ord + Clone> PartialSolution<P, VS, P
store: &Arena<Incompatibility<P, VS>>,
) {
use indexmap::map::Entry;
let term = store[cause].get(&package).unwrap().negate();
let global_index = self.next_global_index;
let mut dated_derivation = DatedDerivation {
global_index: self.next_global_index,
decision_level: self.current_decision_level,
cause,
accumulated_intersection: store[cause].get(&package).unwrap().negate(),
};
self.next_global_index += 1;
let pa_last_index = self.package_assignments.len().saturating_sub(1);
match self.package_assignments.entry(package) {
Entry::Occupied(mut occupied) => {
let idx = occupied.index();
let pa = occupied.get_mut();
pa.highest_decision_level = self.current_decision_level;
let accumulated_intersection;
match &mut pa.assignments_intersection {
// Check that add_derivation is never called in the wrong context.
AssignmentsIntersection::Decision(_) => {
panic!("add_derivation should not be called after a decision")
}
AssignmentsIntersection::Derivations(t) => {
*t = t.intersection(&term);
accumulated_intersection = t.clone();
*t = t.intersection(&dated_derivation.accumulated_intersection);
dated_derivation.accumulated_intersection = t.clone();
if t.is_positive() {
// we can use `swap_indices` to make `changed_this_decision_level` only go down by 1
// but the copying is slower then the larger search
Expand All @@ -234,27 +237,18 @@ impl<P: Package, VS: VersionSet, Priority: Ord + Clone> PartialSolution<P, VS, P
}
}
}
pa.dated_derivations.push(DatedDerivation {
global_index,
decision_level: self.current_decision_level,
cause,
accumulated_intersection,
});
pa.dated_derivations.push(dated_derivation);
}
Entry::Vacant(v) => {
let term = dated_derivation.accumulated_intersection.clone();
if term.is_positive() {
self.changed_this_decision_level =
std::cmp::min(self.changed_this_decision_level, pa_last_index);
}
v.insert(PackageAssignments {
smallest_decision_level: self.current_decision_level,
highest_decision_level: self.current_decision_level,
dated_derivations: SmallVec::One([DatedDerivation {
global_index,
decision_level: self.current_decision_level,
cause,
accumulated_intersection: term.clone(),
}]),
dated_derivations: SmallVec::One([dated_derivation]),
assignments_intersection: AssignmentsIntersection::Derivations(term),
});
}
Expand Down

0 comments on commit 5430296

Please sign in to comment.