13 #ifndef STXXL_CONTAINERS_SORTER_HEADER
14 #define STXXL_CONTAINERS_SORTER_HEADER
21 #ifndef STXXL_VERBOSE_SORTER
22 #define STXXL_VERBOSE_SORTER STXXL_VERBOSE2
61 template <
typename ValueType,
73 block_size = BlockSize
91 enum { STATE_INPUT, STATE_OUTPUT } m_state;
106 : m_state(STATE_INPUT),
107 m_runs_creator(cmp, memory_to_use),
108 m_runs_merger(cmp, memory_to_use)
113 : m_state(STATE_INPUT),
114 m_runs_creator(cmp, creator_memory_to_use),
115 m_runs_merger(cmp, merger_memory_to_use)
127 if (m_state == STATE_OUTPUT)
128 m_runs_merger.deallocate();
130 m_runs_creator.allocate();
131 m_state = STATE_INPUT;
137 assert(m_state == STATE_INPUT);
138 m_runs_creator.push(val);
149 if (m_state == STATE_OUTPUT)
151 m_runs_merger.deallocate();
154 m_runs_creator.deallocate();
160 if (m_state == STATE_OUTPUT)
162 m_runs_merger.deallocate();
163 m_runs_creator.result()->clear();
166 m_runs_creator.deallocate();
177 if (m_state == STATE_OUTPUT)
179 m_runs_merger.deallocate();
182 m_runs_creator.deallocate();
183 m_runs_merger.initialize(m_runs_creator.result());
184 m_state = STATE_OUTPUT;
190 m_runs_merger.set_memory_to_use(merger_memory_to_use);
202 assert(m_state == STATE_INPUT);
204 m_runs_merger.initialize(m_runs_creator.result());
205 m_state = STATE_OUTPUT;
211 assert(m_state == STATE_OUTPUT);
213 m_runs_merger.deallocate();
215 m_state = STATE_INPUT;
224 m_runs_merger.set_memory_to_use(merger_memory_to_use);
235 if (m_state == STATE_INPUT)
236 return m_runs_creator.size();
238 return m_runs_merger.size();
243 assert(m_state == STATE_OUTPUT);
244 return m_runs_merger.empty();
255 assert(m_state == STATE_OUTPUT);
256 return *m_runs_merger;
262 return &(operator * ());
268 assert(m_state == STATE_OUTPUT);
280 #endif // !STXXL_CONTAINERS_SORTER_HEADER
sorter(const cmp_type &cmp, unsigned_type creator_memory_to_use, unsigned_type merger_memory_to_use)
Constructor variant with differently sizes runs_creator and runs_merger.
void finish()
Finish push input state and deallocate input buffer.
AllocStrategy alloc_strategy_type
#define STXXL_DEFAULT_BLOCK_SIZE(type)
stream::runs_merger< typename runs_creator_type::sorted_runs_type, cmp_type, alloc_strategy_type > runs_merger_type
corresponding runs merger type
runs_merger_type m_runs_merger
runs merger reading items when in STATE_OUTPUT
void sort(ExtIterator first, ExtIterator last, StrictWeakOrdering cmp, unsigned_type M)
Sort records comparison-based, see stxxl::sort -- Sorting Comparison-Based.
runs_creator_type m_runs_creator
runs creator object holding all items
#define STXXL_DEFAULT_ALLOC_STRATEGY
uint_pair & operator++()
prefix increment operator (directly manipulates the integer parts)
void clear()
Remove all items and return to input state.
void finish_clear()
Deallocate buffers and clear result.
External sorter container. Introduction to sorter container: see STXXL Sorter tutorial. Design and Internals of sorter container: see Sorter.
unsigned_type size() const
Number of items pushed or items remaining to be read.
void sort(unsigned_type merger_memory_to_use)
Switch to output state, rewind() in case the output was already sorted.
void rewind()
Rewind output stream to beginning.
Forms sorted runs of data from a stream.
void push(const value_type &val)
Push another item (only callable during input state).
#define STXXL_BEGIN_NAMESPACE
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
bool empty() const
Standard stream method.
void set_merger_memory_to_use(unsigned_type merger_memory_to_use)
Change runs_merger memory usage.
stream::runs_creator< stream::use_push< ValueType >, cmp_type, block_size, alloc_strategy_type > runs_creator_type
runs creator type with push() method
void sort()
Switch to output state, rewind() in case the output was already sorted.
sorter(const cmp_type &cmp, unsigned_type memory_to_use)
Constructor allocation memory_to_use bytes in ram for sorted runs.
#define STXXL_END_NAMESPACE
void sort_reuse()
Switch to output state, rewind() in case the output was already sorted.