diff --git a/lemon/kary_heap.h b/lemon/dheap.h copy from lemon/kary_heap.h copy to lemon/dheap.h --- a/lemon/kary_heap.h +++ b/lemon/dheap.h @@ -16,12 +16,12 @@ * */ -#ifndef LEMON_KARY_HEAP_H -#define LEMON_KARY_HEAP_H +#ifndef LEMON_DHEAP_H +#define LEMON_DHEAP_H ///\ingroup heaps ///\file -///\brief Fourary heap implementation. +///\brief D-ary heap implementation. #include #include @@ -31,21 +31,21 @@ /// \ingroup heaps /// - ///\brief K-ary heap data structure. + ///\brief D-ary heap data structure. /// - /// This class implements the \e K-ary \e heap data structure. + /// This class implements the \e D-ary \e heap data structure. /// It fully conforms to the \ref concepts::Heap "heap concept". /// - /// The \ref KaryHeap "K-ary heap" is a generalization of the + /// The \ref DHeap "D-ary heap" is a generalization of the /// \ref BinHeap "binary heap" structure, its nodes have at most - /// \c K children, instead of two. - /// \ref BinHeap and \ref FouraryHeap are specialized implementations - /// of this structure for K=2 and K=4, respectively. + /// \c D children, instead of two. + /// \ref BinHeap and \ref QuadHeap are specialized implementations + /// of this structure for D=2 and D=4, respectively. /// /// \tparam PR Type of the priorities of the items. /// \tparam IM A read-writable item map with \c int values, used /// internally to handle the cross references. - /// \tparam K The degree of the heap, each node have at most \e K + /// \tparam D The degree of the heap, each node have at most \e D /// children. The default is 16. Powers of two are suggested to use /// so that the multiplications and divisions needed to traverse the /// nodes of the heap could be performed faster. @@ -55,12 +55,12 @@ ///\sa BinHeap ///\sa FouraryHeap #ifdef DOXYGEN - template + template #else - template > #endif - class KaryHeap { + class DHeap { public: /// Type of the item-int map. typedef IM ItemIntMap; @@ -99,7 +99,7 @@ /// \param map A map that assigns \c int values to the items. /// It is used internally to handle the cross references. /// The assigned value must be \c PRE_HEAP (-1) for each item. - explicit KaryHeap(ItemIntMap &map) : _iim(map) {} + explicit DHeap(ItemIntMap &map) : _iim(map) {} /// \brief Constructor. /// @@ -108,7 +108,7 @@ /// It is used internally to handle the cross references. /// The assigned value must be \c PRE_HEAP (-1) for each item. /// \param comp The function object used for comparing the priorities. - KaryHeap(ItemIntMap &map, const Compare &comp) + DHeap(ItemIntMap &map, const Compare &comp) : _iim(map), _comp(comp) {} /// \brief The number of items stored in the heap. @@ -131,8 +131,8 @@ void clear() { _data.clear(); } private: - int parent(int i) { return (i-1)/K; } - int firstChild(int i) { return K*i+1; } + int parent(int i) { return (i-1)/D; } + int firstChild(int i) { return D*i+1; } bool less(const Pair &p1, const Pair &p2) const { return _comp(p1.second, p2.second); @@ -151,9 +151,9 @@ void bubbleDown(int hole, Pair p, int length) { if( length>1 ) { int child = firstChild(hole); - while( child+K<=length ) { + while( child+D<=length ) { int min=child; - for (int i=1; i