From b8476b62b75e35f20b8cdd1bebcfc5da7ef286b9 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 13 Oct 2009 18:31:53 +0000 Subject: [PATCH] Add a few functions. git-svn-id: https://svn.dealii.org/trunk@19849 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/index_set.h | 74 +++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/deal.II/base/include/base/index_set.h b/deal.II/base/include/base/index_set.h index acf130640c..0092c4346d 100644 --- a/deal.II/base/include/base/index_set.h +++ b/deal.II/base/include/base/index_set.h @@ -101,6 +101,33 @@ class IndexSet */ bool is_contiguous () const; + /** + * Return the number of elements + * stored in this index set. + */ + unsigned int n_elements () const; + + /** + * Return the nth index stored in + * this index set. @p n obviously + * needs to be less than + * n_elements(). + */ + unsigned int nth_index_in_set (const unsigned int n) const; + + /** + * Return the how-manyth element + * of this set (counted in + * ascending order) @p n is. @p n + * needs to be less than the + * size(). This function throws + * an exception if the index @p n + * is not actually a member of + * this index set, i.e. if + * is_element(n) is false. + */ + unsigned int index_within_set (const unsigned int n) const; + /** * Compress the internal * representation by merging @@ -300,6 +327,53 @@ IndexSet::is_contiguous () const +inline +unsigned int +IndexSet::n_elements () const +{ + // make sure we have + // non-overlapping ranges and + // individual indices + compress (); + + unsigned int s = individual_indices.size(); + for (std::set::iterator + range = contiguous_ranges.begin(); + range != contiguous_ranges.end(); + ++range) + s += (range->second - range->first); + + return s; +} + + + +inline +unsigned int +IndexSet::nth_index_in_set (const unsigned int n) const +{ + Assert (n < n_elements(), ExcIndexRange (n, 0, n_elements())); + + Assert (is_contiguous(), ExcNotImplemented()); + return (n+contiguous_ranges.begin()->first); +} + + + +inline +unsigned int +IndexSet::index_within_set (const unsigned int n) const +{ + Assert (is_element(n) == true, + ExcMessage ("Given number is not an element of this set.")); + Assert (n < size(), ExcIndexRange (n, 0, size())); + + Assert (is_contiguous(), ExcNotImplemented()); + return (n-contiguous_ranges.begin()->first); +} + + + DEAL_II_NAMESPACE_CLOSE -- 2.39.5