summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorroot <root@petrie.tu.ok.cox.net>2013-06-11 10:30:31 -0500
committerroot <root@petrie.tu.ok.cox.net>2013-06-11 10:30:31 -0500
commita2d873a77c6dd2e7f6219e6941af796e1f904e69 (patch)
tree85002b7ca26bbb4d80da1c3d0ef9ef99183d0ffb /src
parent129821d274a0569c3a078679c07f9c63aeff249f (diff)
downloadapk-tools-a2d873a77c6dd2e7f6219e6941af796e1f904e69.tar.gz
apk-tools-a2d873a77c6dd2e7f6219e6941af796e1f904e69.tar.bz2
apk-tools-a2d873a77c6dd2e7f6219e6941af796e1f904e69.tar.xz
apk-tools-a2d873a77c6dd2e7f6219e6941af796e1f904e69.zip
Revert "solver: increase score fields to 32-bits (from 16-bits)"
This reverts commit 84bfef1a6b587a7da7d12fb701ab0d1d5d6ce2a9.
Diffstat (limited to 'src')
-rw-r--r--src/apk_solver_data.h22
-rw-r--r--src/solver.c48
2 files changed, 39 insertions, 31 deletions
diff --git a/src/apk_solver_data.h b/src/apk_solver_data.h
index 8076a08..5777325 100644
--- a/src/apk_solver_data.h
+++ b/src/apk_solver_data.h
@@ -17,10 +17,24 @@
#include "apk_provider_data.h"
struct apk_score {
- uint32_t unsatisfied;
- uint32_t non_preferred_actions;
- uint32_t non_preferred_pinnings;
- uint32_t preference;
+ union {
+ struct {
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+ unsigned short preference;
+ unsigned short non_preferred_pinnings;
+ unsigned short non_preferred_actions;
+ unsigned short unsatisfied;
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ unsigned short unsatisfied;
+ unsigned short non_preferred_actions;
+ unsigned short non_preferred_pinnings;
+ unsigned short preference;
+#else
+#error Unknown endianess.
+#endif
+ };
+ uint64_t score;
+ };
};
struct apk_solver_name_state {
diff --git a/src/solver.c b/src/solver.c
index 24ee5a9..ff91434 100644
--- a/src/solver.c
+++ b/src/solver.c
@@ -129,15 +129,11 @@ static solver_result_t push_decision(struct apk_solver_state *ss,
int branching_point,
int topology_position);
+#ifdef DEBUG_CHECKS
static void addscore(struct apk_score *a, struct apk_score *b)
{
struct apk_score orig = *a;
-
- a->unsatisfied += b->unsatisfied;
- a->non_preferred_actions += b->non_preferred_actions;
- a->non_preferred_pinnings += b->non_preferred_pinnings;
- a->preference += b->preference;
-
+ a->score += b->score;
ASSERT(a->unsatisfied >= orig.unsatisfied, "Unsatisfied overflow");
ASSERT(a->non_preferred_actions >= orig.non_preferred_actions, "Preferred action overflow");
ASSERT(a->non_preferred_pinnings >= orig.non_preferred_pinnings, "Preferred pinning overflow");
@@ -147,36 +143,38 @@ static void addscore(struct apk_score *a, struct apk_score *b)
static void subscore(struct apk_score *a, struct apk_score *b)
{
struct apk_score orig = *a;
-
- a->unsatisfied -= b->unsatisfied;
- a->non_preferred_actions -= b->non_preferred_actions;
- a->non_preferred_pinnings -= b->non_preferred_pinnings;
- a->preference -= b->preference;
-
+ a->score -= b->score;
ASSERT(a->unsatisfied <= orig.unsatisfied, "Unsatisfied underflow");
ASSERT(a->non_preferred_actions <= orig.non_preferred_actions, "Preferred action underflow");
ASSERT(a->non_preferred_pinnings <= orig.non_preferred_pinnings, "Preferred pinning overflow");
ASSERT(a->preference <= orig.preference, "Preference underflow");
}
+#else
+static void addscore(struct apk_score *a, struct apk_score *b)
+{
+ a->score += b->score;
+}
+
+static void subscore(struct apk_score *a, struct apk_score *b)
+{
+ a->score -= b->score;
+}
+#endif
static inline int cmpscore(struct apk_score *a, struct apk_score *b)
{
- if (a->unsatisfied != b->unsatisfied)
- return a->unsatisfied < b->unsatisfied ? -1 : 1;
- if (a->non_preferred_actions != b->non_preferred_actions)
- return a->non_preferred_actions < b->non_preferred_actions ? -1 : 1;
- if (a->non_preferred_pinnings != b->non_preferred_pinnings)
- return a->non_preferred_pinnings < b->non_preferred_pinnings ? -1 : 1;
- if (a->preference != b->preference)
- return a->preference < b->preference ? -1 : 1;
+ if (a->score < b->score) return -1;
+ if (a->score > b->score) return 1;
return 0;
}
static inline int cmpscore2(struct apk_score *a1, struct apk_score *a2, struct apk_score *b)
{
- struct apk_score a = *a1;
- addscore(&a, a2);
- return cmpscore(&a, b);
+ struct apk_score a;
+ a.score = a1->score + a2->score;
+ if (a.score < b->score) return -1;
+ if (a.score > b->score) return 1;
+ return 0;
}
static struct apk_package_state *pkg_to_ps(struct apk_package *pkg)
@@ -1982,10 +1980,6 @@ void apk_solver_print_errors(struct apk_database *db,
char pkgtext[256];
int i, j;
- /* negative for hard failure without partial solution */
- if (unsatisfiable <= 0)
- return;
-
apk_name_array_init(&names);
apk_error("%d unsatisfiable dependencies:", unsatisfiable);