TPIE

11a2c2d
External sorting

The recommended way to sort large data set (which will typically be stored in a tpie::file_stream in TPIE) is to use one of the tpie::sort functions defined in sort.h.

When you have a tpie::file_stream over some type T (opened for reading and writing), you can order the elements of this stream according to the order defined by the < operator (i.e. using T::operator< or operator<(T,T) ) simply invoke tpie::sort (mystream, mystream). When the input and output stream is the same, the temporary space usage of tpie::sort is the same as the space used by the input stream.

If you wish to store the result in a stream different from the input stream, supply this stream as the second argument to \r tpie::sort, this requires extra space equivalent to twice the space used by the input stream.

#include <tpie/tpie.h> // for tpie::tpie_init
#include <tpie/sort.h> // for tpie::sort
int main() {
//create a stream with 1000 ints
for (int i = 0; i < 1000; ++i) {
mystream.write(i);
}
//sort the stream using the "<" operator
tpie::sort(mystream,mystream);
return 0;
}

The current interface is defined in the tpie namespace, but legacy definitions exist in the tpie::ami namespace.

tpie::sort
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.
Definition: sort.h:141
tpie::file_stream
Compressed stream.
Definition: predeclare.h:49
tpie::tpie_init
TPIE_EXPORT void tpie_init(flags< subsystem > subsystems=ALL)
Initialize the given subsystems of TPIE.
tpie.h
sort.h
tpie::tpie_finish
TPIE_EXPORT void tpie_finish(flags< subsystem > subsystems=ALL)
Deinitialize the given subsystems of TPIE.