Commit 01d0e4c4 authored by Timo Teräs's avatar Timo Teräs

solver: optimize backjumping

to be functional when backtracking
parent 831bce5c
...@@ -60,7 +60,8 @@ struct apk_sign_ctx { ...@@ -60,7 +60,8 @@ struct apk_sign_ctx {
struct apk_dependency { struct apk_dependency {
struct apk_name *name; struct apk_name *name;
apk_blob_t *version; apk_blob_t *version;
unsigned short repository_tag; unsigned solver_state : 22;
unsigned repository_tag : 6;
unsigned conflict : 1; unsigned conflict : 1;
unsigned result_mask : 3; unsigned result_mask : 3;
}; };
......
...@@ -1029,8 +1029,10 @@ static void apply_constraint(struct apk_solver_state *ss, struct apk_dependency ...@@ -1029,8 +1029,10 @@ static void apply_constraint(struct apk_solver_state *ss, struct apk_dependency
} }
} }
if (name->ss.last_touched_decision == 0 || changed) if (name->ss.last_touched_decision == 0 || changed) {
dep->solver_state = name->ss.last_touched_decision;
name->ss.last_touched_decision = ss->num_decisions; name->ss.last_touched_decision = ss->num_decisions;
}
if (!dep->conflict) { if (!dep->conflict) {
dbg_printf("%s requirers += %d\n", name->name, strength); dbg_printf("%s requirers += %d\n", name->name, strength);
...@@ -1099,12 +1101,10 @@ static void undo_constraint(struct apk_solver_state *ss, struct apk_dependency * ...@@ -1099,12 +1101,10 @@ static void undo_constraint(struct apk_solver_state *ss, struct apk_dependency *
} }
} }
/* note: for perfection, we should revert here to the if (dep->solver_state) {
* *previous* value, but that'd require keeping track name->ss.last_touched_decision = dep->solver_state;
* of it which would require dynamic memory allocations dep->solver_state = 0;
* or additional solver state field in apk_dependency }
* to store it (or hefty recalculations). */
name->ss.last_touched_decision = 0;
if (!dep->conflict) { if (!dep->conflict) {
name->ss.requirers -= strength; name->ss.requirers -= strength;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment