From 14f57660c1ab1e273d0354d42e62c7d58e4f2357 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 15 Oct 2009 20:25:37 +0000 Subject: [PATCH] Introduce a flag is_compressed. git-svn-id: https://svn.dealii.org/trunk@19890 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/index_set.h | 24 +++++++++++++++++++++++- deal.II/base/source/index_set.cc | 4 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/deal.II/base/include/base/index_set.h b/deal.II/base/include/base/index_set.h index a9afa1a034..0a565c5b5b 100644 --- a/deal.II/base/include/base/index_set.h +++ b/deal.II/base/include/base/index_set.h @@ -181,6 +181,21 @@ class IndexSet */ mutable std::set ranges; + /** + * True if compress() has been + * called after the last change + * in the set of indices. + * + * The variable is marked + * "mutable" so that it can be + * changed by compress(), though + * this of course doesn't change + * anything about the external + * representation of this index + * set. + */ + mutable bool is_compressed; + /** * The overall size of the index * range. Elements of this index @@ -210,6 +225,7 @@ IndexSet::RangeComparison::operator() (const Range &range_1, inline IndexSet::IndexSet () : + is_compressed (true), index_space_size (0) {} @@ -218,6 +234,7 @@ IndexSet::IndexSet () inline IndexSet::IndexSet (const unsigned int size) : + is_compressed (true), index_space_size (size) {} @@ -231,6 +248,7 @@ IndexSet::set_size (const unsigned int sz) ExcMessage ("This function can only be called if the current " "object does not yet contain any elements.")); index_space_size = sz; + is_compressed = true; } @@ -256,7 +274,10 @@ IndexSet::add_range (const unsigned int begin, ExcIndexRange (begin, 0, end)); if (begin != end) - ranges.insert (Range(begin,end)); + { + ranges.insert (Range(begin,end)); + is_compressed = false; + } } @@ -269,6 +290,7 @@ IndexSet::add_index (const unsigned int index) ExcIndexRange (index, 0, index_space_size)); ranges.insert (Range(index, index+1)); + is_compressed = false; } diff --git a/deal.II/base/source/index_set.cc b/deal.II/base/source/index_set.cc index 8838800216..3b24d41360 100644 --- a/deal.II/base/source/index_set.cc +++ b/deal.II/base/source/index_set.cc @@ -18,6 +18,8 @@ DEAL_II_NAMESPACE_OPEN void IndexSet::compress () const { + if (is_compressed == true) + return; // see if any of the // contiguous ranges can be // merged. since they are sorted by @@ -73,6 +75,8 @@ IndexSet::compress () const last_index)); } } + + is_compressed = true; } -- 2.39.5