[Aptitude-svn-commit] r3941 - in branches/aptitude-0.3/aptitude: . src/generic/problemresolver

Daniel Burrows dburrows at costa.debian.org
Tue Aug 23 17:09:33 UTC 2005


Author: dburrows
Date: Tue Aug 23 17:09:29 2005
New Revision: 3941

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h
Log:
Use the size and score of solutions to quickly compare them (avoids tons
of calls to lexicographical_compare).

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Tue Aug 23 17:09:29 2005
@@ -1,3 +1,13 @@
+2005-08-23  Daniel Burrows  <dburrows at debian.org>
+
+	* src/generic/problemresolver/problemresolver.h:
+
+	  Efficiency tweak: when comparing solutions by their contents,
+	  don't do a full lexicographical compare unless the two solutions
+	  have different sizes and different scores.  This moves
+	  lexicographical_compare from second place with 18% of the
+	  running time to third place with 7% of the running time.
+
 2005-08-20  Daniel Burrows  <dburrows at debian.org>
 
 	* src/generic/aptitude_resolver_universe.cc:

Modified: branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h	Tue Aug 23 17:09:29 2005
@@ -196,13 +196,39 @@
       // S1 < S2 if
       //   - S1(p)=S2(p) for all p<p' and S1(p')<S2(p'), where
       //     p,p' \in \dom(S1) \cup dom(S2)
-      typename std::map<package,action>::const_iterator i1,i2;
+
+
+      // NB: the correctness of this code depends implicitly on the
+      // invariant that the score is a function of the contents of the
+      // solution.  Essentially we're using the score as a sort of
+      // hash value on solutions!
+      if(s1.get_score() < s2.get_score())
+	return true;
+      else if(s2.get_score() < s1.get_score())
+	return false;
+      else if(s1.get_action_score() < s2.get_action_score())
+	return true;
+      else if(s2.get_action_score() < s1.get_action_score())
+	return false;
+
       const std::map<package,action>
 	&a1=s1.get_actions(), &a2=s2.get_actions();
       const std::set<dep>
 	&us1=s1.get_unresolved_soft_deps(), &us2=s2.get_unresolved_soft_deps();
 
-      return a1 < a2 || (a2 == a1 && us1 < us2);
+
+      // Speed hack: order by size first to avoid traversing the whole
+      // tree.
+      if(a1.size() < a2.size())
+	return true;
+      else if(a2.size() < a1.size())
+	return false;
+      else if(us1.size() < us2.size())
+	return true;
+      else if(us2.size() < us1.size())
+	return false;
+      else
+	return a1 < a2 || (a2 == a1 && us1 < us2);
     }
   };
 



More information about the Aptitude-svn-commit mailing list