//---------------------------------------------------------------------------
// $Id$
//
-// Copyright (C) 2009, 2010, 2011 by the deal.II authors
+// Copyright (C) 2009, 2010, 2011, 2012 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
*/
IndexSet (const unsigned int size);
+ /**
+ * Remove all indices from this
+ * index set. The index set retains
+ * its size, however.
+ */
+ void clear ();
+
/**
* Set the maximal size of the
* indices upon which this object
* This function can only be
* called if the index set does
* not yet contain any elements.
+ * This can be achieved by calling
+ * clear(), for example.
*/
void set_size (const unsigned int size);
* *this and @p other.
*/
void add_indices(const IndexSet & other);
-
+
/**
* Return whether the specified
* index is an element of the
DeclException1 (ExcIndexNotPresent, int,
<< "The global index " << arg1
<< " is not an element of this set.");
-
+
/**
- * Write or read the data of this object to or
+ * Write or read the data of this object to or
* from a stream for the purpose of serialization
- */
+ */
template <class Archive>
void serialize (Archive & ar, const unsigned int version);
* never get to see an invalid range in the wild.
**/
Range ();
-
+
/**
* Constructor. Create a half-open interval with the given indices.
*
{
return sizeof(Range);
}
-
+
/**
- * Write or read the data of this object to or
+ * Write or read the data of this object to or
* from a stream for the purpose of serialization
- */
+ */
template <class Archive>
void serialize (Archive & ar, const unsigned int version);
};
+inline
+void
+IndexSet::clear ()
+{
+ ranges.clear ();
+ largest_range = 0;
+ is_compressed = true;
+}
+
+
inline
void
IndexSet::set_size (const unsigned int sz)
{
if (this == &other)
return;
-
+
for (std::vector<Range>::iterator range = other.ranges.begin();
range != other.ranges.end();
++range)
// of the following ranges
// because otherwise p would be
// a different iterator
- //
+ //
// since we already know the position
// relative to the largest range (we
// called compress!), we can perform
std::vector<Range>::const_iterator
p = std::upper_bound (ranges.begin() + (index<ranges[largest_range].begin?
0 : largest_range+1),
- index<ranges[largest_range].begin ?
+ index<ranges[largest_range].begin ?
ranges.begin() + largest_range:
ranges.end(),
Range (index, size()+1));
Range & r = ranges.back();
v = r.nth_index_in_set + r.end - r.begin;
}
-
-#ifdef DEBUG
+
+#ifdef DEBUG
unsigned int s = 0;
for (std::vector<Range>::iterator range = ranges.begin();
range != ranges.end();
++range)
s += (range->end - range->begin);
Assert(s==v, ExcInternalError());
-#endif
-
+#endif
+
return v;
}
range_end = ranges.end();
}
- std::vector<Range>::const_iterator
+ std::vector<Range>::const_iterator
p = Utilities::lower_bound(range_begin, range_end, r,
Range::nth_index_compare);
range_end = ranges.end();
}
- std::vector<Range>::const_iterator
+ std::vector<Range>::const_iterator
p = Utilities::lower_bound(range_begin, range_end, r,
Range::end_compare);
--- /dev/null
+//-----------------------------------------------------------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2009, 2012 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::clear
+
+#include "../tests.h"
+#include <iomanip>
+#include <iomanip>
+#include <fstream>
+#include <cmath>
+
+#include <deal.II/base/index_set.h>
+
+
+void test ()
+{
+ IndexSet index_set (20);
+ index_set.add_range (2,4);
+ index_set.add_range (12,18);
+ index_set.add_index (6);
+ index_set.add_index (8);
+ index_set.add_index (14);
+ index_set.add_index (16);
+
+ // clear the IndexSet and then set elements
+ // again
+ index_set.clear ();
+
+ index_set.add_range (2,4);
+ index_set.add_range (12,18);
+ index_set.add_index (6);
+ index_set.add_index (8);
+ index_set.add_index (14);
+ index_set.add_index (16);
+
+ for (unsigned int i=0; i<index_set.size(); ++i)
+ deallog << i << ' ' << (index_set.is_element(i) ? "true" : "false")
+ << std::endl;
+}
+
+
+
+
+int main()
+{
+ std::ofstream logfile("index_set_21/output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ test ();
+}