//---------------------------------------------------------------- // File and Version Information: // $Id: AstSTLMap.cc,v 1.2 2006/06/30 11:24:22 steinke Exp $ // // Description: // Implementation of AstSTLMap class. // // Author List: // Luca Lista 26 Mar 97 // // Bertram Kopf (RUB) migrated to PandaRoot //--------------------------------------------------------------- //----------------------- // This Class's Header -- //----------------------- #include "AstSTLMap.h" //------------- // C Headers -- //------------- extern "C" { } //--------------- // C++ Headers -- //--------------- #include #include #include //------------------------------- // Collaborating Class Headers -- //------------------------------- //----------------------------------------------------------------------- // Local Macros, Typedefs, Structures, Unions and Forward Declarations -- //----------------------------------------------------------------------- // ---------------------------------------- // -- Public Function Member Definitions -- // ---------------------------------------- //---------------- // Constructors -- //---------------- template AstSTLMap::AstSTLMap(size_t buckets) : AstAbsSTLMap(buckets), _allT2(new std::vector()) {} template AstSTLMap::AstSTLMap(unsigned (*hashFunction)(T1 *const &), size_t buckets) : AstAbsSTLMap(hashFunction, buckets), _allT2(new std::vector()) {} //-------------- // Destructor -- //-------------- template AstSTLMap::~AstSTLMap() { delete _allT2; } //------------- // Modifiers -- //------------- template void AstSTLMap::appendToMap( T1* const & t1ref, T2* const & t2ref){ (*this)[t1ref].push_back(t2ref); _allT2->push_back(t2ref); } template bool AstSTLMap::findIntersectionSet(const std::set &withThis, std::vector &returned) const{ // First construct a dummy hash set since the intersection function modifies self. std::set dummy; return findIntersectionSet(withThis, returned, dummy); } template bool AstSTLMap::findIntersectionSet(const std::set &withThis, std::vector &returned, std::set &returnedSet) const{ if (!AstAbsSTLMap::findIntersectionSet(withThis, returnedSet)) return false; typename std::set::iterator iter = returnedSet.begin(); while(iter != returnedSet.end()){ std::vector contained; typename std::map >::const_iterator position; if ((position = find(*iter)) != AstSTLMap::end()) { contained = position->second; // RW Ordered Vector cannot append one of itself! for (size_t i=0; i bool AstSTLMap::findIntersectionSet(const std::vector &vector, std::vector &returned) const{ std::set inputVector; for (size_t i= 0; i bool AstSTLMap::findDifferenceSet(const std::set &withThis, std::vector &returned) const{ std::set dummy; return findDifferenceSet(withThis, returned, dummy); } template bool AstSTLMap::findDifferenceSet(const std::set &withThis, std::vector &returned, std::set &returnedSet) const{ if (!AstAbsSTLMap::findDifferenceSet(withThis, returnedSet)) return false; typename std::set::iterator iter = returnedSet.begin(); // while(iter != returnedSet.end()){ if ( find(*iter) != AstSTLMap::end()) { // Bertram: replaced upper line by this line std::vector contained = find(*iter)->second; for (size_t i=0; i bool AstSTLMap::findDifferenceSet(const std::vector &vector, std::vector &returned) const{ std::set inputVector; for (size_t i= 0; i AstSTLMap & AstSTLMap::unionMap(const AstSTLMap &withThis){ typename std::set::iterator iter = withThis.hashSetT1()->begin(); while (iter != withThis.hashSetT1()->end()) { AstSTLMap::hashSetT1()->insert(*iter); ++iter; } iter = AstSTLMap::hashSetT1()->begin(); while (iter != AstSTLMap::hashSetT1()->end()){ // Only add new contents. Do not want overwrites if (find(*iter) == AstSTLMap::end()) { std::vector retVal = withThis.find(*iter)->second; (*this)[*iter] = retVal; } ++iter; } // It's more efficient to clear the T2 list and re-write it // than to remove specific objects. _allT2->clear(); typename std::map >::iterator iterator = AstSTLMap::begin(); while (iterator != AstSTLMap::end()) { std::vector addThese = iterator->second; for (size_t i= 0; ipush_back(addThese[i]); ++iterator; } return *this; } template AstSTLMap & AstSTLMap::intersectionMap(const AstSTLMap &withThis){ std::set result; typename std::set::iterator iter = withThis.hashSetT1()->begin(); while (iter != withThis.hashSetT1()->end()) { if (AstSTLMap::hashSetT1()->find(*iter) != AstSTLMap::hashSetT1()->end()) result.insert(*iter); ++iter; } AstSTLMap::hashSetT1()->clear(); (*(AstSTLMap::hashSetT1())) = result; iter = AstSTLMap::hashSetT1()->begin(); while (iter != AstSTLMap::hashSetT1()->end()){ // Only add new contents. Do not want overwrites if (find(*iter) == AstSTLMap::end()) { std::vector retVal = withThis.find(*iter)->second; (*this)[*iter] = retVal; } ++iter; } _allT2->clear(); typename std::map >::iterator iterator = AstSTLMap::begin(); while (iterator != AstSTLMap::end()) { std::vector addThese = iterator->second; for (size_t i= 0; ipush_back(addThese[i]); ++iterator; } return *this; }