template<typename ValueType, typename CompareType, unsigned BlockSize = STXXL_DEFAULT_BLOCK_SIZE(ValueType), class AllocStrategy = STXXL_DEFAULT_ALLOC_STRATEGY>
class stxxl::sorter< ValueType, CompareType, BlockSize, AllocStrategy >
External sorter container.
Introduction to sorter container: see STXXL Sorter tutorial.
Design and Internals of sorter container: see Sorter.
External Sorter: use stream package objects to keep a sorted container.
This sorter container combines the two functions of runs_creator and runs_merger from the stream packages into a two-phase container.
In the first phase the container is filled with unordered items via push(), which are presorted internally into runs of size M. When the internal memory overflows a runs is written to external memory in blocks of block_size.
When sort() is called the container enters the output phase and push() is disallowed. After calling sort() the items can be read in sorted order using operator*() to get the top item, operator++() to advance to the next one and empty() to check for end of stream. This is exactly the stream interface.
In the output phase the sorter can be returned to the beginning of the stream using rewind() and everything is read again in sorted order.
Using clear() the object can be reset into input state and all items are destroyed.
Added in STXXL 1.4
- Template Parameters
-
ValueType | type of the contained objects (POD with no references to internal memory) |
CompareType | type of comparison object used for sorting the runs |
BlockSize | size of the external memory block in bytes, default is STXXL_DEFAULT_BLOCK_SIZE(ValTp) |
AllocStr | parallel disk allocation strategy, default is STXXL_DEFAULT_ALLOC_STRATEGY |
- Examples:
- examples/applications/skew3.cpp, examples/containers/sorter1.cpp, examples/containers/sorter2.cpp, and examples/stream/stream1.cpp.
Definition at line 64 of file sorter.h.
template<typename ValueType , typename CompareType , unsigned BlockSize = STXXL_DEFAULT_BLOCK_SIZE(ValueType), class AllocStrategy = STXXL_DEFAULT_ALLOC_STRATEGY>
void stxxl::sorter< ValueType, CompareType, BlockSize, AllocStrategy >::rewind |
( |
| ) |
|
|
inline |
template<typename ValueType , typename CompareType , unsigned BlockSize = STXXL_DEFAULT_BLOCK_SIZE(ValueType), class AllocStrategy = STXXL_DEFAULT_ALLOC_STRATEGY>
void stxxl::sorter< ValueType, CompareType, BlockSize, AllocStrategy >::sort |
( |
| ) |
|
|
inline |
Switch to output state, rewind() in case the output was already sorted.
Definition at line 176 of file sorter.h.
template<typename ValueType , typename CompareType , unsigned BlockSize = STXXL_DEFAULT_BLOCK_SIZE(ValueType), class AllocStrategy = STXXL_DEFAULT_ALLOC_STRATEGY>
template<typename ValueType , typename CompareType , unsigned BlockSize = STXXL_DEFAULT_BLOCK_SIZE(ValueType), class AllocStrategy = STXXL_DEFAULT_ALLOC_STRATEGY>
void stxxl::sorter< ValueType, CompareType, BlockSize, AllocStrategy >::sort_reuse |
( |
| ) |
|
|
inline |
Switch to output state, rewind() in case the output was already sorted.
Definition at line 201 of file sorter.h.