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

Daniel Burrows dburrows at costa.debian.org
Tue Aug 30 17:29:23 UTC 2005


Author: dburrows
Date: Tue Aug 30 17:29:20 2005
New Revision: 3995

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/problemresolver/problemresolver.h
Log:
Use the mapset to vastly accelerate the problemresolver; now faster
than before and without eating hundreds of megs of memory!

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Tue Aug 30 17:29:20 2005
@@ -1,5 +1,10 @@
 2005-08-30  Daniel Burrows  <dburrows at debian.org>
 
+	* src/generic/problemresolver/problemresolver.h:
+
+	  Make the conflict set a mapset instead of a std::set; use
+	  setmap's special abilities to accelerate searches.
+
 	* src/generic/setset.h:
 
 	  Add a size() routine in setset and mapset.

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 30 17:29:20 2005
@@ -52,6 +52,8 @@
 #include "exceptions.h"
 #include "solution.h"
 
+#include "../setset.h"
+
 /** A dummy iterator that's always an "end" iterator. */
 template<class V>
 struct dummy_end_iterator
@@ -304,7 +306,7 @@
   /** Stores conflicts: sets of installations that have been
    *  determined to be mutually incompatible.
    */
-  std::set<imm::map<package, action> > conflicts;
+  mapset<package, action> conflicts;
 
   /** The initial set of broken dependencies.  Kept here for use in
    *  the stupid-elimination algorithm.
@@ -336,16 +338,19 @@
   std::ostream &dump_conflict(std::ostream &out, const action &act) const;
 
 
-  /** \param conflictor an action contained in a conflict.
-   *  \param a an action from a solution or a conflict.
+  /** \param conflictorpair a (package, action) pair contained in a conflict.
+   *  \param apair a (package, action) pair from a solution or a conflict.
    *
    *  \return \b true if the given conflictor matches a.  This relation
    *          is transitive, so if c1 matches c2 and c2 matches a,
    *          then c1 matches a.
    */
-  static bool conflictor_matches(const action &conflictor,
-				 const action &a)
+  static bool conflictor_matches(const std::pair<package, action> &conflictorpair,
+				 const std::pair<package, action> &apair)
     {
+      const action &conflictor = conflictorpair.second;
+      const action &a = apair.second;
+
       if(a.ver != conflictor.ver)
 	return false;
 
@@ -389,22 +394,17 @@
    *  \return a conflict matched by m, or conflicts.end() if no such
    *  conflict exists.
    */
-  typename std::set<imm::map<package, action> >::const_iterator
-  matches_any_conflict(const imm::map<package, action> &m) const
+  typename mapset<package, action>::const_iterator
+  find_matching_conflict(const imm::map<package, action> &m) const
   {
-    for(typename std::set<imm::map<package, action> >::const_iterator ci = conflicts.begin();
-	ci != conflicts.end(); ++ci)
-	if(conflict_matches(*ci, m))
-	  return ci;
-
-    return conflicts.end();
+    return conflicts.find_submap(m, &conflictor_matches);
   }
 
   /** Test whether the given solution contains a conflict. */
   bool contains_conflict(const solution &s) const
   {
-    typename std::set<imm::map<package, action> >::const_iterator
-      found = matches_any_conflict(s.get_actions());
+    typename mapset<package, action>::const_iterator
+      found = find_matching_conflict(s.get_actions());
     bool rval = (found != conflicts.end());
 
     if(debug && rval)
@@ -426,8 +426,8 @@
    */
   void add_conflict(const imm::map<package, action> &conflict)
   {
-    typename std::set<imm::map<package, action> >::const_iterator
-      found = matches_any_conflict(conflict);
+    typename mapset<package, action>::const_iterator
+      found = find_matching_conflict(conflict);
 
     if(found != conflicts.end())
       {
@@ -441,30 +441,9 @@
 	  }
       }
     else
-      {
-	for(typename std::set<imm::map<package, action> >::const_iterator ci = conflicts.begin(), cj;
-	    ci != conflicts.end(); ci = cj)
-	  {
-	    cj = ci;
-	    ++cj;
-
-	    if(conflict_matches(conflict, *ci))
-	      {
-		if(debug)
-		  {
-		    std::cout << "Dropping conflict ";
-		    dump_conflict(std::cout, *ci);
-		    std::cout << " because it is redundant with ";
-		    dump_conflict(std::cout, conflict);
-		    std::cout << std::endl;
-		  }
-
-		conflicts.erase(ci);
-	      }
-	  }
-
-	conflicts.insert(conflict);
-      }
+      // TODO: drop conflicts of which this is a subset.  Needs work
+      // at the setset level.
+      conflicts.insert(conflict);
   }
 
 #if 0
@@ -1600,8 +1579,8 @@
 	imm::map<package, action> new_acts = s.get_actions();
 	new_acts.put(v.get_package(), act);
 
-	typename std::set<imm::map<package, action> >::const_iterator
-	  found = matches_any_conflict(new_acts);
+	typename mapset<package, action>::const_iterator
+	  found = find_matching_conflict(new_acts);
 
 	if(found == conflicts.end())
 	  generator.make_successor(s, &act, &act+1,
@@ -1617,8 +1596,10 @@
 		std::cout << std::endl;
 	      }
 
+	    imm::map<package, action> m = *found;
+
 	    for(typename imm::map<package, action>::const_iterator ci
-		  = found->begin(); ci != found->end(); ++ci)
+		  = m.begin(); ci != m.end(); ++ci)
 	      {
 		// Discard the version that we were trying to install,
 		// so that the caller can use this to form a more



More information about the Aptitude-svn-commit mailing list