Skip to content

Instantly share code, notes, and snippets.

@ryanjdew
Created May 25, 2014 12:49
Show Gist options
  • Save ryanjdew/cce1d7cc87c860336657 to your computer and use it in GitHub Desktop.
Save ryanjdew/cce1d7cc87c860336657 to your computer and use it in GitHub Desktop.
C++ finish MarkLogic UDF function
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