[MOAB-dev] r2814 - MOAB/trunk

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Fri Apr 10 17:35:19 CDT 2009


Author: kraftche
Date: 2009-04-10 17:35:18 -0500 (Fri, 10 Apr 2009)
New Revision: 2814

Modified:
   MOAB/trunk/RangeMap.hpp
Log:
add some method for testing if RangeMap contains specified key values

Modified: MOAB/trunk/RangeMap.hpp
===================================================================
--- MOAB/trunk/RangeMap.hpp	2009-04-10 22:34:36 UTC (rev 2813)
+++ MOAB/trunk/RangeMap.hpp	2009-04-10 22:35:18 UTC (rev 2814)
@@ -55,6 +55,12 @@
   
   /** Find the value corresponding to the specified key.  Returns NullVal if not found */
   inline ValType find( KeyType key ) const;
+  
+  /** Check if range contains key */
+  inline bool exists( KeyType key ) const;
+  
+  /** Check if range contains key */
+  inline bool intersects( KeyType start, KeyType count ) const;
 
   /** Remove a block of values */
   inline iterator erase( KeyType beg, KeyType count );
@@ -164,6 +170,22 @@
   return i->value + key - i->begin;
 }
 
+template <typename KeyType, typename ValType, ValType NullVal> inline
+bool RangeMap<KeyType,ValType,NullVal>::exists( KeyType key ) const
+{
+  Range search = { key, 1, NullVal };
+  typename RangeList::const_iterator i = std::lower_bound( data.begin(), data.end(), search );
+  return i != data.end() && key >= i->begin;
+}
+
+template <typename KeyType, typename ValType, ValType NullVal> inline 
+bool RangeMap<KeyType,ValType,NullVal>::intersects( KeyType start, KeyType count ) const
+{
+  Range search = { start, count, NullVal };
+  typename RangeList::const_iterator i = std::lower_bound( data.begin(), data.end(), search );
+  return i != data.end() && start + count > i->begin && i->begin+i->count > start;
+}
+
 template <typename KeyType, typename ValType, ValType NullVal>
 inline typename RangeMap<KeyType,ValType,NullVal>::iterator
 RangeMap<KeyType,ValType,NullVal>::erase( KeyType key, KeyType count )



More information about the moab-dev mailing list