]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
make IndexSet::n_elements() an O(1) operation.
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 27 Dec 2010 19:28:39 +0000 (19:28 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 27 Dec 2010 19:28:39 +0000 (19:28 +0000)
git-svn-id: https://svn.dealii.org/trunk@23073 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 1a17164e8115de739753b774d0168bb7c03d0834..0c0b59213cc32a1c7c0f44d85967062746de9dde 100644 (file)
@@ -745,13 +745,23 @@ IndexSet::n_elements () const
                                   // non-overlapping ranges
   compress ();
 
+  unsigned int v = 0;
+  if (!ranges.empty())
+    {
+      Range & r = ranges.back();
+      v = r.nth_index_in_set + r.end - r.begin;
+    }
+  
+#ifdef DEBUG  
   unsigned int s = 0;
   for (std::vector<Range>::iterator range = ranges.begin();
        range != ranges.end();
        ++range)
     s += (range->end - range->begin);
-
-  return s;
+  Assert(s==v, ExcInternalError());
+#endif  
+  
+  return v;
 }
 
 

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.