Template Class priority_queue<T, Cont, Comp>

Synopsis

#include "boost/p_queue.hpp"

template <class T,
          class Cont = std::vector<T>,
          class Comp = std::less<typename Cont::value_type> >
class boost::priority_queue
{
public:
  typedef typename Cont::value_type      value_type;
  typedef typename Cont::size_type       size_type;
  typedef          Cont                  container_type;
  typedef typename Cont::reference       reference;
  typedef typename Cont::const_reference const_reference;

  typedef typename Cont::iterator        iterator;
  typedef typename Cont::const_iterator  const_iterator;

  explicit priority_queue(Comp const& comp = Comp());

  bool            empty() const;
  size_type       size() const;
  const_reference top() const;

  void push(const_reference val);
  void pop();
  void change_top(const_reference val);

  const_iterator begin() const;
  const_iterator end() const;
};
    

Description

The template class priority_queue is a replacement for the standard template class std::priority_queue. It has a slightly extended interface, namely the methods begin() and end() to get access to all elements currenty stored in the priority queue and the method change_top() which is used for efficient modification of the largest element's priority.

The basic method to maintain the internal data structure is identical to that of d-heaps but for priority_queue the elements inserted into the priority queue are kept in the array. Thus, these are swapped. However, this removes the need to maintain a mapping between the elements in the heap and their position resulting a huge performance boost. On the other hand, this remove the possibility to change the priority of an arbitrary element because the elements cannot be found efficiently in the priority queue. If you never need to change the priority of an element except for the largest element this class is probably suitable. If you need only the methods also present for std::priority_queue you should probably stick to the standard class...

For a description of the methods of priority_queue<T, Cont, Comp> see the description of common methods.

See Also

heap(3), heap-common(3)
Copyright © 1999 Dietmar Kühl (dietmar.kuehl@claas-solutions.de)
Claas Solutions GmbH