*/
void compress () const;
+ /**
+ * Comparison for equality of
+ * index sets. This operation is
+ * only allowed if the size of
+ * the two sets is the same
+ * (though of course they do not
+ * have to have the same number
+ * of indices).
+ */
+ bool operator == (const IndexSet &is) const;
+
+ /**
+ * Comparison for inequality of
+ * index sets. This operation is
+ * only allowed if the size of
+ * the two sets is the same
+ * (though of course they do not
+ * have to have the same number
+ * of indices).
+ */
+ bool operator != (const IndexSet &is) const;
+
+ /**
+ * Return the intersection of the
+ * current index set and the
+ * argument given, i.e. a set of
+ * indices that are elements of
+ * both index sets. The two index
+ * sets must have the same size
+ * (though of course they do not
+ * have to have the same number
+ * of indices).
+ */
+ IndexSet operator & (const IndexSet &is) const;
+
#ifdef DEAL_II_USE_TRILINOS
/**
* Given an MPI communicator,
&&
(range_1.end < range_2.end)));
}
+
+ friend
+ inline bool operator== (const Range &range_1,
+ const Range &range_2)
+ {
+ return ((range_1.begin == range_2.begin)
+ ||
+ (range_1.begin == range_2.begin));
+ }
};
/**
+inline
+bool
+IndexSet::operator == (const IndexSet &is) const
+{
+ Assert (size() == is.size(),
+ ExcDimensionMismatch (size(), is.size()));
+
+ compress ();
+ is.compress ();
+
+ return ranges == is.ranges;
+}
+
+
+
+inline
+bool
+IndexSet::operator != (const IndexSet &is) const
+{
+ Assert (size() == is.size(),
+ ExcDimensionMismatch (size(), is.size()));
+
+ compress ();
+ is.compress ();
+
+ return ranges != is.ranges;
+}
+
+
+
+inline
+IndexSet
+IndexSet::operator & (const IndexSet &is) const
+{
+ Assert (size() == is.size(),
+ ExcDimensionMismatch (size(), is.size()));
+
+ compress ();
+ is.compress ();
+
+ std::vector<Range>::const_iterator r1 = ranges.begin(),
+ r2 = is.ranges.begin();
+ IndexSet result (size());
+
+ while ((r1 != ranges.end())
+ &&
+ (r2 != is.ranges.end()))
+ {
+ // if r1 and r2 do not overlap
+ // at all, then move the
+ // pointer that sits to the
+ // left of the other up by one
+ if (r1->end <= r2->begin)
+ ++r1;
+ else if (r2->end <= r1->begin)
+ ++r2;
+ else
+ {
+ // the ranges must overlap
+ // somehow
+ Assert (((r1->begin <= r2->begin) &&
+ (r1->end > r2->begin))
+ ||
+ ((r2->begin <= r1->begin) &&
+ (r2->end > r1->begin)),
+ ExcInternalError());
+
+ // add the overlapping
+ // range to the result
+ result.add_range (std::max (r1->begin,
+ r2->begin),
+ std::min (r1->end,
+ r2->end));
+
+ // now move that iterator
+ // that ends earlier one
+ // up. note that it has to
+ // be this one because a
+ // subsequent range may
+ // still have a chance of
+ // overlapping with the
+ // range that ends later
+ if (r1->end <= r2->end)
+ ++r1;
+ else
+ ++r2;
+ }
+ }
+
+ result.compress ();
+ return result;
+}
+
+
+
DEAL_II_NAMESPACE_CLOSE
--- /dev/null
+//-----------------------------------------------------------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2009 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//-----------------------------------------------------------------------------
+
+// test IndexSet::operator &
+
+#include "../tests.h"
+#include <iomanip>
+#include <iomanip>
+#include <fstream>
+#include <cmath>
+
+#include <base/index_set.h>
+
+
+void test ()
+{
+ IndexSet is1 (20);
+ IndexSet is2 (20);
+
+ is1.add_index (2);
+ is1.add_index (3);
+ is1.add_index (4);
+ is1.add_index (6);
+ is1.add_index (7);
+
+ is2.add_range (4,9);
+
+ IndexSet is3 = is1 & is2;
+
+ for (unsigned int i=0; i<is3.size(); ++i)
+ {
+ deallog << i << ' ' << (is3.is_element(i) ? "true" : "false")
+ << std::endl;
+
+ Assert ((is1.is_element(i) && is2.is_element(i))
+ ==
+ is3.is_element(i),
+ ExcInternalError());
+ }
+
+ // some sanity tests
+ Assert ((is1 & is2) == (is2 & is1), ExcInternalError());
+ Assert ((is1 & is3) == (is2 & is3), ExcInternalError());
+ Assert ((is1 & is3) == is3, ExcInternalError());
+ Assert ((is3 & is1) == is3, ExcInternalError());
+ Assert ((is3 & is3) == is3, ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+
+int main()
+{
+ std::ofstream logfile("index_set_13/output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ test ();
+}