]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Further along with merging ranges.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 10 Oct 2009 02:34:25 +0000 (02:34 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 10 Oct 2009 02:34:25 +0000 (02:34 +0000)
git-svn-id: https://svn.dealii.org/trunk@19798 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/index_set.cc

index be02d748ccad8d1227e783ddaa5ff327a4640547..f19984c9b26fc734b8db22b61935b80161ed455c 100644 (file)
@@ -57,9 +57,45 @@ IndexSet::compress () const
   }
 
 
-                                  // we can roll any of
+                                  // next see if we can roll any of
                                   // the individual entries into the
                                   // contiguous ranges
+
+
+                                  // finally see if any of the
+                                  // contiguous ranges can be
+                                  // merged. since they are sorted by
+                                  // their first index, determining
+                                  // overlap isn't all that hard
+  for (std::set<ContiguousRange, RangeComparison>::iterator
+        i = contiguous_ranges.begin();
+       i != contiguous_ranges.end();
+       ++i)
+    {
+      std::set<ContiguousRange, RangeComparison>::const_iterator
+       next = i;
+      ++next;
+
+      if (next != contiguous_ranges.end())
+       if (next->first <= i->second)
+         {
+           const unsigned int first_index = i->first;
+           const unsigned int last_index  = next->second;
+
+                                            // delete the two old
+                                            // ranges and insert the
+                                            // new range
+           contiguous_ranges.erase (i, ++next);
+           contiguous_ranges.insert (ContiguousRange(first_index,
+                                                     last_index));
+
+                                            // then set iterator to
+                                            // the same position as
+                                            // before
+           i = contiguous_ranges.lower_bound (ContiguousRange(first_index,
+                                                              last_index));
+         }
+    }
 }
 
 

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.