src/lemon/bin_heap.h
changeset 1331 7e93d3f0406d
parent 1270 806451fd084b
child 1336 fd5fd79123fd
     1.1 --- a/src/lemon/bin_heap.h	Sat Apr 09 19:27:48 2005 +0000
     1.2 +++ b/src/lemon/bin_heap.h	Sat Apr 09 19:30:49 2005 +0000
     1.3 @@ -59,16 +59,14 @@
     1.4      typedef ItemIntMap                       ItemIntMapType;
     1.5      typedef Compare                          PrioCompare;
     1.6  
     1.7 -    /**
     1.8 -     * Each Item element have a state associated to it. It may be "in heap",
     1.9 -     * "pre heap" or "post heap". The later two are indifferent from the
    1.10 -     * heap's point of view, but may be useful to the user.
    1.11 -     *
    1.12 -     * The ItemIntMap _should_ be initialized in such way, that it maps
    1.13 -     * PRE_HEAP (-1) to any element to be put in the heap...
    1.14 -     */
    1.15 -    ///\todo it is used nowhere
    1.16 +    /// \brief Type to represent the items states.
    1.17      ///
    1.18 +    /// Each Item element have a state associated to it. It may be "in heap",
    1.19 +    /// "pre heap" or "post heap". The later two are indifferent from the
    1.20 +    /// heap's point of view, but may be useful to the user.
    1.21 +    ///
    1.22 +    /// The ItemIntMap _should_ be initialized in such way, that it maps
    1.23 +    /// PRE_HEAP (-1) to any element to be put in the heap...
    1.24      enum state_enum {
    1.25        IN_HEAP = 0,
    1.26        PRE_HEAP = -1,
    1.27 @@ -78,41 +76,37 @@
    1.28    private:
    1.29      std::vector<PairType> data;
    1.30      Compare comp;
    1.31 -    // FIXME: jo ez igy???
    1.32      ItemIntMap &iim;
    1.33  
    1.34    public:
    1.35 -    ///The constructor
    1.36 -
    1.37 -    /**
    1.38 -       \c _iim should be given to the constructor, since it is used
    1.39 -       internally to handle the cross references.
    1.40 -    */
    1.41 +    /// \brief The constructor.
    1.42 +    ///
    1.43 +    /// The constructor.
    1.44 +    /// \param _iim should be given to the constructor, since it is used
    1.45 +    /// internally to handle the cross references. The value of the map
    1.46 +    /// should be PRE_HEAP (-1) for each element.
    1.47      explicit BinHeap(ItemIntMap &_iim) : iim(_iim) {}
    1.48      
    1.49 -    ///The constructor
    1.50 -
    1.51 -    /**
    1.52 -       \c _iim should be given to the constructor, since it is used
    1.53 -       internally to handle the cross references. \c _comp is an
    1.54 -       object for ordering of the priorities.
    1.55 -    */
    1.56 +    /// \brief The constructor.
    1.57 +    ///
    1.58 +    /// The constructor.
    1.59 +    /// \param _iim should be given to the constructor, since it is used
    1.60 +    /// internally to handle the cross references. The value of the map
    1.61 +    /// should be PRE_HEAP (-1) for each element.
    1.62 +    ///
    1.63 +    /// \param _comp The comparator function object.
    1.64      BinHeap(ItemIntMap &_iim, const Compare &_comp) 
    1.65        : iim(_iim), comp(_comp) {}
    1.66  
    1.67  
    1.68 -    ///The number of items stored in the heap.
    1.69 -
    1.70 -    /**
    1.71 -       Returns the number of items stored in the heap.
    1.72 -    */
    1.73 +    /// The number of items stored in the heap.
    1.74 +    ///
    1.75 +    /// \brief Returns the number of items stored in the heap.
    1.76      int size() const { return data.size(); }
    1.77      
    1.78 -    ///Checks if the heap stores no items.
    1.79 -    
    1.80 -    /**
    1.81 -       Returns \c true if and only if the heap stores no items.
    1.82 -    */
    1.83 +    /// \brief Checks if the heap stores no items.
    1.84 +    ///
    1.85 +    /// Returns \c true if and only if the heap stores no items.
    1.86      bool empty() const { return data.empty(); }
    1.87  
    1.88    private:
    1.89 @@ -142,86 +136,76 @@
    1.90      }
    1.91  
    1.92    public:
    1.93 -    ///Adds \c p.first to the heap with priority \c p.second.
    1.94 -    
    1.95 -    /**
    1.96 -       Adds \c p.first to the heap with priority \c p.second.
    1.97 -       \c p.first must not be stored in the heap. 
    1.98 -    */
    1.99 +    /// \brief Insert a pair of item and priority into the heap.
   1.100 +    ///
   1.101 +    /// Adds \c p.first to the heap with priority \c p.second.
   1.102 +    /// \param p The pair to insert.
   1.103      void push(const PairType &p) {
   1.104        int n = data.size();
   1.105        data.resize(n+1);
   1.106        bubble_up(n, p);
   1.107      }
   1.108  
   1.109 -    ///Adds \c i to the heap with priority \c p. 
   1.110 -    
   1.111 -    /**
   1.112 -       Adds \c i to the heap with priority \c p. 
   1.113 -       \pre \c i must not be stored in the heap. 
   1.114 -    */
   1.115 +    /// \brief Insert an item into the heap with the given heap.
   1.116 +    ///    
   1.117 +    /// Adds \c i to the heap with priority \c p. 
   1.118 +    /// \param i The item to insert.
   1.119 +    /// \param p The priority of the item.
   1.120      void push(const Item &i, const Prio &p) { push(PairType(i,p)); }
   1.121  
   1.122 -    ///Returns the item with minimum priority relative to \c Compare.
   1.123 -    
   1.124 -    /**
   1.125 -       This method returns the item with minimum priority relative to \c
   1.126 -       Compare.  
   1.127 -       \pre The heap must be nonempty.  
   1.128 -    */
   1.129 +    /// \brief Returns the item with minimum priority relative to \c Compare.
   1.130 +    ///
   1.131 +    /// This method returns the item with minimum priority relative to \c
   1.132 +    /// Compare.  
   1.133 +    /// \pre The heap must be nonempty.  
   1.134      Item top() const {
   1.135        return data[0].first;
   1.136      }
   1.137  
   1.138 -    ///Returns the minimum priority relative to \c Compare.
   1.139 -
   1.140 -    /**
   1.141 -       It returns the minimum priority relative to \c Compare.
   1.142 -       \pre The heap must be nonempty.
   1.143 -    */
   1.144 +    /// \brief Returns the minimum priority relative to \c Compare.
   1.145 +    ///
   1.146 +    /// It returns the minimum priority relative to \c Compare.
   1.147 +    /// \pre The heap must be nonempty.
   1.148      Prio prio() const {
   1.149        return data[0].second;
   1.150      }
   1.151  
   1.152 -    ///Deletes the item with minimum priority relative to \c Compare.
   1.153 -
   1.154 -    /**
   1.155 -    This method deletes the item with minimum priority relative to \c
   1.156 -    Compare from the heap.  
   1.157 -    \pre The heap must be non-empty.  
   1.158 -    */
   1.159 +    /// \brief Deletes the item with minimum priority relative to \c Compare.
   1.160 +    ///
   1.161 +    /// This method deletes the item with minimum priority relative to \c
   1.162 +    /// Compare from the heap.  
   1.163 +    /// \pre The heap must be non-empty.  
   1.164      void pop() {
   1.165        rmidx(0);
   1.166      }
   1.167  
   1.168 -    ///Deletes \c i from the heap.
   1.169 -
   1.170 -    /**
   1.171 -       This method deletes item \c i from the heap, if \c i was
   1.172 -       already stored in the heap. 
   1.173 -    */
   1.174 +    /// \brief Deletes \c i from the heap.
   1.175 +    ///
   1.176 +    /// This method deletes item \c i from the heap, if \c i was
   1.177 +    /// already stored in the heap.
   1.178 +    /// \param i The item to erase. 
   1.179      void erase(const Item &i) {
   1.180        rmidx(iim[i]);
   1.181      }
   1.182  
   1.183      
   1.184 -    ///Returns the priority of \c i.
   1.185 -
   1.186 -    /**
   1.187 -       This function returns the priority of item \c i.  
   1.188 -       \pre \c i must be in the heap.
   1.189 -    */
   1.190 +    /// \brief Returns the priority of \c i.
   1.191 +    ///
   1.192 +    /// This function returns the priority of item \c i.  
   1.193 +    /// \pre \c i must be in the heap.
   1.194 +    /// \param i The item.
   1.195      Prio operator[](const Item &i) const {
   1.196        int idx = iim[i];
   1.197        return data[idx].second;
   1.198      }
   1.199  
   1.200 -    ///\c i gets to the heap with priority \c p independently if \c i was already there.
   1.201 -
   1.202 -    /**
   1.203 -       This method calls \ref push(\c i, \c p) if \c i is not stored
   1.204 -       in the heap and sets the priority of \c i to \c p otherwise.
   1.205 -    */
   1.206 +    /// \brief \c i gets to the heap with priority \c p independently 
   1.207 +    /// if \c i was already there.
   1.208 +    ///
   1.209 +    /// This method calls \ref push(\c i, \c p) if \c i is not stored
   1.210 +    /// in the heap and sets the priority of \c i to \c p otherwise.
   1.211 +    /// \param i The item.
   1.212 +    /// \param p The priority.
   1.213      void set(const Item &i, const Prio &p) {
   1.214        int idx = iim[i];
   1.215        if( idx < 0 ) {
   1.216 @@ -235,38 +219,38 @@
   1.217        }
   1.218      }
   1.219  
   1.220 -    ///Decreases the priority of \c i to \c p.
   1.221 +    /// \brief Decreases the priority of \c i to \c p.
   1.222  
   1.223 -    /**
   1.224 -       This method decreases the priority of item \c i to \c p.
   1.225 -       \pre \c i must be stored in the heap with priority at least \c
   1.226 -       p relative to \c Compare.
   1.227 -    */
   1.228 +    /// This method decreases the priority of item \c i to \c p.
   1.229 +    /// \pre \c i must be stored in the heap with priority at least \c
   1.230 +    /// p relative to \c Compare.
   1.231 +    /// \param i The item.
   1.232 +    /// \param p The priority.
   1.233      void decrease(const Item &i, const Prio &p) {
   1.234        int idx = iim[i];
   1.235        bubble_up(idx, PairType(i,p));
   1.236      }
   1.237      
   1.238 -    ///Increases the priority of \c i to \c p.
   1.239 -
   1.240 -    /**
   1.241 -       This method sets the priority of item \c i to \c p. 
   1.242 -       \pre \c i must be stored in the heap with priority at most \c
   1.243 -       p relative to \c Compare.
   1.244 -    */
   1.245 +    /// \brief Increases the priority of \c i to \c p.
   1.246 +    ///
   1.247 +    /// This method sets the priority of item \c i to \c p. 
   1.248 +    /// \pre \c i must be stored in the heap with priority at most \c
   1.249 +    /// p relative to \c Compare.
   1.250 +    /// \param i The item.
   1.251 +    /// \param p The priority.
   1.252      void increase(const Item &i, const Prio &p) {
   1.253        int idx = iim[i];
   1.254        bubble_down(idx, PairType(i,p), data.size());
   1.255      }
   1.256  
   1.257 -    ///Returns if \c item is in, has already been in, or has never been in the heap.
   1.258 -
   1.259 -    /**
   1.260 -       This method returns PRE_HEAP if \c item has never been in the
   1.261 -       heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
   1.262 -       otherwise. In the latter case it is possible that \c item will
   1.263 -       get back to the heap again.
   1.264 -    */
   1.265 +    /// \brief Returns if \c item is in, has already been in, or has 
   1.266 +    /// never been in the heap.
   1.267 +    ///
   1.268 +    /// This method returns PRE_HEAP if \c item has never been in the
   1.269 +    /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
   1.270 +    /// otherwise. In the latter case it is possible that \c item will
   1.271 +    /// get back to the heap again.
   1.272 +    /// \param i The item.
   1.273      state_enum state(const Item &i) const {
   1.274        int s = iim[i];
   1.275        if( s>=0 )