From: Wolfgang Bangerth Date: Thu, 24 Aug 2023 23:33:47 +0000 (-0600) Subject: Introduce IndexSet::is_subset_of(). X-Git-Tag: relicensing~549^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd35b086bac8565387f540c3d90ed27165848ced;p=dealii.git Introduce IndexSet::is_subset_of(). --- 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 {