16 #ifndef STXXL_CONTAINERS_PQ_HELPERS_HEADER
17 #define STXXL_CONTAINERS_PQ_HELPERS_HEADER
37 #if defined(STXXL_PARALLEL_MODE) && ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) < 40400)
38 #undef STXXL_PARALLEL_PQ_MULTIWAY_MERGE_INTERNAL
39 #undef STXXL_PARALLEL_PQ_MULTIWAY_MERGE_EXTERNAL
40 #undef STXXL_PARALLEL_PQ_MULTIWAY_MERGE_DELETE_BUFFER
41 #define STXXL_PARALLEL_PQ_MULTIWAY_MERGE_INTERNAL 0
42 #define STXXL_PARALLEL_PQ_MULTIWAY_MERGE_EXTERNAL 0
43 #define STXXL_PARALLEL_PQ_MULTIWAY_MERGE_DELETE_BUFFER 0
47 #ifndef STXXL_PARALLEL_PQ_MULTIWAY_MERGE_INTERNAL
48 #define STXXL_PARALLEL_PQ_MULTIWAY_MERGE_INTERNAL 1
50 #ifndef STXXL_PARALLEL_PQ_MULTIWAY_MERGE_EXTERNAL
51 #define STXXL_PARALLEL_PQ_MULTIWAY_MERGE_EXTERNAL 1
53 #ifndef STXXL_PARALLEL_PQ_MULTIWAY_MERGE_DELETE_BUFFER
54 #define STXXL_PARALLEL_PQ_MULTIWAY_MERGE_DELETE_BUFFER 1
57 #endif //STXXL_PARALLEL
59 #if STXXL_PARALLEL && STXXL_PARALLEL_PQ_MULTIWAY_MERGE_EXTERNAL
60 #define STXXL_PQ_EXTERNAL_LOSER_TREE 0 // no loser tree for the external sequences
62 #define STXXL_PQ_EXTERNAL_LOSER_TREE 1
65 #if STXXL_PARALLEL && STXXL_PARALLEL_PQ_MULTIWAY_MERGE_INTERNAL
66 #define STXXL_PQ_INTERNAL_LOSER_TREE 0 // no loser tree for the internal sequences
68 #define STXXL_PQ_INTERNAL_LOSER_TREE 1
71 #define STXXL_VERBOSE_PQ(msg) STXXL_VERBOSE2_THIS("priority_queue::" << msg)
82 namespace priority_queue_local {
90 template <
typename ValueType,
typename ContainerType = std::vector<ValueType>,
91 typename CompareType = std::less<ValueType> >
98 typedef typename container_type::reference
reference;
112 : heap(capacity), current_size(0)
118 {
return current_size == 0; }
123 {
return current_size; }
146 heap[current_size] = x;
148 std::push_heap(heap.begin(), heap.begin() + current_size, comp);
165 std::pop_heap(heap.begin(), heap.begin() + current_size, comp);
174 sort(heap.begin(), heap.begin() + current_size, comp);
175 std::reverse_copy(heap.begin(), heap.begin() + current_size, target);
186 template <
class Predicate,
typename FirstType,
typename SecondType>
196 bool operator () (
const FirstType& x,
const SecondType& y)
const
207 template <
typename ValueType,
unsigned_type MaxSize>
212 enum { max_size = MaxSize };
222 assert(m_size < max_size);
223 m_array[m_size++] = x;
229 return m_array[m_size - 1];
260 #endif // !STXXL_CONTAINERS_PQ_HELPERS_HEADER
void push(const value_type &x)
Add data to the queue.
container_type::const_reference const_reference
void sort(ExtIterator first, ExtIterator last, StrictWeakOrdering cmp, unsigned_type M)
Sort records comparison-based, see stxxl::sort -- Sorting Comparison-Based.
Inverts the order of a comparison functor by swapping its arguments.
void check_sort_settings()
const_reference top() const
Returns a read-only (constant) reference to the data at the first element of the queue.
container_type::size_type size_type
bool empty() const
Returns true if the queue is empty.
Similar to std::stack, with the following differences:
invert_order(const Predicate &_pred)
size_type size() const
Returns the number of elements in the queue.
void push(const value_type &x)
#define STXXL_BEGIN_NAMESPACE
void pop()
Removes first element.
Similar to std::priority_queue, with the following differences:
void sort_to(value_type *target)
Sort all contained elements, write result to target.
internal_priority_queue(size_type capacity)
Default constructor creates no elements.
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
ContainerType container_type
const value_type & top() const
container_type::reference reference
void clear()
Remove all contained elements.
#define STXXL_END_NAMESPACE