Created
May 25, 2014 12:49
-
-
Save ryanjdew/cce1d7cc87c860336657 to your computer and use it in GitHub Desktop.
C++ finish MarkLogic UDF function
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
template<class T> | |
void Bucketeer<T>:: | |
finish(OutputSequence& os, Reporter& reporter) | |
{ | |
// start the MarkLogic map | |
os.startMap(); | |
// interate over the unique keys | |
// note the use of buckets.upper_bound() to ensure we get a key only once | |
for (typename std::multimap<String, T>::iterator it = buckets.begin(); it != buckets.end(); it = buckets.upper_bound(it->first)) { | |
std::pair <typename std::multimap<String,T>::iterator, typename std::multimap<String,T>::iterator> ret; | |
// get the range for the key values | |
ret = buckets.equal_range(it->first); | |
// write the map key | |
os.writeMapKey(it->first); | |
// iterate over the values for current key | |
for (typename std::multimap<String, T>::iterator it2 = ret.first; it2 != ret.second; ++it2) { | |
// write the value | |
os.writeValue(it2->second); | |
} | |
} | |
os.endMap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment