"MapReduce-MPI WWW Site"_mws - "MapReduce-MPI Documentation"_md :c

:link(mws,http://www.cs.sandia.gov/~sjplimp/mapreduce.html)
:link(md,Manual.html)

:line

MapReduce sort_values() method :h3

int MapReduce::sort_values(int (*mycompare)(char *, int, char *, int)) :pre

This calls the sort_values() method of a MapReduce object, which sorts
a KeyValue object by its values to produce a new KeyValue object.  The
mycompare() function you provide compares pairs of values for the
sort, since the MapReduce object does not know how to interpret the
content of your values.  The method returns the total number of
key/value pairs in the new KeyValue object which will be the same as
in the original.

This method is used to sort key/value pairs by value before a KeyValue
object is transformed into a KeyMultiValue object, e.g. via the
"clone()"_clone.html, "collapse()"_collapse.html, or
"convert()"_convert.html methods.  Note that these operations preserve
the order of pairs in the KeyValue object when creating a
KeyMultiValue object, which can then be passed to your application for
output, e.g. via the "reduce()"_reduce.html method.  Note however,
that sort_values() does NOT sort values across all processors but only
sorts the values on each processor within the KeyValue object.  Thus
if you "gather()"_gather.html or "aggregate()"_aggregate.html after
performing a sort_values(), the sorted order will be lost, since those
methods move key/value pairs to new processors.

In this example the user function is called mycompare() and it must
have the following interface

int mycompare(char *value1, int len1, char *value2, int len2) :pre

Value1 and value2 are pointers to the byte strings for 2 values, each
of length len1 and len2.  Your function should compare them and return
a -1, 0, or 1 if value1 is less than, equal to, or greater than
value2, respectively.

This method is an on-processor operation, requiring no communication.
When run in parallel, each processor operates only on the key/value
pairs it stores.

:line

[Related methods]: "sort_keys()"_sort_keys.html,
"sort_multivalues()"_sort_multivalues.html
