20 #ifndef _INTERNAL_SORT_H
21 #define _INTERNAL_SORT_H
36 #include <tpie/file_stream.h>
51 TPIE_OS_SIZE_T source;
54 {
return (x.keyval == y.keyval);}
57 {
return (x.keyval != y.keyval);}
60 {
return (x.keyval <= y.keyval);}
63 {
return (x.keyval >= y.keyval);}
66 {
return (x.keyval < y.keyval);}
69 {
return (x.keyval > y.keyval);}
97 void allocate(TPIE_OS_SIZE_T nItems);
130 ItemArray.resize(len);
142 TPIE_OS_SIZE_T memAvail=memSize-space_overhead();
144 if (memAvail < space_per_item())
return 0;
145 return memAvail/space_per_item();
165 template<
class T,
class Compare>
201 template<
class T,
class Compare>
204 TPIE_OS_SIZE_T nItems,
206 tp_assert ( nItems <= len,
"Internal buffer overfull (nItems > len)");
209 TPIE_OS_SIZE_T i = 0;
214 tp_assert ( nItems <= len,
"Internal buffer overfull (nItems > len)");
217 fp.
id() << __FILE__ << __FUNCTION__ <<
typeid(T) <<
typeid(Compare);
223 read_progress.
init(nItems);
225 for (i = 0; i < nItems; i++) {
226 ItemArray[i] = InStr->
read();
227 read_progress.
step();
229 read_progress.
done();
232 tpie::parallel_sort<true>(ItemArray.begin(), ItemArray.begin()+nItems, sort_progress, cmp_o);
240 write_progress.
init(nItems);
242 for (i = 0; i < nItems; i++) {
243 OutStr->write(ItemArray[i]);
244 write_progress.
step();
246 write_progress.
done();
252 #endif // _INTERNAL_SORT_H
Defines the tp_assert macro.
Compare cmp_o
Comparison object used for sorting.
Memory management subsystem.
The base class for indicating the progress of some task.
unique_id_type & id()
Return this progress indicator's unique id.
Comparision object based Internal_Sorter_base subclass implementation; uses quick_sort_obj().
The base class for internal sorters.
void sort(file_stream< T > *InStr, file_stream< T > *OutStr, TPIE_OS_SIZE_T nItems, progress_indicator_base *pi=0)
Reads nItems sequentially from InStr, starting at the current file position; writes the sorted output...
void truncate(stream_size_type offset)
Truncate to given size.
TPIE_OS_SIZE_T MaxItemCount(TPIE_OS_SIZE_T memSize)
Returns maximum number of items that can be sorted using memSize bytes.
#define TPIE_FSI
For use when constructing a fractional subindicator.
const T & read()
Reads next item from stream if can_read() == true.
Fractional progress reporter.
This file contains a few deprecated definitions for legacy code.
void deallocate(void)
Clean up internal array ItemArray.
void allocate(TPIE_OS_SIZE_T nItems)
Allocate ItemArray as array that can hold nItems.
void seek(stream_offset_type offset, offset_type whence=beginning)
Precondition: is_open() Precondition: offset == 0.
array< T > ItemArray
Array that holds items to be sorted.
void done()
Advance the indicator to the end.
void init(stream_size_type range=0)
Initialize progress indicator.
TPIE_OS_SIZE_T space_overhead()
Returns fixed memory usage overhead in bytes per class instantiation.
Simple parallel quick sort implementation with progress tracking.
virtual void init(stream_size_type range)
Initialize progress indicator.
void step(stream_size_type step=1)
Record an increment to the indicator and advance the indicator.
Fractional progress reporting.
virtual void done()
Advance the indicator to the end.
TPIE_OS_SIZE_T space_per_item()
Returns memory usage in bytes per sort item.
A simple class that facilitates doing key sorting followed by in-memory permuting to sort items in-me...
#define tp_assert(condition, message)
Internal_Sorter_Base(void)
Constructor.
~Internal_Sorter_Obj()
Empty destructor.
TPIE_OS_SIZE_T len
length of ItemArray
Subindicator for fractional progress reporting.
Internal_Sorter_Obj(Compare cmp)
Empty constructor.