Superclass for merge management objects. More...
#include <tpie/merge.h>
Superclass for merge management objects.
A merge management object class must inherit from merge_base:
template<class T> class MergeMgr: public merge_base;
In addition, a merge management object must provide initialize() and operate() member functions, whose purposes are analogous to their namesakes for scan management objects. ()
err initialize(arity_t arity, const T * const *in, merge_flag *taken_flags, int &taken_index);
where arity
is the number of input streams in the merge, in
is a pointer to an array of pointers to input objects, each of which is the first objects appearing in one of the input streams, taken_flags
an array of flags indicating which of the inputs are present (i.e. which of the input streams is not empty), and a pointer to an output object.
The typical behavior of initialize() is to place all the input objects into a data structure and then return MERGE_READ_MULTIPLE to indicate that it used (and is now finished with) all of the inputs which were indicated to be valid by taken_flags
. initialize need not process all inputs; it can turn off any flags in taken_flags
corresponding to inputs that should be presented to operate(). Alternatively, it can set taken_index
to the index of a single input it processed and return MERGE_CONTINUE.
err operate(const T * const *in, merge_flag *taken_flags, int &taken_index, T *out);
The operate() member function is called repeatedly to process input objects. Typically, operate() will choose a single input object to process, and set taken_index
to the index of the pointer to that object in the input array. This object is then typically added to a dynamic data structure maintained by the merge management object. If output is generated, for example by removing an object from the dynamic data structure, operate() should return MERGE_OUTPUT, otherwise, it returns either MERGE_CONTINUE to indicate that more input should be presented, or MERGE_DONE to indicate that the merge has completed.
Alternatively, operate() can clear the elements of taken_flags
that correspond to inputs it does not currently wish to process, and then return MERGE_READ_MULTIPLE. This is generally undesirable because, if only one input is taken, it is far slower than using taken_index
to indicate which input was taken. The merge management object must clear all other flags, and then TPIE must test all the flags to see which inputs were or were not processed.