Changeset 3297

Show
Ignore:
Timestamp:
11/06/09 13:58:45 (2 weeks ago)
Author:
kraftche
Message:

Speed up range-based get_adjacencies:

Initial time: 11.92 s
After MBCore changes: 9.42 s
After MBRange changes: 9.32 s

MBCore: more intellegent merges/intersect of range-based data
MBRange: insert single handle with hint

Location:
MOAB/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • MOAB/trunk/MBCore.cpp

    r3273 r3297  
    12171217  MBRange temp_range; 
    12181218  std::vector<MBEntityHandle> temp_vec; 
     1219  std::vector<MBEntityHandle>::const_iterator adj_it; 
    12191220  MBErrorCode result = MB_SUCCESS, tmp_result; 
    12201221 
     
    12351236    if (MB_SUCCESS != tmp_result) result = tmp_result; 
    12361237     
     1238    std::sort( temp_vec.begin(), temp_vec.end() ); 
     1239     
    12371240      // if we're on the first iteration and we didn't come in with entities, 
    12381241      // just get the first results and move on 
    12391242    if (adj_entities.empty() && from_it == from_entities.begin()) { 
    1240       std::copy(temp_vec.begin(), temp_vec.end(), mb_range_inserter(adj_entities)); 
     1243      std::copy(temp_vec.rbegin(), temp_vec.rend(), mb_range_inserter(adj_entities)); 
    12411244      continue; 
    12421245    } 
    12431246 
    12441247      // operate on the vectors 
     1248    MBRange::iterator hint = adj_entities.begin(); 
    12451249    if (operation_type == MBInterface::INTERSECT) { 
    1246         // only have to sort if we're doing intersection 
    1247       std::sort(temp_vec.begin(), temp_vec.end()); 
    1248       std::set_intersection(adj_entities.begin(), adj_entities.end(),  
    1249                             temp_vec.begin(), temp_vec.end(), 
    1250                             mb_range_inserter(temp_range)); 
    1251       adj_entities.swap(temp_range); 
     1250      adj_it = temp_vec.begin(); 
     1251      while (hint != adj_entities.end()) { 
     1252        while (adj_it != temp_vec.end() && *adj_it < *hint) 
     1253          ++adj_it; 
     1254        if (adj_it == temp_vec.end()) { 
     1255          adj_entities.erase( hint, adj_entities.end() ); 
     1256          break; 
     1257        } 
     1258         
     1259        if (*adj_it == *hint) 
     1260          ++hint; 
     1261        else 
     1262          hint = adj_entities.erase(hint); 
     1263      } 
     1264       
     1265        // If doing INTERSECT and the current results are the empty set, 
     1266        // then the final result must also be the empty set.   
     1267      if (adj_entities.empty()) 
     1268        return MB_SUCCESS; 
    12521269    } 
    12531270    else if (operation_type == MBInterface::UNION) { 
    1254       std::copy(temp_vec.begin(), temp_vec.end(), mb_range_inserter(adj_entities)); 
     1271      for (adj_it = temp_vec.begin(); adj_it != temp_vec.end(); ++adj_it) 
     1272        hint = adj_entities.insert( hint, *adj_it ); 
    12551273    } 
    12561274  } 
  • MOAB/trunk/MBRange.cpp

    r3129 r3297  
    232232*/ 
    233233 
    234 MBRange::iterator MBRange::insert(MBEntityHandle val) 
     234MBRange::iterator MBRange::insert( MBRange::iterator hint, MBEntityHandle val ) 
    235235{ 
    236236 
     
    247247  // find the location in the list where we can safely insert 
    248248  // new items and keep it ordered 
    249   PairNode* jter = mHead.mNext; 
     249  PairNode* hter = hint.mNode; 
     250  PairNode* jter = hter->first <= val ? hter : mHead.mNext; 
    250251  for( ; (jter != &mHead) && (jter->second < val); jter=jter->mNext); 
    251252  PairNode* iter = jter; 
     
    300301} 
    301302 
    302  
    303 /*! 
    304   inserts a range of values 
    305 */ 
    306 MBRange::iterator MBRange::insert(MBEntityHandle val1, MBEntityHandle val2) 
    307 { 
    308  
    309   if(val1 == 0 || val1 > val2) 
    310     return end(); 
    311  
    312   return insert( begin(), val1, val2 ); 
    313 } 
    314  
    315303MBRange::iterator MBRange::insert( MBRange::iterator prev, 
    316304                                   MBEntityHandle val1,  
    317305                                   MBEntityHandle val2 ) 
    318306{ 
    319   assert( val1 <= val2 && val1 ); 
     307  if(val1 == 0 || val1 > val2) 
     308    return end(); 
    320309 
    321310  // Empty  
  • MOAB/trunk/MBRange.hpp

    r3110 r3297  
    242242  inline bool empty() const; 
    243243 
     244  iterator insert( iterator hint, MBEntityHandle val ); 
     245 
    244246  //! insert an item into the list and return the iterator for the inserted item 
    245   iterator insert(MBEntityHandle val); 
     247  iterator insert(MBEntityHandle val) 
     248    { return insert( begin(), val ); } 
    246249   
    247250  //! insert a range of items into this list and return the iterator for the first 
    248251  //! inserted item 
    249   iterator insert(MBEntityHandle val1, MBEntityHandle val2); 
     252  iterator insert( iterator hint, MBEntityHandle first, MBEntityHandle last ); 
     253   
     254  //! insert a range of items into this list and return the iterator for the first 
     255  //! inserted item 
     256  iterator insert(MBEntityHandle val1, MBEntityHandle val2) 
     257    { return insert( begin(), val1, val2 ); } 
    250258   
    251259    //! remove an item from this list and return an iterator to the next item 
     
    339347 
    340348  int index(MBEntityHandle handle) const; 
    341    
    342   MBRange::iterator insert( MBRange::iterator prev, 
    343                             MBEntityHandle first, 
    344                             MBEntityHandle last ); 
    345349   
    346350protected: