20 #ifndef _MERGE_SORTED_RUNS_H
21 #define _MERGE_SORTED_RUNS_H
38 #include <tpie/file_stream.h>
72 template <
class T,
class M>
76 TPIE_OS_OFFSET cutoff=-1,
80 size_t arity = end-start;
91 for (i = 0; i < arity; i++) {
94 in_objects[i] = &stream->
read();
95 MergeHeap->insert( in_objects[i], i );
99 if (indicator) indicator->step();
106 MergeHeap->initialize ( );
111 while (MergeHeap->sizeofheap() > 0) {
112 i = MergeHeap->get_min_run_id ();
113 outStream->write(*in_objects[i]);
118 if ( (cutoff != -1) && (nread[i]>=cutoff))
122 if (stream->
can_read()) in_objects[i] = &stream->
read();
125 if (indicator) indicator->step();
129 MergeHeap->delete_min_and_insert(NULL);
132 MergeHeap->delete_min_and_insert (in_objects[i]);
150 template <
class T,
class CMPR>
182 template <
class T,
class CMPR>
204 #endif //_MERGE_SORTED_RUNS_H
The base class for indicating the progress of some task.
A generic array with a fixed size.
bool can_read()
Check if the next call to read() will succeed or not.
TPIE_OS_SIZE_T arity_t
Intended to signal the number of input streams in a merge.
const T & read()
Reads next item from stream if can_read() == true.
This file contains a few deprecated definitions for legacy code.
void merge_sorted_runs(typename tpie::array< tpie::unique_ptr< file_stream< T > > >::iterator start, typename tpie::array< tpie::unique_ptr< file_stream< T > > >::iterator end, file_stream< T > *outStream, M *MergeHeap, TPIE_OS_OFFSET cutoff=-1, progress_indicator_base *indicator=NULL)
This is a common merge routine for all of the AMI_merge_sorted, AMI_ptr_merge_sorted and AMI_key_merg...
A record pointer heap that uses a comparison object.
void ptr_merge_sorted(typename tpie::array< tpie::unique_ptr< file_stream< T > > >::iterator start, typename tpie::array< tpie::unique_ptr< file_stream< T > > >::iterator end, file_stream< T > *outStream, CMPR *cmp)
Merging with a heap that keeps a pointer to the records rather than the records themselves: CMPR is t...
void allocate(size_t size)
Allocates space for the heap.
void merge_sorted(typename tpie::array< std::unique_ptr< file_stream< T > > >::iterator start, typename tpie::array< std::unique_ptr< file_stream< T > > >::iterator end, file_stream< T > *outStream, CMPR *cmp)
Merging with a heap that contains the records to be merged.
std::unique_ptr< T, tpie_deleter > unique_ptr
like std::unique_ptr, but delete the object with tpie_delete.
void allocate(size_t size)
Allocates space for the heap.