]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement indexing also for non-contiguous ranges.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 15 Oct 2009 22:57:43 +0000 (22:57 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 15 Oct 2009 22:57:43 +0000 (22:57 +0000)
git-svn-id: https://svn.dealii.org/trunk@19897 0785d39b-7218-0410-832d-ea1e28bc413d

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

index eb6a8b2bf1a2657f18bca72d524223b0dae3bc0b..b310ade67fd1cc9d3416ed564b3912c7fcecf5ca 100644 (file)
@@ -438,8 +438,17 @@ 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+ranges.begin()->begin);
+//TODO: this could be done more efficiently by using a binary search
+  for (std::vector<Range>::const_iterator p = ranges.begin();
+       p != ranges.end(); ++p)
+    {
+      Assert (n >= p->nth_index_in_set, ExcInternalError());
+      if (n < p->nth_index_in_set + (p->end-p->begin))
+       return p->begin + (n-p->nth_index_in_set);
+    }
+
+  Assert (false, ExcInternalError());
+  return numbers::invalid_unsigned_int;
 }
 
 
@@ -452,8 +461,17 @@ IndexSet::index_within_set (const unsigned int n) const
          ExcMessage ("Given number is not an element of this set."));
   Assert (n < size(), ExcIndexRange (n, 0, size()));
 
-  Assert (is_contiguous(), ExcNotImplemented());
-  return (n-ranges.begin()->begin);
+//TODO: this could be done more efficiently by using a binary search
+  for (std::vector<Range>::const_iterator p = ranges.begin();
+       p != ranges.end(); ++p)
+    {
+      Assert (n >= p->begin, ExcInternalError());
+      if (n < p->end)
+       return (n-p->begin) + p->nth_index_in_set;
+    }
+
+  Assert (false, ExcInternalError());
+  return numbers::invalid_unsigned_int;
 }
 
 

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.