From: Wolfgang Bangerth Date: Thu, 26 Jan 2023 23:07:09 +0000 (-0700) Subject: Introduce IndexSet::get_index_vector(). X-Git-Tag: v9.5.0-rc1~592^2~4 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f5357ba6837f71449e246d72205a448664e44f7;p=dealii.git Introduce IndexSet::get_index_vector(). --- diff --git a/include/deal.II/base/index_set.h b/include/deal.II/base/index_set.h index 500e19260a..a0084d30ef 100644 --- a/include/deal.II/base/index_set.h +++ b/include/deal.II/base/index_set.h @@ -385,8 +385,22 @@ public: size_type pop_front(); + /** + * Return a vector with all indices contained in this IndexSet. This + * vector may of course be quite large if the IndexSet stores many + * indices. (This may be true even if the IndexSet itself does not + * take up much memory: IndexSet stores indices in a compressed + * format in which contiguous ranges of indices are only stored using + * pairs of indices.) + */ + std::vector + get_index_vector() const; + /** * Fill the given vector with all indices contained in this IndexSet. + * + * This function is equivalent to calling get_index_vector() and + * assigning the result to the @p indices argument. */ void fill_index_vector(std::vector &indices) const; diff --git a/source/base/index_set.cc b/source/base/index_set.cc index 1a47ae2c01..d6aaab50ac 100644 --- a/source/base/index_set.cc +++ b/source/base/index_set.cc @@ -684,12 +684,12 @@ IndexSet::at(const size_type global_index) const -void -IndexSet::fill_index_vector(std::vector &indices) const +std::vector +IndexSet::get_index_vector() const { compress(); - indices.clear(); + std::vector indices; indices.reserve(n_elements()); for (const auto &range : ranges) @@ -697,6 +697,16 @@ IndexSet::fill_index_vector(std::vector &indices) const indices.push_back(entry); Assert(indices.size() == n_elements(), ExcInternalError()); + + return indices; +} + + + +void +IndexSet::fill_index_vector(std::vector &indices) const +{ + indices = get_index_vector(); }