[MOAB-dev] r3880 - MOAB/trunk/src/moab
kraftche at cae.wisc.edu
kraftche at cae.wisc.edu
Tue May 11 13:46:27 CDT 2010
Author: kraftche
Date: 2010-05-11 13:46:26 -0500 (Tue, 11 May 2010)
New Revision: 3880
Modified:
MOAB/trunk/src/moab/Range.hpp
Log:
add templatized method for fast insertion of any other container into an Range
Modified: MOAB/trunk/src/moab/Range.hpp
===================================================================
--- MOAB/trunk/src/moab/Range.hpp 2010-05-11 17:02:12 UTC (rev 3879)
+++ MOAB/trunk/src/moab/Range.hpp 2010-05-11 18:46:26 UTC (rev 3880)
@@ -172,6 +172,7 @@
#include <iterator>
#include <iosfwd>
+#include <algorithm>
#include "moab/Types.hpp"
namespace moab {
@@ -257,6 +258,17 @@
//! inserted item
iterator insert(EntityHandle val1, EntityHandle val2)
{ return insert( begin(), val1, val2 ); }
+
+ template <typename T>
+ iterator insert_list( T begin_iter, T end_iter );
+
+ template <class T>
+ iterator insert( typename T::const_iterator begin_iter, typename T::const_iterator end_iter )
+ { return insert_list( begin_iter, end_iter ); }
+
+ template <typename T>
+ iterator insert( const T* begin_iter, const T* end_iter )
+ { return insert_list( begin_iter, end_iter ); }
//! remove an item from this list and return an iterator to the next item
iterator erase(iterator iter);
@@ -803,6 +815,26 @@
i += index;
return *i;
}
+
+template <typename Iterator>
+Range::iterator Range::insert_list( Iterator begin_iter, Iterator end_iter )
+{
+ size_t n = std::distance(begin_iter, end_iter);
+ EntityHandle* sorted = new EntityHandle[n];
+ std::copy( begin_iter, end_iter, sorted );
+ std::sort( sorted, sorted + n );
+ iterator hint = begin();
+ size_t i;
+ while (i < n) {
+ size_t j = i + 1;
+ while (j < n && sorted[j] == 1+sorted[j-1])
+ ++j;
+ hint = insert( hint, sorted[i], sorted[i] + ((j - i) - 1) );
+ i = j;
+ }
More information about the moab-dev
mailing list