TPIE

v1.1rc1-6-g0c97303
tpie::ami::merge_base< T > Class Template Reference

Superclass for merge management objects. More...

#include <tpie/merge.h>

Detailed Description

template<class T>
class tpie::ami::merge_base< T >

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. ()

initialize()
The user's initialize() member function is called by the merge function once so that application-specific data structures (if any) can be initialized.

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.

()

operate()
When performing a merge, TPIE relies on the application programmer to provide code to determine the order of any two application data elements, and certain other application-specific processing. By convention, TPIE expects these decisions to be made by the operate() function:

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.

Definition at line 69 of file merge.h.


The documentation for this class was generated from the following file: