[MOAB-dev] r2656 - in MOAB/trunk: . m4

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Tue Feb 24 12:00:34 CST 2009


Author: kraftche
Date: 2009-02-24 12:00:34 -0600 (Tue, 24 Feb 2009)
New Revision: 2656

Modified:
   MOAB/trunk/SparseTagCollection.cpp
   MOAB/trunk/SparseTagCollection.hpp
   MOAB/trunk/m4/cplusplus.m4
Log:
Check in the rest of the std::unordered_map SparseTag stuff, as I already
accidentally checked in part of it.


Modified: MOAB/trunk/SparseTagCollection.cpp
===================================================================
--- MOAB/trunk/SparseTagCollection.cpp	2009-02-24 16:52:13 UTC (rev 2655)
+++ MOAB/trunk/SparseTagCollection.cpp	2009-02-24 18:00:34 UTC (rev 2656)
@@ -44,7 +44,7 @@
 {
   void* tag_data = NULL;
 
-  std::map<MBEntityHandle, void*>::iterator tag_iterator;
+  myMapType::iterator tag_iterator;
   for(tag_iterator = mData.begin(); tag_iterator != mData.end(); ++tag_iterator)
   {
     tag_data = tag_iterator->second;
@@ -63,8 +63,11 @@
 
   MBErrorCode ret_val = MB_TAG_NOT_FOUND;
 
-  std::map<MBEntityHandle, void*>::iterator iterator =
-    mData.lower_bound(entity_handle);
+#ifdef HAVE_UNORDERED_MAP
+  myMapType::iterator iterator = mData.find(entity_handle);
+#else
+  myMapType::iterator iterator = mData.lower_bound(entity_handle);
+#endif
   
   // data space already exists
   if (iterator!= mData.end() && iterator->first == entity_handle)
@@ -89,8 +92,7 @@
   if (mDataSize == MB_VARIABLE_LENGTH)
     return MB_VARIABLE_DATA_LENGTH;
 
-  std::map<MBEntityHandle, void*>::iterator iter =
-    mData.find(entity_handle);
+  myMapType::iterator iter = mData.find(entity_handle);
 
   if(iter == mData.end())
     return MB_TAG_NOT_FOUND;
@@ -101,8 +103,11 @@
 
 MBErrorCode SparseTagCollection::set_data(const MBEntityHandle entity_handle, const void* data, int size)
 {
-  std::map<MBEntityHandle, void*>::iterator iterator =
-    mData.lower_bound(entity_handle);
+#ifdef HAVE_UNORDERED_MAP
+  myMapType::iterator iterator = mData.find(entity_handle);
+#else
+  myMapType::iterator iterator = mData.lower_bound(entity_handle);
+#endif
   
   if (mDataSize == MB_VARIABLE_LENGTH) {
     if (size == 0) {
@@ -134,8 +139,7 @@
 
 MBErrorCode SparseTagCollection::get_data(const MBEntityHandle entity_handle, const void*& data, int& size)
 {
-  std::map<MBEntityHandle, void*>::iterator iter =
-    mData.find(entity_handle);
+  myMapType::iterator iter = mData.find(entity_handle);
 
   if(iter == mData.end())
     return MB_TAG_NOT_FOUND;
@@ -156,8 +160,7 @@
 
 MBErrorCode SparseTagCollection::remove_data( const MBEntityHandle entity_handle )
 {
-  std::map<MBEntityHandle, void*>::iterator iterator =
-    mData.find(entity_handle);
+  myMapType::iterator iterator = mData.find(entity_handle);
 
   if(iterator != mData.end())
   {
@@ -175,7 +178,7 @@
 MBErrorCode SparseTagCollection::get_number_entities(MBEntityType type, int& num_entities)
 {
   num_entities = 0;
-  std::map<MBEntityHandle, void*>::iterator iter;
+  myMapType::iterator iter;
   for(iter = mData.begin(); iter != mData.end(); ++iter)
   {
     if(TYPE_FROM_HANDLE(iter->first) == type)
@@ -187,7 +190,7 @@
 //! gets all entity handles that match a type and tag
 MBErrorCode SparseTagCollection::get_entities(MBEntityType type, MBRange &entities)
 {
-  std::map<MBEntityHandle, void*>::iterator iter;
+  myMapType::iterator iter;
   for(iter = mData.begin(); iter != mData.end(); ++iter)
   {
     if(TYPE_FROM_HANDLE(iter->first) == type)
@@ -205,11 +208,26 @@
                                                     const void* tag_value,
                                                     int value_size)
 {
-  std::map<MBEntityHandle, void*>::iterator iter, end;
+  myMapType::iterator iter, end;
+#ifdef HAVE_UNORDERED_MAP
+  iter = mData.begin();
+  end = mData.end();
+  while(iter != end) {
+    while (iter != end && TYPE_FROM_HANDLE(iter->first) != type)
+      ++iter;
+    myMapType::iterator iter2 = iter;
+    while (iter2 != end && TYPE_FROM_HANDLE(iter2->first) == type)
+      ++iter2;
+    find_tag_values_equal( tag_info, tag_value, value_size, iter, iter2, entities );
+    iter = iter2;
+  }
+    
+#else
   int junk;
   iter = mData.lower_bound( CREATE_HANDLE( type, MB_START_ID, junk ) );
   end = mData.upper_bound( CREATE_HANDLE( type, MB_END_ID, junk ) );
   find_tag_values_equal( tag_info, tag_value, value_size, iter, end, entities );
+#endif
   return MB_SUCCESS;
 }
 

Modified: MOAB/trunk/SparseTagCollection.hpp
===================================================================
--- MOAB/trunk/SparseTagCollection.hpp	2009-02-24 16:52:13 UTC (rev 2655)
+++ MOAB/trunk/SparseTagCollection.hpp	2009-02-24 18:00:34 UTC (rev 2656)
@@ -39,7 +39,14 @@
 #pragma warning(disable : 4786)
 #endif
 
-#include <map>
+
+#define STRINGIFY_(X) #X
+#define STRINGIFY(X) STRINGIFY_(X)
+#ifdef HAVE_UNORDERED_MAP
+# include STRINGIFY(HAVE_UNORDERED_MAP)
+#else
+# include <map>
+#endif
 #include <vector>
 
 #include "MBTypes.h"
@@ -134,8 +141,13 @@
   SparseTagDataAllocator mAllocator;
 
   //! map of entity id and tag data
-  std::map<MBEntityHandle /*entity_handle*/ , void* /*data*/ > mData;
+#ifdef HAVE_UNORDERED_MAP
+  typedef UNORDERED_MAP_NS::unordered_map<MBEntityHandle,void*> myMapType;
+#else
+  typedef std::map<MBEntityHandle /*entity_handle*/ , void* /*data*/ > myMapType;
+#endif
 
+  myMapType mData;
 };
 
 inline bool SparseTagCollection::contains(const MBEntityHandle entity) const
@@ -145,8 +157,7 @@
 
 inline MBErrorCode SparseTagCollection::get_entities(MBRange &entities) const 
 {
-  for (std::map<MBEntityHandle,void*>::const_iterator mit = mData.begin();
-       mit != mData.end(); mit++) 
+  for (myMapType::const_iterator mit = mData.begin(); mit != mData.end(); mit++) 
     entities.insert((*mit).first);
 
   return MB_SUCCESS;

Modified: MOAB/trunk/m4/cplusplus.m4
===================================================================
--- MOAB/trunk/m4/cplusplus.m4	2009-02-24 16:52:13 UTC (rev 2655)
+++ MOAB/trunk/m4/cplusplus.m4	2009-02-24 18:00:34 UTC (rev 2656)
@@ -1,4 +1,38 @@
 #######################################################################################
+# Check for existance unordered_map in either std:: or std::tr1:: namespace
+# Executes first argument if found, second if not found.  If unordered_map
+# is found, the variable 'result' will contain its namespace.
+#######################################################################################
+AC_DEFUN([MK_CHECK_UNORDERED_MAP],[
+
+AC_CACHE_CHECK([for C++ unordered_map],
+               [mk_cv_cxx_unordered_map],
+               [AC_LANG_PUSH(C++)
+                mk_cv_cxx_unordered_map=no
+                AC_TRY_COMPILE([#include <unordered_map>],
+                               [std::unordered_map<int,int> map],
+                               [mk_cv_cxx_unordered_map="std"; incdir=])
+                if test "xno" == "x$mk_cv_cxx_unordered_map"; then
+                  AC_TRY_COMPILE([#include <tr1/unordered_map>],
+                                 [std::tr1::unordered_map<int,int> map],
+                                 [mk_cv_cxx_unordered_map="std::tr1"; incdir=tr1/])
+                fi
+                if test "xno" == "x$mk_cv_cxx_unordered_map"; then
+                  AC_TRY_COMPILE([#include <boost/unordered_map>],
+                                 [boost::unordered_map<int,int> map],
+                                 [mk_cv_cxx_unordered_map="boost"; incdir=boost/])
+                fi
+                AC_LANG_POP(C++)])
+if test "xno" != "x$mk_cv_cxx_unordered_map"; then
+  result="$mk_cv_cxx_unordered_map"
+  $1
+else
+  result=
+  $2
+fi
+])  
+
+#######################################################################################
 # Check for existance of new no-file-extension C++ headers.
 # Conditinionally sets the following preprocessor macros:
 #   CANT_USE_STD



More information about the moab-dev mailing list