53 #include <tpie/pipelining/merge_sorter.h>
54 #include <tpie/file_stream.h>
65 template<
typename Stream,
typename T,
typename Compare>
66 void generic_sort(Stream & instream, Compare comp,
67 progress_indicator_base * indicator) {
69 stream_size_type sz = instream.size();
71 fractional_progress fp(indicator);
72 fractional_subindicator push(fp,
"sort",
TPIE_FSI, sz,
"Write sorted runs");
73 fractional_subindicator
merge(fp,
"sort",
TPIE_FSI, sz,
"Perform merge heap");
74 fractional_subindicator
output(fp,
"sort",
TPIE_FSI, sz,
"Write sorted output");
79 merge_sorter<T, true, Compare> s(comp);
83 while (instream.can_read()) s.push(instream.read()), push.step();
91 while (s.can_pull()) instream.write(s.pull()),
output.step();
97 template<
typename Stream,
typename T,
typename Compare>
98 void generic_sort(Stream & instream, Stream & outstream, Compare comp,
99 progress_indicator_base *indicator) {
101 if (&instream == &outstream) {
102 generic_sort<Stream, T, Compare>(instream, comp, indicator);
106 stream_size_type sz = instream.size();
108 fractional_progress fp(indicator);
109 fractional_subindicator push(fp,
"sort",
TPIE_FSI, sz,
"Write sorted runs");
110 fractional_subindicator
merge(fp,
"sort",
TPIE_FSI, sz,
"Perform merge heap");
111 fractional_subindicator
output(fp,
"sort",
TPIE_FSI, sz,
"Write sorted output");
116 merge_sorter<T, true, Compare> s(comp);
120 while (instream.can_read()) s.push(instream.read()), push.step();
126 outstream.truncate(0);
128 while (s.can_pull()) outstream.write(s.pull()),
output.step();
140 template<
typename T,
typename Compare>
143 bits::generic_sort<uncompressed_stream<T>, T, Compare>(instream, outstream, &comp, &indicator);
153 sort(instream, outstream, comp, indicator);
163 bits::generic_sort<file_stream<T>, T>(instream, outstream, comp, indicator);
178 template<
typename T,
typename Compare>
181 sort(instream, instream, comp, &indicator);
188 template<
typename T,
typename Compare>
191 bits::generic_sort<file_stream<T>, T>(instream, comp, &indicator);
200 sort(instream, instream, &indicator);
204 void sort(file_stream<T> &instream,
205 progress_indicator_base &indicator) {
207 sort(instream, comp, indicator);
214 template <
typename T>
216 sort(instream, instream);
223 #endif // _AMI_SORT_H
void sort(uncompressed_stream< T > &instream, uncompressed_stream< T > &outstream, Compare comp, progress_indicator_base &indicator)
Sort elements of a stream using the given STL-style comparator object.
The base class for indicating the progress of some task.
Null-object progress indicator.
#define TPIE_FSI
For use when constructing a fractional subindicator.
This file contains a few deprecated definitions for legacy code.
Contains deprecated sorting algorithms.
memory_manager & get_memory_manager()
Return a reference to the memory manager.
Fractional progress reporting.
pipe_middle< factory< bits::merge_t< pull_t >::template type, pull_t > > merge(pullpipe_begin< pull_t > with)
A node that merges a pull pipeline into a push pipeline.
Simple class acting both as file and a file::stream.
pipe_end< termfactory< bits::output_t< T >, file_stream< T > & > > output(file_stream< T > &fs)
A pipelining node that writes the pushed items to a file stream.
Simple class acting both as a tpie::file and a tpie::file::stream.