Last active
December 16, 2015 15:39
-
-
Save superwills/5457289 to your computer and use it in GitHub Desktop.
Reverses a mapping of map: T -> vector<S> to map: S -> vector<T>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reverses a mapping of map: T -> vector<S> to map: S -> vector<T> | |
template<typename T, typename S> | |
void reverseMapping( map< T, vector<S> >& oMapping, map< S, vector<T> >& revMapping ) | |
{ | |
for( typename map< T, vector<S> >::iterator iter = oMapping.begin() ; iter != oMapping.end() ; ++iter ) | |
{ | |
for( int i = 0 ; i < iter->second.size() ; i++ ) | |
{ | |
pair< typename map< S, vector<T> >::iterator, bool > res = | |
revMapping.insert( make_pair( iter->second[i], vector<T>() ) ) ; | |
res.first->second.push_back( iter->first ) ; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment