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];
254 template <
typename Iterator>
257 typedef std::pair<Iterator, Iterator>
pair;
262 typedef typename std::iterator_traits<iterator>::value_type
value_type;
263 typedef typename std::iterator_traits<iterator>::difference_type
size_type;
273 :
pair(first, last), m_origin(origin)
328 return end() - begin();
348 #endif // !STXXL_CONTAINERS_PQ_HELPERS_HEADER
void push(const value_type &x)
Add data to the queue.
container_type::const_reference const_reference
const_reference front() const
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.
std::pair< Iterator, Iterator > pair
std::iterator_traits< iterator >::value_type value_type
short_sequence(Iterator first, Iterator last, origin_type origin)
const_iterator cbegin() const
void check_sort_settings()
const_reference top() const
Returns a read-only (constant) reference to the data at the first element of the queue.
const_iterator end() const
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)
unsigned_type origin_type
#define STXXL_BEGIN_NAMESPACE
void pop()
Removes first element.
origin_type origin() const
Similar to std::priority_queue, with the following differences:
void sort_to(value_type *target)
Sort all contained elements, write result to target.
const value_type & const_reference
const_iterator begin() const
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
std::iterator_traits< iterator >::difference_type size_type
container_type::reference reference
const_iterator cend() const
const_reference back() const
void clear()
Remove all contained elements.
#define STXXL_END_NAMESPACE
const iterator const_iterator