TPIE

v1.1rc1-6-g0c97303
tpie::sort_manager< T, I, M > Class Template Reference

A class of manager objects for merge sorting objects of type T. More...

#include <tpie/sort_manager.h>

Public Member Functions

 sort_manager (I *isort, M *mheap)
 
void sort (file_stream< T > *in, file_stream< T > *out, progress_indicator_base *indicator=NULL)
 Sort in stream to out stream an save in stream (uses 3x space) More...
 
void sort (file_stream< T > *in, progress_indicator_base *indicator=NULL)
 Sort in stream and overwrite unsorted input with sorted output (uses 2x space) More...
 

Detailed Description

template<class T, class I, class M>
class tpie::sort_manager< T, I, M >

A class of manager objects for merge sorting objects of type T.

We will actually use one of two subclasses of this class which use either a comparison object, or the binary comparison operator <.

Definition at line 58 of file sort_manager.h.

Member Function Documentation

template<class T , class I , class M >
void tpie::sort_manager< T, I, M >::sort ( file_stream< T > *  in,
file_stream< T > *  out,
progress_indicator_base indicator = NULL 
)

Sort in stream to out stream an save in stream (uses 3x space)

Definition at line 174 of file sort_manager.h.

References tpie::file_stream< T >::read(), tpie::stream_crtp< child_t >::seek(), tpie::stream_crtp< child_t >::size(), and tpie::file_stream< T >::write().

Referenced by tpie::sort().

175  {
176  m_indicator = indicator;
177 
178  // if the input and output stream are the same, we only use 2x space.
179  // otherwise, we need 3x space. (input, current temp runs, output runs)
180  use2xSpace = (in == out);
181 
182  inStream = in;
183  outStream = out;
184 
185  // Basic checks that input is ok
186  if (in==NULL || out==NULL) {
187  if (m_indicator) {m_indicator->init(1); m_indicator->step(); m_indicator->done();}
188  throw exception("NULL_POINTER");
189  }
190 
191  if (inStream->size() < 2) {
192  if (m_indicator) {m_indicator->init(1); m_indicator->step(); m_indicator->done();}
193  in->seek(0);
194  if (in != out) {
195  out->seek(0);
196  if (in->size() == 1)
197  out->write(in->read());
198  }
199  return;
200  }
201 
202  // Else, there is something to sort, do it
203  start_sort();
204 }
virtual void done()
Advance the indicator to the end.
void step(stream_size_type step=1)
Record an increment to the indicator and advance the indicator.
virtual void init(stream_size_type range=0)
Initialize progress indicator.
template<class T , class I , class M >
void tpie::sort_manager< T, I, M >::sort ( file_stream< T > *  in,
progress_indicator_base indicator = NULL 
)

Sort in stream and overwrite unsorted input with sorted output (uses 2x space)

Definition at line 207 of file sort_manager.h.

References tpie::sort().

207  {
208  sort(in, in, indicator);
209 }
void sort(file_stream< T > *in, file_stream< T > *out, progress_indicator_base *indicator=NULL)
Sort in stream to out stream an save in stream (uses 3x space)
Definition: sort_manager.h:174

The documentation for this class was generated from the following file: