]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Introduce IndexSet::is_subset_of().
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 24 Aug 2023 23:33:47 +0000 (17:33 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 25 Aug 2023 00:11:40 +0000 (18:11 -0600)
include/deal.II/base/index_set.h
source/base/index_set.cc

index 76776af802e1ad94a1d7740c3eae1a059b2bf4b7..fe0b4de11d4778ec6b754a5ca146555a132e3a66 100644 (file)
@@ -444,6 +444,16 @@ public:
   void
   fill_binary_vector(VectorType &vector) const;
 
+  /**
+   * Determine whether the current object represents a set of indices
+   * that is a subset of the set represented by the argument. This
+   * function returns `true` if the two sets are the same, that is, it
+   * considers the "subset" comparison typically used in set theory,
+   * rather than the "strict subset" comparison.
+   */
+  bool
+  is_subset_of(const IndexSet &other) const;
+
   /**
    * Output a text representation of this IndexSet to the given stream. Used
    * for testing.
index 8582fd7f9c8499c771e5038f12dd6648c8ecf7c6..f3c7b66b660e98b8f245f8bd409e5da8d648dc4d 100644 (file)
@@ -497,6 +497,23 @@ IndexSet::add_indices(const IndexSet &other, const size_type offset)
 
 
 
+bool
+IndexSet::is_subset_of(const IndexSet &other) const
+{
+  // See whether there are indices in the current set that are not in 'other'.
+  // If so, then this is clearly not a subset of 'other'.
+  IndexSet A_minus_B = *this;
+  A_minus_B.subtract_set(other);
+  if (A_minus_B.n_elements() > 0)
+    return false;
+  else
+    // Else, every index in 'this' is also in 'other', since we ended up
+    // with an empty set upon subtraction. This means that we have a subset:
+    return true;
+}
+
+
+
 void
 IndexSet::write(std::ostream &out) const
 {

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.