From bd35b086bac8565387f540c3d90ed27165848ced Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 24 Aug 2023 17:33:47 -0600 Subject: [PATCH] Introduce IndexSet::is_subset_of(). --- include/deal.II/base/index_set.h | 10 ++++++++++ source/base/index_set.cc | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/deal.II/base/index_set.h b/include/deal.II/base/index_set.h index 76776af802..fe0b4de11d 100644 --- a/include/deal.II/base/index_set.h +++ b/include/deal.II/base/index_set.h @@ -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. diff --git a/source/base/index_set.cc b/source/base/index_set.cc index 8582fd7f9c..f3c7b66b66 100644 --- a/source/base/index_set.cc +++ b/source/base/index_set.cc @@ -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 { -- 2.39.5