20 #ifndef _MERGE_SORTED_RUNS_H
21 #define _MERGE_SORTED_RUNS_H
70 template <
class T,
class M>
74 TPIE_OS_OFFSET cutoff=-1,
78 size_t arity = end-start;
89 for (i = 0; i < arity; i++) {
92 in_objects[i] = &stream->
read();
93 MergeHeap->insert( in_objects[i], i );
97 if (indicator) indicator->step();
104 MergeHeap->initialize ( );
109 while (MergeHeap->sizeofheap() > 0) {
110 i = MergeHeap->get_min_run_id ();
111 outStream->
write(*in_objects[i]);
116 if ( (cutoff != -1) && (nread[i]>=cutoff))
120 if (stream->
can_read()) in_objects[i] = &stream->
read();
123 if (indicator) indicator->step();
127 MergeHeap->delete_min_and_insert(NULL);
130 MergeHeap->delete_min_and_insert (in_objects[i]);
148 template <
class T,
class CMPR>
180 template <
class T,
class CMPR>
202 #endif //_MERGE_SORTED_RUNS_H
The base class for indicating the progress of some task.
A generic array with a fixed size.
TPIE_OS_SIZE_T arity_t
Intended to signal the number of input streams in a merge.
const item_type & read()
Read an item from the stream.
This file contains a few deprecated definitions for legacy code.
void write(const item_type &item)
Write an item to the stream.
void ptr_merge_sorted(typename tpie::array< tpie::auto_ptr< file_stream< T > > >::iterator start, typename tpie::array< tpie::auto_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 merge_sorted_runs(typename tpie::array< tpie::auto_ptr< file_stream< T > > >::iterator start, typename tpie::array< tpie::auto_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 merge_sorted(typename tpie::array< std::auto_ptr< file_stream< T > > >::iterator start, typename tpie::array< std::auto_ptr< file_stream< T > > >::iterator end, file_stream< T > *outStream, CMPR *cmp)
Merging with a heap that contains the records to be merged.
void allocate(size_t size)
Allocates space for the heap.
A Stream object stores an ordered collection of objects of type T on external memory.
Simple class acting both as file and a file::stream.
bool can_read() const
Check if we can read an item with read().
void allocate(size_t size)
Allocates space for the heap.
like std::auto_ptr, but delete the object with tpie_delete.