TPIE

v1.1rc1-6-g0c97303
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 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.