COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/concepts/heap.h

    r757 r631  
    1717 */
    1818
    19 #ifndef LEMON_CONCEPTS_HEAP_H
    20 #define LEMON_CONCEPTS_HEAP_H
    21 
    2219///\ingroup concept
    2320///\file
    2421///\brief The concept of heaps.
    2522
     23#ifndef LEMON_CONCEPTS_HEAP_H
     24#define LEMON_CONCEPTS_HEAP_H
     25
    2626#include <lemon/core.h>
    2727#include <lemon/concept_check.h>
     
    3636    /// \brief The heap concept.
    3737    ///
    38     /// This concept class describes the main interface of heaps.
    39     /// The various \ref heaps "heap structures" are efficient
    40     /// implementations of the abstract data type \e priority \e queue.
    41     /// They store items with specified values called \e priorities
    42     /// in such a way that finding and removing the item with minimum
    43     /// priority are efficient. The basic operations are adding and
    44     /// erasing items, changing the priority of an item, etc.
     38    /// Concept class describing the main interface of heaps. A \e heap
     39    /// is a data structure for storing items with specified values called
     40    /// \e priorities in such a way that finding the item with minimum
     41    /// priority is efficient. In a heap one can change the priority of an
     42    /// item, add or erase an item, etc.
    4543    ///
    46     /// Heaps are crucial in several algorithms, such as Dijkstra and Prim.
    47     /// Any class that conforms to this concept can be used easily in such
    48     /// algorithms.
    49     ///
    50     /// \tparam PR Type of the priorities of the items.
    51     /// \tparam IM A read-writable item map with \c int values, used
     44    /// \tparam PR Type of the priority of the items.
     45    /// \tparam IM A read and writable item map with int values, used
    5246    /// internally to handle the cross references.
    53     /// \tparam CMP A functor class for comparing the priorities.
     47    /// \tparam Comp A functor class for the ordering of the priorities.
    5448    /// The default is \c std::less<PR>.
    5549#ifdef DOXYGEN
    56     template <typename PR, typename IM, typename CMP>
     50    template <typename PR, typename IM, typename Comp = std::less<PR> >
    5751#else
    58     template <typename PR, typename IM, typename CMP = std::less<PR> >
     52    template <typename PR, typename IM>
    5953#endif
    6054    class Heap {
     
    7165      ///
    7266      /// Each item has a state associated to it. It can be "in heap",
    73       /// "pre-heap" or "post-heap". The latter two are indifferent from the
    74       /// heap's point of view, but may be useful to the user.
     67      /// "pre heap" or "post heap". The later two are indifferent
     68      /// from the point of view of the heap, but may be useful for
     69      /// the user.
    7570      ///
    7671      /// The item-int map must be initialized in such way that it assigns
     
    7873      enum State {
    7974        IN_HEAP = 0,    ///< = 0. The "in heap" state constant.
    80         PRE_HEAP = -1,  ///< = -1. The "pre-heap" state constant.
    81         POST_HEAP = -2  ///< = -2. The "post-heap" state constant.
     75        PRE_HEAP = -1,  ///< = -1. The "pre heap" state constant.
     76        POST_HEAP = -2  ///< = -2. The "post heap" state constant.
    8277      };
    8378
    84       /// \brief Constructor.
    85       ///
    86       /// Constructor.
     79      /// \brief The constructor.
     80      ///
     81      /// The constructor.
    8782      /// \param map A map that assigns \c int values to keys of type
    8883      /// \c Item. It is used internally by the heap implementations to
    8984      /// handle the cross references. The assigned value must be
    90       /// \c PRE_HEAP (<tt>-1</tt>) for each item.
     85      /// \c PRE_HEAP (<tt>-1</tt>) for every item.
    9186      explicit Heap(ItemIntMap &map) {}
    9287
    93       /// \brief Constructor.
    94       ///
    95       /// Constructor.
    96       /// \param map A map that assigns \c int values to keys of type
    97       /// \c Item. It is used internally by the heap implementations to
    98       /// handle the cross references. The assigned value must be
    99       /// \c PRE_HEAP (<tt>-1</tt>) for each item.
    100       /// \param comp The function object used for comparing the priorities.
    101       explicit Heap(ItemIntMap &map, const CMP &comp) {}
    102 
    10388      /// \brief The number of items stored in the heap.
    10489      ///
    105       /// This function returns the number of items stored in the heap.
     90      /// Returns the number of items stored in the heap.
    10691      int size() const { return 0; }
    10792
    108       /// \brief Check if the heap is empty.
    109       ///
    110       /// This function returns \c true if the heap is empty.
     93      /// \brief Checks if the heap is empty.
     94      ///
     95      /// Returns \c true if the heap is empty.
    11196      bool empty() const { return false; }
    11297
    113       /// \brief Make the heap empty.
    114       ///
    115       /// This functon makes the heap empty.
    116       /// It does not change the cross reference map. If you want to reuse
    117       /// a heap that is not surely empty, you should first clear it and
    118       /// then you should set the cross reference map to \c PRE_HEAP
    119       /// for each item.
    120       void clear() {}
    121 
    122       /// \brief Insert an item into the heap with the given priority.
    123       ///
    124       /// This function inserts the given item into the heap with the
    125       /// given priority.
     98      /// \brief Makes the heap empty.
     99      ///
     100      /// Makes the heap empty.
     101      void clear();
     102
     103      /// \brief Inserts an item into the heap with the given priority.
     104      ///
     105      /// Inserts the given item into the heap with the given priority.
    126106      /// \param i The item to insert.
    127107      /// \param p The priority of the item.
    128       /// \pre \e i must not be stored in the heap.
    129108      void push(const Item &i, const Prio &p) {}
    130109
    131       /// \brief Return the item having minimum priority.
    132       ///
    133       /// This function returns the item having minimum priority.
     110      /// \brief Returns the item having minimum priority.
     111      ///
     112      /// Returns the item having minimum priority.
    134113      /// \pre The heap must be non-empty.
    135114      Item top() const {}
     
    137116      /// \brief The minimum priority.
    138117      ///
    139       /// This function returns the minimum priority.
     118      /// Returns the minimum priority.
    140119      /// \pre The heap must be non-empty.
    141120      Prio prio() const {}
    142121
    143       /// \brief Remove the item having minimum priority.
    144       ///
    145       /// This function removes the item having minimum priority.
     122      /// \brief Removes the item having minimum priority.
     123      ///
     124      /// Removes the item having minimum priority.
    146125      /// \pre The heap must be non-empty.
    147126      void pop() {}
    148127
    149       /// \brief Remove the given item from the heap.
    150       ///
    151       /// This function removes the given item from the heap if it is
    152       /// already stored.
     128      /// \brief Removes an item from the heap.
     129      ///
     130      /// Removes the given item from the heap if it is already stored.
    153131      /// \param i The item to delete.
    154       /// \pre \e i must be in the heap.
    155132      void erase(const Item &i) {}
    156133
    157       /// \brief The priority of the given item.
    158       ///
    159       /// This function returns the priority of the given item.
    160       /// \param i The item.
    161       /// \pre \e i must be in the heap.
     134      /// \brief The priority of an item.
     135      ///
     136      /// Returns the priority of the given item.
     137      /// \param i The item.
     138      /// \pre \c i must be in the heap.
    162139      Prio operator[](const Item &i) const {}
    163140
    164       /// \brief Set the priority of an item or insert it, if it is
     141      /// \brief Sets the priority of an item or inserts it, if it is
    165142      /// not stored in the heap.
    166143      ///
    167144      /// This method sets the priority of the given item if it is
    168       /// already stored in the heap. Otherwise it inserts the given
    169       /// item into the heap with the given priority.
     145      /// already stored in the heap.
     146      /// Otherwise it inserts the given item with the given priority.
    170147      ///
    171148      /// \param i The item.
     
    173150      void set(const Item &i, const Prio &p) {}
    174151
    175       /// \brief Decrease the priority of an item to the given value.
    176       ///
    177       /// This function decreases the priority of an item to the given value.
     152      /// \brief Decreases the priority of an item to the given value.
     153      ///
     154      /// Decreases the priority of an item to the given value.
    178155      /// \param i The item.
    179156      /// \param p The priority.
    180       /// \pre \e i must be stored in the heap with priority at least \e p.
     157      /// \pre \c i must be stored in the heap with priority at least \c p.
    181158      void decrease(const Item &i, const Prio &p) {}
    182159
    183       /// \brief Increase the priority of an item to the given value.
    184       ///
    185       /// This function increases the priority of an item to the given value.
     160      /// \brief Increases the priority of an item to the given value.
     161      ///
     162      /// Increases the priority of an item to the given value.
    186163      /// \param i The item.
    187164      /// \param p The priority.
    188       /// \pre \e i must be stored in the heap with priority at most \e p.
     165      /// \pre \c i must be stored in the heap with priority at most \c p.
    189166      void increase(const Item &i, const Prio &p) {}
    190167
    191       /// \brief Return the state of an item.
     168      /// \brief Returns if an item is in, has already been in, or has
     169      /// never been in the heap.
    192170      ///
    193171      /// This method returns \c PRE_HEAP if the given item has never
     
    199177      State state(const Item &i) const {}
    200178
    201       /// \brief Set the state of an item in the heap.
    202       ///
    203       /// This function sets the state of the given item in the heap.
    204       /// It can be used to manually clear the heap when it is important
    205       /// to achive better time complexity.
     179      /// \brief Sets the state of an item in the heap.
     180      ///
     181      /// Sets the state of the given item in the heap. It can be used
     182      /// to manually clear the heap when it is important to achive the
     183      /// better time complexity.
    206184      /// \param i The item.
    207185      /// \param st The state. It should not be \c IN_HEAP.
Note: See TracChangeset for help on using the changeset viewer.