diff options
author | Timo Teräs <timo.teras@iki.fi> | 2013-01-21 15:37:23 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2013-01-21 15:37:23 +0200 |
commit | 93bd3057135bd73befa2ae499f18a51b8749c142 (patch) | |
tree | 79c64dd6cd8208c2443c7d73aab3d79b02942172 /src | |
parent | 235342ea0b31b66ea24120c58cd661b6c807a2a4 (diff) | |
download | apk-tools-93bd3057135bd73befa2ae499f18a51b8749c142.tar.gz apk-tools-93bd3057135bd73befa2ae499f18a51b8749c142.tar.bz2 apk-tools-93bd3057135bd73befa2ae499f18a51b8749c142.tar.xz apk-tools-93bd3057135bd73befa2ae499f18a51b8749c142.zip |
solver: simplify strength evaluation in constraint handling
Diffstat (limited to 'src')
-rw-r--r-- | src/solver.c | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/src/solver.c b/src/solver.c index bf9a167..3943bad 100644 --- a/src/solver.c +++ b/src/solver.c @@ -984,17 +984,10 @@ static int next_branch(struct apk_solver_state *ss) static void apply_constraint(struct apk_solver_state *ss, struct apk_dependency *dep) { - struct apk_package *requirer_pkg = NULL; + struct apk_decision *d = &ss->decisions[ss->num_decisions]; + struct apk_package *requirer_pkg = decision_to_pkg(d); struct apk_name *name = dep->name; - int i, strength, changed = 0; - - if (ss->num_decisions > 0) { - struct apk_decision *d = &ss->decisions[ss->num_decisions]; - requirer_pkg = decision_to_pkg(d); - strength = d->requirers; - } else { - strength = 1; - } + int i, changed = 0, strength = d->requirers; dbg_printf("--->apply_constraint: %s (strength %d)\n", name->name, strength); @@ -1063,17 +1056,10 @@ static void apply_constraint(struct apk_solver_state *ss, struct apk_dependency static void undo_constraint(struct apk_solver_state *ss, struct apk_dependency *dep) { + struct apk_decision *d = &ss->decisions[ss->num_decisions]; struct apk_name *name = dep->name; - struct apk_package *requirer_pkg = NULL; - int i, strength; - - if (ss->num_decisions > 0) { - struct apk_decision *d = &ss->decisions[ss->num_decisions]; - requirer_pkg = decision_to_pkg(d); - strength = d->requirers; - } else { - strength = 1; - } + struct apk_package *requirer_pkg = decision_to_pkg(d); + int i, strength = d->requirers; dbg_printf("--->undo_constraint: %s (strength %d)\n", name->name, strength); @@ -1553,6 +1539,8 @@ int apk_solver_solve(struct apk_database *db, ss->max_decisions ++; ss->decisions = calloc(1, sizeof(struct apk_decision[ss->max_decisions])); + /* "Initial decision" is used as dummy for world constraints. */ + ss->decisions[0].requirers = 1; foreach_dependency(ss, world, apply_constraint); do { |