From: heister Date: Mon, 27 Dec 2010 19:28:39 +0000 (+0000) Subject: make IndexSet::n_elements() an O(1) operation. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1be4c06866137120eb2c884b886384dec2590a93;p=dealii-svn.git make IndexSet::n_elements() an O(1) operation. git-svn-id: https://svn.dealii.org/trunk@23073 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/base/index_set.h b/deal.II/include/deal.II/base/index_set.h index 1a17164e81..0c0b59213c 100644 --- a/deal.II/include/deal.II/base/index_set.h +++ b/deal.II/include/deal.II/base/index_set.h @@ -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::iterator range = ranges.begin(); range != ranges.end(); ++range) s += (range->end - range->begin); - - return s; + Assert(s==v, ExcInternalError()); +#endif + + return v; }