TPIE

11a2c2d
sort.h File Reference
#include <tpie/portability.h>
#include <tpie/sort_manager.h>
#include <tpie/mergeheap.h>
#include <tpie/internal_sort.h>
#include <tpie/progress_indicator_base.h>
#include <tpie/progress_indicator_null.h>
#include <tpie/fractional_progress.h>
#include <tpie/pipelining/merge_sorter.h>
#include <tpie/file_stream.h>
#include <tpie/uncompressed_stream.h>
#include <tpie/sort_deprecated.h>

Go to the source code of this file.

Namespaces

 tpie
 

Functions

template<typename Stream , typename T , typename Compare >
void tpie::bits::generic_sort (Stream &instream, Compare comp, progress_indicator_base *indicator)
 Sort elements of a stream in-place using the given STL-style comparator object. More...
 
template<typename Stream , typename T , typename Compare >
void tpie::bits::generic_sort (Stream &instream, Stream &outstream, Compare comp, progress_indicator_base *indicator)
 
template<typename T , typename Compare >
void tpie::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. More...
 
template<typename T >
void tpie::sort (uncompressed_stream< T > &instream, uncompressed_stream< T > &outstream, tpie::progress_indicator_base *indicator=NULL)
 Sort elements of a stream using the less-than operator. More...
 
template<typename T >
void tpie::sort (file_stream< T > &instream, file_stream< T > &outstream, tpie::progress_indicator_base *indicator=NULL)
 Sort elements of a stream using the less-than operator. More...
 
template<typename T , typename Compare >
void tpie::sort (uncompressed_stream< T > &instream, Compare comp, progress_indicator_base &indicator)
 Sort elements of a stream in-place using the given STL-style comparator object. More...
 
template<typename T , typename Compare >
void tpie::sort (file_stream< T > &instream, Compare comp, progress_indicator_base &indicator)
 Sort elements of a stream in-place using the given STL-style comparator object. More...
 
template<typename T >
void tpie::sort (uncompressed_stream< T > &instream, progress_indicator_base &indicator)
 Sort elements of a stream in-place using the less-than operator. More...
 
template<typename T >
void tpie::sort (file_stream< T > &instream, progress_indicator_base &indicator)
 
template<typename T >
void tpie::sort (uncompressed_stream< T > &instream)
 Sort elements of a stream in-place using the less-than operator and no progress indicator. More...
 

Detailed Description

Sorting algorithms.

In-place Variants for Sorting in TPIE:
TPIE can sort given an input stream and output stream, or just an input stream. When just an input stream is specified, the original input elements are deleted the input stream is rewritten with the sorted output elements. If both the input stream and output stream are specified, the original input elements are saved. During sorting, a temporary copy of each element is stored on disk as part of intermediate sorting results. If N is the size on disk of the original input stream, the polymorphs of sorting with both input and output streams use 3N space, whereas if just an input stream is specified, 2N space is used. If the original unsorted input stream is not needed after sorting, it is recommended that users use the sort() polymorph with with just an input stream, to save space and avoid having to maintain both an input and output stream.

Definition in file sort.h.

Function Documentation

◆ generic_sort()

template<typename Stream , typename T , typename Compare >
void tpie::bits::generic_sort ( Stream &  instream,
Compare  comp,
progress_indicator_base indicator 
)

Sort elements of a stream in-place using the given STL-style comparator object.

Definition at line 66 of file sort.h.

67  {
68 
69  stream_size_type sz = instream.size();
70 
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");
75  fp.init(sz);
76 
77  instream.seek(0);
78 
79  merge_sorter<T, true, Compare> s(comp);
80  s.set_available_memory(get_memory_manager().available());
81  s.begin();
82  push.init(sz);
83  while (instream.can_read()) s.push(instream.read()), push.step();
84  push.done();
85  s.end();
86 
87  instream.truncate(0);
88  s.calc(merge);
89 
90  output.init(sz);
91  while (s.can_pull()) instream.write(s.pull()), output.step();
92  output.done();
93  fp.done();
94  instream.seek(0);
95 }
tpie::get_memory_manager
TPIE_EXPORT memory_manager & get_memory_manager()
Return a reference to the memory manager.
TPIE_FSI
#define TPIE_FSI
Definition: fractional_progress.h:38
tpie::pipelining::merge
pipe_middle< tfactory< bits::merge_t, Args< pull_t >, pull_t > > merge(pullpipe_begin< pull_t > with)
A node that merges a pull pipeline into a push pipeline.
Definition: merge.h:65
tpie::pipelining::output
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.
Definition: file_stream.h:430