]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add add_indices.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 15 Oct 2009 20:21:01 +0000 (20:21 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 15 Oct 2009 20:21:01 +0000 (20:21 +0000)
git-svn-id: https://svn.dealii.org/trunk@19888 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/index_set.h

index 180fe7cf3e2e076fad21b8e61ae6faa85768ed6b..a9afa1a03443b2aa1ac3727a1521b2a411abb452 100644 (file)
@@ -85,6 +85,17 @@ class IndexSet
                                      */
     void add_index (const unsigned int index);
 
+                                    /**
+                                     * Add a whole set of indices
+                                     * described by dereferencing
+                                     * every element of the the
+                                     * iterator range
+                                     * <code>[begin,end)</code>.
+                                     */
+    template <typename ForwardIterator>
+    void add_indices (const ForwardIterator &begin,
+                     const ForwardIterator &end);
+
                                     /**
                                      * Return whether the specified
                                      * index is an element of the
@@ -245,15 +256,7 @@ IndexSet::add_range (const unsigned int begin,
          ExcIndexRange (begin, 0, end));
 
   if (begin != end)
-    {
-                                      // if it turns out to be a
-                                      // single element then add that
-                                      // separately
-      if (end == begin+1)
-       add_index (begin);
-      else
-       ranges.insert (Range(begin,end));
-    }
+    ranges.insert (Range(begin,end));
 }
 
 
@@ -270,6 +273,35 @@ IndexSet::add_index (const unsigned int index)
 
 
 
+template <typename ForwardIterator>
+inline
+void
+IndexSet::add_indices (const ForwardIterator &begin,
+                      const ForwardIterator &end)
+{
+                                  // insert each element of the
+                                  // range. if some of them happen to
+                                  // be consecutive, merge them to a
+                                  // range
+  for (ForwardIterator p=begin; p<end;)
+    {
+      const unsigned int begin_index = *p;
+      unsigned int       end_index   = begin_index + 1;
+      ForwardIterator q = p;
+      ++q;
+      while ((q != end) && (*q == end_index))
+       {
+         ++end_index;
+         ++q;
+       }
+
+      add_range (begin_index, end_index);
+      p = q;
+    }
+}
+
+
+
 inline
 bool
 IndexSet::is_element (const unsigned int index) const

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.