*/
bool is_contiguous () const;
+ /**
+ * Return whether the index set stored by this object contains no elements.
+ * This is similar, but faster than checking <code>n_elements() == 0</code>.
+ */
+ bool is_empty () const;
+
/**
* Return whether the IndexSets are ascending with respect to MPI process
* number and 1:1, i.e., each index is contained in exactly one IndexSet
*/
void subtract_set (const IndexSet &other);
+ /**
+ * Removes and returns the last element of the last range.
+ * Throws an exception if the IndexSet is empty.
+ */
+ size_type pop_back ();
+
+ /**
+ * Removes and returns the first element of the first range.
+ * Throws an exception if the IndexSet is empty.
+ */
+ size_type pop_front ();
+
/**
* Fills the given vector with all indices contained in this IndexSet.
*/
}
+inline
+bool
+IndexSet::is_empty () const
+{
+ return ranges.empty();
+}
+
+
inline
IndexSet::size_type
+IndexSet::size_type
+IndexSet::pop_back ()
+{
+ Assert(ranges.size() != 0,
+ ExcMessage("pop_back() failed, because this IndexSet contains no entries."));
+
+ const size_type index = ranges.back().end-1;
+ --ranges.back().end;
+
+ if (ranges.back().begin == ranges.back().end)
+ ranges.pop_back();
+
+ return index;
+}
+
+
+
+IndexSet::size_type
+IndexSet::pop_front ()
+{
+ Assert(ranges.size() != 0,
+ ExcMessage("pop_front() failed, because this IndexSet contains no entries."));
+
+ const size_type index = ranges.front().begin;
+ ++ranges.front().begin;
+
+ if (ranges.front().begin == ranges.front().end)
+ ranges.erase(ranges.begin());
+
+ // We have to set this in any case, because nth_index_in_set is not longer
+ // up to date for all but the first range
+ is_compressed = false;
+
+ return index;
+}
+
+
+
void
IndexSet::add_indices(const IndexSet &other,
const unsigned int offset)
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2010 - 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+// Check that pop_front() for `IndexSet` works properly
+
+#include "../tests.h"
+#include <fstream>
+
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/index_set.h>
+
+int main()
+{
+ std::ofstream logfile("output");
+ deallog.attach(logfile);
+
+ IndexSet is1(10);
+ is1.add_range(0, 2);
+ is1.add_range(5,8);
+
+ deallog << is1.n_elements() << ", " << is1.pop_front() << std::endl;
+ deallog << is1.n_elements() << ", " << is1.pop_front() << std::endl;
+ deallog << is1.n_elements() << ", " << is1.pop_front() << std::endl;
+
+ is1.add_index(1);
+
+ deallog << is1.n_elements() << ", " << is1.pop_front() << std::endl;
+ deallog << is1.n_elements() << ", " << is1.pop_front() << std::endl;
+}
--- /dev/null
+
+DEAL::4, 0
+DEAL::3, 1
+DEAL::2, 5
+DEAL::2, 1
+DEAL::1, 6
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2010 - 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+// Check that pop_back() for `IndexSet` works properly
+
+#include "../tests.h"
+#include <fstream>
+
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/index_set.h>
+
+int main()
+{
+ std::ofstream logfile("output");
+ deallog.attach(logfile);
+
+ IndexSet is1(10);
+ is1.add_range(0, 2);
+ is1.add_range(5,8);
+
+ deallog << is1.n_elements() << ", " << is1.pop_back() << std::endl;
+ deallog << is1.n_elements() << ", " << is1.pop_back() << std::endl;
+ deallog << is1.n_elements() << ", " << is1.pop_back() << std::endl;
+
+ is1.add_index(9);
+
+ deallog << is1.n_elements() << ", " << is1.pop_back() << std::endl;
+ deallog << is1.n_elements() << ", " << is1.pop_back() << std::endl;
+}
--- /dev/null
+
+DEAL::4, 7
+DEAL::3, 6
+DEAL::2, 5
+DEAL::2, 9
+DEAL::1, 1