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

Daniel Burrows dburrows at costa.debian.org
Sun Sep 18 03:29:48 UTC 2005


Author: dburrows
Date: Sun Sep 18 03:29:45 2005
New Revision: 4105

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/immset.h
Log:
Write an intrinsic subset routine.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Sun Sep 18 03:29:45 2005
@@ -1,5 +1,10 @@
 2005-09-17  Daniel Burrows  <dburrows at debian.org>
 
+	* src/generic/immset.h:
+
+	  Write an intrinsic subset routine for the binary trees that
+	  should be quicker than iterating over them.
+
 	* src/generic/problemresolver/conflictset.h, src/generic/problemresolver/problemresolver.h, tests/test_resolver.cc:
 
 	  Back out the conflictset class, since it didn't speed anything

Modified: branches/aptitude-0.3/aptitude/src/generic/immset.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/immset.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/immset.h	Sun Sep 18 03:29:45 2005
@@ -570,6 +570,40 @@
           nodes_intersect(n1.getRight(), n2.getRight(), f);
     }
 
+    /** \return \b true if n1 contains n2 under f. */
+    template<typename F>
+    bool node_contains(const node &n1, const node &n2, const F &f) const
+    {
+      if(n2.empty())
+        return true;
+      else if(n1.empty())
+        return false;
+      else if(value_compare(n1.getVal(), n2.getVal()))
+        {
+	  // Strip the left subtree of n2.
+	  node n2repl = n2.getLeft().empty()
+	    ? n2 : node(n2.getVal(), node(), n2.getRight());
+
+	  return node_contains(n1, n2.getLeft(), f) &&
+	         node_contains(n1.getRight(), n2repl, f);
+        }
+      else if(value_compare(n1.getVal(), n2.getVal()))
+        {
+	  // Strip the right subtree of n2.
+	  node n2repl = n2.getRight().empty()
+	    ? n2 : node(n2.getVal(), n2.getLeft(), node());
+
+	  return node_contains(n1, n2.getRight(), f) &&
+	         node_contains(n1.getLeft(), n2repl, f);
+	}
+      else
+        {
+	  return f(n2.getVal(), n1.getVal()) &&
+	         node_contains(n1.getLeft(), n2.getLeft(), f) &&
+	         node_contains(n1.getRight(), n2.getRight(), f);
+	}
+    }
+
     /** Remove the given value from the given tree. */
     node remove(const node &n, const Val &x) const
     {
@@ -638,6 +672,7 @@
 
     /** \return \b true if other contains an element equivalent to
      *                  an element in this and related by f.
+     *                  f is invoked as (thiselt, otherelt).
      */
     template<typename F>
     bool intersects(const set &other, const F &f) const
@@ -651,6 +686,24 @@
       return nodes_intersect(root, other.root, universal_relation<Val>());
     }
 
+    /** \return \b true if each element of other is related by f to an
+     *                  element in this.  f is invoked as
+     *                  (otherelt, thiselt).
+     */
+    template<typename F>
+    bool contains(const set &other, const F &f) const
+    {
+      return node_contains(root, other.root, f);
+    }
+
+    /** \return \b true if each element in other has an equivalent
+     *                  element in this set.
+     */
+    bool contains(const set &other) const
+    {
+      return node_contains(root, other.root, universal_relation<Val>());
+    }
+
     /** Do an "in-place" update of this set, by replacing the root
      *  with a new root.
      */



More information about the Aptitude-svn-commit mailing list