# HG changeset patch # User Peter Kovacs # Date 2009-09-29 13:32:01 # Node ID 65a0521e744e683924d5aff918686b3773c11822 # Parent 0977046c60d27196e3b008fe9f65350180ec5362 Rename heap structures (#301) - KaryHeap --> DHeap - FouraryHeap --> QuadHeap - BinomHeap --> BinomialHeap diff --git a/lemon/Makefile.am b/lemon/Makefile.am --- a/lemon/Makefile.am +++ b/lemon/Makefile.am @@ -60,7 +60,7 @@ lemon/bellman_ford.h \ lemon/bfs.h \ lemon/bin_heap.h \ - lemon/binom_heap.h \ + lemon/binomial_heap.h \ lemon/bucket_heap.h \ lemon/cbc.h \ lemon/circulation.h \ @@ -72,6 +72,7 @@ lemon/core.h \ lemon/cplex.h \ lemon/dfs.h \ + lemon/dheap.h \ lemon/dijkstra.h \ lemon/dim2.h \ lemon/dimacs.h \ @@ -80,14 +81,12 @@ lemon/error.h \ lemon/euler.h \ lemon/fib_heap.h \ - lemon/fourary_heap.h \ lemon/full_graph.h \ lemon/glpk.h \ lemon/gomory_hu.h \ lemon/graph_to_eps.h \ lemon/grid_graph.h \ lemon/hypercube_graph.h \ - lemon/kary_heap.h \ lemon/kruskal.h \ lemon/hao_orlin.h \ lemon/lgf_reader.h \ @@ -105,6 +104,7 @@ lemon/pairing_heap.h \ lemon/path.h \ lemon/preflow.h \ + lemon/quad_heap.h \ lemon/radix_heap.h \ lemon/radix_sort.h \ lemon/random.h \ diff --git a/lemon/binom_heap.h b/lemon/binomial_heap.h rename from lemon/binom_heap.h rename to lemon/binomial_heap.h --- a/lemon/binom_heap.h +++ b/lemon/binomial_heap.h @@ -16,8 +16,8 @@ * */ -#ifndef LEMON_BINOM_HEAP_H -#define LEMON_BINOM_HEAP_H +#ifndef LEMON_BINOMIAL_HEAP_H +#define LEMON_BINOMIAL_HEAP_H ///\file ///\ingroup heaps @@ -53,7 +53,7 @@ #else template > #endif - class BinomHeap { + class BinomialHeap { public: /// Type of the item-int map. typedef IM ItemIntMap; @@ -94,7 +94,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 BinomHeap(ItemIntMap &map) + explicit BinomialHeap(ItemIntMap &map) : _min(0), _head(-1), _iim(map), _num_items(0) {} /// \brief Constructor. @@ -104,7 +104,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. - BinomHeap(ItemIntMap &map, const Compare &comp) + BinomialHeap(ItemIntMap &map, const Compare &comp) : _min(0), _head(-1), _iim(map), _comp(comp), _num_items(0) {} /// \brief The number of items stored in the heap. @@ -424,7 +424,7 @@ private: class Store { - friend class BinomHeap; + friend class BinomialHeap; Item name; int parent; @@ -441,5 +441,5 @@ } //namespace lemon -#endif //LEMON_BINOM_HEAP_H +#endif //LEMON_BINOMIAL_HEAP_H diff --git a/lemon/kary_heap.h b/lemon/dheap.h rename from lemon/kary_heap.h rename 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 #include @@ -31,13 +31,14 @@ /// \ingroup heaps /// - ///\brief Fourary heap data structure. + ///\brief Fourary (quaternary) heap data structure. /// - /// This class implements the \e fourary \e heap data structure. + /// This class implements the \e Fourary (\e quaternary) \e heap + /// data structure. /// It fully conforms to the \ref concepts::Heap "heap concept". /// - /// The fourary heap is a specialization of the \ref KaryHeap "K-ary heap" - /// for K=4. It is similar to the \ref BinHeap "binary heap", + /// The fourary heap is a specialization of the \ref DHeap "D-ary heap" + /// for D=4. It is similar to the \ref BinHeap "binary heap", /// but its nodes have at most four children, instead of two. /// /// \tparam PR Type of the priorities of the items. @@ -47,13 +48,13 @@ /// The default is \c std::less. /// ///\sa BinHeap - ///\sa KaryHeap + ///\sa DHeap #ifdef DOXYGEN template #else template > #endif - class FouraryHeap { + class QuadHeap { public: /// Type of the item-int map. typedef IM ItemIntMap; @@ -92,7 +93,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 FouraryHeap(ItemIntMap &map) : _iim(map) {} + explicit QuadHeap(ItemIntMap &map) : _iim(map) {} /// \brief Constructor. /// @@ -101,7 +102,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. - FouraryHeap(ItemIntMap &map, const Compare &comp) + QuadHeap(ItemIntMap &map, const Compare &comp) : _iim(map), _comp(comp) {} /// \brief The number of items stored in the heap. @@ -335,7 +336,7 @@ _data[idx].first = j; } - }; // class FouraryHeap + }; // class QuadHeap } // namespace lemon diff --git a/test/heap_test.cc b/test/heap_test.cc --- a/test/heap_test.cc +++ b/test/heap_test.cc @@ -30,12 +30,12 @@ #include #include -#include -#include +#include +#include #include #include #include -#include +#include #include #include "test_tools.h" @@ -185,26 +185,26 @@ dijkstraHeapTest(digraph, length, source); } - // FouraryHeap + // QuadHeap { - typedef FouraryHeap IntHeap; + typedef QuadHeap IntHeap; checkConcept, IntHeap>(); heapSortTest(); heapIncreaseTest(); - typedef FouraryHeap NodeHeap; + typedef QuadHeap NodeHeap; checkConcept, NodeHeap>(); dijkstraHeapTest(digraph, length, source); } - // KaryHeap + // DHeap { - typedef KaryHeap IntHeap; + typedef DHeap IntHeap; checkConcept, IntHeap>(); heapSortTest(); heapIncreaseTest(); - typedef KaryHeap NodeHeap; + typedef DHeap NodeHeap; checkConcept, NodeHeap>(); dijkstraHeapTest(digraph, length, source); } @@ -245,14 +245,14 @@ dijkstraHeapTest(digraph, length, source); } - // BinomHeap + // BinomialHeap { - typedef BinomHeap IntHeap; + typedef BinomialHeap IntHeap; checkConcept, IntHeap>(); heapSortTest(); heapIncreaseTest(); - typedef BinomHeap NodeHeap; + typedef BinomialHeap NodeHeap; checkConcept, NodeHeap>(); dijkstraHeapTest(digraph, length, source); }