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

Daniel Burrows dburrows at costa.debian.org
Mon Aug 29 22:59:04 UTC 2005


Author: dburrows
Date: Mon Aug 29 22:59:01 2005
New Revision: 3985

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/immset.h
Log:
Add a for_each operation that should be quicker for simple iteration over trees.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Mon Aug 29 22:59:01 2005
@@ -1,5 +1,15 @@
 2005-08-29  Daniel Burrows  <dburrows at debian.org>
 
+	* src/generic/immset.h:
+
+	  Add a for_each operation that should be quicker for simple
+	  iteration over trees.
+
+	* src/generic/problemresolver/problemresolver.h:
+
+	  Fix contains_rejected, which was not just slow (due to
+	  imm::*::const_iterator), but was actually flat-out wrong.
+
 	* src/broken_indicator.cc, src/cmdline/cmdline_resolver.cc, src/generic/aptcache.cc, src/generic/problemresolver/problemresolver.h, src/generic/problemresolver/solution.h, src/generic/problemresolver/test.cc, src/solution_fragment.cc, src/solution_screen.cc, tests/test_resolver.cc:
 
 	  Use the new imm::* containers instead of std::*.  This makes

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	Mon Aug 29 22:59:01 2005
@@ -317,6 +317,22 @@
 	// Nothing to do; the tree is already balanced.
 	return *this;
     }
+
+    /** Apply the given operator to each value in the tree in
+     *  order.
+     */
+    template<typename Op>
+    void for_each(const Op &o)
+    {
+      if(isValid())
+	{
+	  getLeft().for_each(o);
+
+	  o(getVal());
+
+	  getRight().for_each(o);
+	}
+    }
   };
 
   /** An entire weighted tree.
@@ -516,6 +532,13 @@
     {
     }
 
+    /** Apply the given operator to each member of this set. */
+    template<typename Op>
+    void for_each(const Op &o) const
+    {
+      root.for_each(o);
+    }
+
     /** Insert an element into a tree, returning a new tree.  This is
      *  not a member function, to stress that it does NOT modify the
      *  old tree; instead, it returns a new tree containing the
@@ -687,6 +710,25 @@
     typedef typename mapping_type::node node;
 
   private:
+    /** An operator that unpacks pairs and passes them to the real
+     *  operator.
+     */
+    template<typename Op>
+    struct map_for_each
+    {
+      const Op &realop;
+    public:
+      map_for_each(const Op &_realop)
+	:realop(_realop)
+      {
+      }
+
+      void operator()(const std::pair<Key, Val> &p)
+      {
+	realop(p.first, p.second);
+      }
+    };
+
     mapping_type contents;
 
   public:
@@ -702,6 +744,16 @@
     {
     }
 
+    /** Apply the given operator to each binding in this map.
+     *
+     *  \param o a function object of two arguments (key, val).
+     */
+    template<typename Op>
+    void for_each(const Op &o) const
+    {
+      return contents.for_each(map_for_each(o));
+    }
+
     mapping_type get_bindings() const
     {
       return contents;



More information about the Aptitude-svn-commit mailing list