]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a few functions.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 13 Oct 2009 18:31:53 +0000 (18:31 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 13 Oct 2009 18:31:53 +0000 (18:31 +0000)
git-svn-id: https://svn.dealii.org/trunk@19849 0785d39b-7218-0410-832d-ea1e28bc413d

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

index acf130640c828e4f04e579cb1d3f68f864d0502f..0092c4346d8ecdf240e665a177df83f560d25dd8 100644 (file)
@@ -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<ContiguousRange, RangeComparison>::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

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.