From 1be4c06866137120eb2c884b886384dec2590a93 Mon Sep 17 00:00:00 2001 From: heister Date: Mon, 27 Dec 2010 19:28:39 +0000 Subject: [PATCH] make IndexSet::n_elements() an O(1) operation. git-svn-id: https://svn.dealii.org/trunk@23073 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/base/index_set.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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; } -- 2.39.5